Tuesday, April 12, 2011

Self Test: Chapters 31 to 37

Questions:

Question 1:

Assume the custom tag is GLOOP and the prefix is TWONG. Which of the following is the syntax for an empty custom tag?
A. < TWONG : GLOOP / >
B. < GLOOP : TWONG / >
C. < GLOOP : TWONG > < / GLOOP : TWONG >
D. < TWONG : GLOOP > < / TWONG : GLOOP >

Question 2:

Which design pattern did the designers of JSP use to provide centralized dispatching of requests via a controller servlet?
A. Model-View-Controller
B. Facade
C. Server-Client
D. Publish-Subscribe

Question 3:

Which of the following options is a valid declaration?
A. < % ! String name="Rocky" % >
B. < % ! String name="Rocky"; % >
C. < % String name="Anand" % >
D. < % public String name="Anand"; % >

Question 4:

The following are the contents of comment.jsp:
1 < html >
2 < head > < title >Two Comments< / title > < / head >
3 < body >
4 < % - - JSP Comment - - % >
5 < ! - - HTML Comment - - >
6 < / body >
7 < / html >

Which option best describes what happens upon executing index.jsp?
A. A fatal error occurs because the body is empty.
B. Line 5 (but not 4) gets added to the output stream.
C. 4 (but not 5) gets added to the output stream.
D. All seven lines get added to the output stream.

Question 5:

The following are the contents of request_parameter.jsp:
< html >
< head >
< title >Retrieve Request Parameter< / title >
< / head >
< body >
< % String customerName = request.getParameter("customer"); % >
< p >
The customer is < % = customerName % >
< / body >
< / html >

Assuming the www.que.com server is responding correctly and the page path is valid, what displays in the browser if the user types http://www.quepublishing.com/customer/request_parameter.jsp?customer=Anand?
A. The customer is
B. A blank page.
C. The customer is Anand
D. An error page.

Question 6:

The following are the contents of welcomeHeader.inc:
< h1 >Welcome to our drive through

Java coding service!< / h1 >

The following are the contents of index.jsp:
< html >
< head > < title >Java Quick Code< / title > < / head >
< body >
< % String file="welcomeHeader.inc"; % >
< %@ include file="file" % > < p >
We are the best J2EE Programmers.
< / body >
< / html >

Which option best describes what happens upon executing comment.jsp?
A. An error occurs.
B. The page displays including the welcome header.
C. The page displays excluding the welcome header.
D. The page displays, but replaces the welcome header with the words welcomeHeader.inc.

Question 7:

Which of the following options is a JSP implicit object?
A. objRequest
B. Request.send
C. request
D. servlet

Question 8:

Which of the following options is not a JSP implicit object?
A. out
B. in
C. response
D. page

Question 9:

Which of the following will not compile (assume < x : tag > is a valid custom tag that is declared for the current JSP file)?
A. < % String employees = "Rocky"+"Anand"; % >
B. < x : tag value='< % = "5" % > ' />
C. < x : tag value="< % = "hi!" % > " />
D. < x : tag value='< % = "Joe said \\"" +statement+ "\\"." % > '/ >

Question 10:

Which among the following objects is the best choice to share information between users?
A. application
B. page
C. request
D. session

Question 11:

Which among the following objects is the best choice to share information between pages for a single user?
A. application
B. page
C. request
D. session

Question 12:

Which of the following objects is used to share information between pages using the setAttribute and getAttribute methods?
A. application
B. page
C. request
D. session

Question 13:

Which option is a valid page directive?
A. < % @ page language="java" import="com.myco.*" buffer="16kb" % >
B. < % @ page import="com.myco.class" buffer="16" % >
C. < % @ page language="javaScript" buffer="16" % >
D. < % @ page import='com.myco.*' buffer='16' % >

Question 14:

Which option indicates whether the current JSP page is intended to be the URL target of another JSP page's error page?
A. < % @ page isErrorPage="true" % >
B. < % @ page isErrorPage="/messages/errorPage.jsp" % >
C. < % @ page errorPage="true" % >
D. < % @ page errorPage="/messages/errorPage.jsp" % >

Question 15:

Which option defines a URL to a resource to which any Java programming language Throwable object(s) thrown but not caught by the page implementation are forwarded for error processing?
A. < % @ page isErrorPage="true" % >
B. < % @ page isErrorPage="/messages/errorPage.jsp" % >
C. < % @ page errorPage="true" % >
D. < % @ page errorPage="/messages/errorPage.jsp" % >

Answers:

Answer 1:

A, D. These use the correct syntax for an empty custom tag of GLOOP having the prefix TWONG.

Answer 2:

A. The Model-View-Controller design pattern is the one the designers of JSP use to provide centralized dispatching of requests via a controller servlet.

Answer 3:

B. This is a valid declaration. Be careful about the semicolon, which is required in a declaration.

Answer 4:

B. Remember that the JSP Comment is ignored by the compiler. However, the HTML Comment is passed through. Even though the browser doesn't display content in response to it, the JSP container does add it to the output stream.

Answer 5:

C. The declaration is correct. The customer is < % = customerName % > fragment becomes The customer is Anand.

Answer 6:

A. The following is wrong: < % @ include file="file" % >. It should have been < % @ include file="welcomeHeader.inc" % >. Note that "file" in quotes literally means you were asking the system to include a file whose filename is “file.”

Answer 7:

C. Option C is correct if the request is the only implicit object.

Answer 8:

B. All of these are JSP implicit objects except the fictitious in.

Answer 9:

C. All of these will compile except C, because there are quotes within quotes. It should have been < x : tag value="<%= \"hi!\" %>" / >.

Answer 10:

A. The same application object is accessible by all users.

Answer 11:

D. The session object is the best choice for sharing information between pages for a single user. Users can see their own session object, but can't see others' session objects.

Answer 12:

A, C, and D. Both the application and the session objects can be used to share information between pages with the setAttribute and setAttribute methods. Either A or D is correct. Option C is also valid because you can share attributes from a “master” page to an “included” page.

Answer 13:

A. Only A is correct. All the others are syntactically wrong. Notice the kb requirement on the buffer attribute.

Answer 14:

A. This is the isErrorPage attribute of the page directive. Another page can now, but doesn't have to, use this page as an error page.

Answer 15:

D. The errorPage attribute of the page directive defines a URL to a resource to which any Java programming language Throwable object(s) thrown but not caught by the page implementation are forwarded for error processing.

Previous Chapter: Quick Recap - Chapters 31 to 37

Next Chapter: Chapter 38 - Introduction to JavaBeans

No comments:

Post a Comment

© 2013 by www.inheritingjava.blogspot.com. All rights reserved. No part of this blog or its contents may be reproduced or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without prior written permission of the Author.

ShareThis

Google+ Followers

Followers