Thursday, April 14, 2011

Self Test: Chapters 38 to 43

Let us test out our knowledge of JavaBeans that we learnt in the past chapters.


Question 1:

Which one of the following interfaces is implemented when declaring a JavaBean?
A. JavaBean
B. ServiceBean
C. HttpJavaBean
D. ServletBean
E. None of the above.

Question 2:

Which one of the following objects is passed to a JavaBean when one of its properties is set via a JSP action?
A. ServletRequest
B. HttpServletRequest
C. ServletResponse
D. HttpServletResponse
E. None of the above.

Question 3:

By default, how many instances of a JavaBean will be created by a servlet container when there are five useBean elements with the same ID on the same JSP page?
A. One
B. Five
C. One per session
D. None of the above

Question 4:

Which of the following cannot be used as the scope when using a JavaBean with JSP?
A. response
B. request
C. session
D. application
E. page

Question 5:

Which of the following are used by servlet containers to set JavaBean properties?
A. cookies
B. form fields
C. memory
D. disk

Question 6:

Which of the following scopes best fits with this description: “An object inside this scope is accessible from all pages processing the request during which the object was created?”
A. page
B. session
C. application
D. request

Question 7:

Is it impossible to share a page scope variable with another JSP or servlet?
A. Yes
B. No
C. Sometimes
D. Configurable

Question 8:

Given a form field named lastName, what is the get method for the associatedJavaBean property?
public String getFirstName ()
return firstName;
public String getFirstName (boolean returnValue)
if (returnValue)
return firstName;
public String getFirstname ()
return Firstname;
public String get("FirstName")
return FirstName;


Answer 1:

E. None of the interfaces mentioned in the answers is implemented when declaring a JavaBean. It isn't an interface that makes a class a JavaBean; it's the way it is used with a public class, public constructor without arguments, and the get/set paradigm. Notice that neither “none of the above” nor “all of the above” answers are allowed on the actual exam.

Answer 2:

E. None of the objects mentioned in the answers is passed to a JavaBean when a property is changed from JSP. Rather, it is simply a method call transferred from the JSP page to the Bean with either the setProperty element or with a direct call within a scriptlet

Answer 3:

D. There will only be one instance of a JavaBean with the same ID created by a servlet container, even when there are five useBean actions on the same JSP page. If you have more than one useBean action with the same ID, you will get a CompileException for the duplicate bean name. See “Creating JavaBeans,” earlier in this chapter.

Answer 4:

A. The response object cannot be used as the scope when using a JavaBean with JSP.

Answer 5:

B. The JavaBean attributes are set when the container captures the form field name-value pairs, and then calls the setter methods in the bean for the attributes which have the same name as the form fields.

Answer 6:

D. The request scope best fits the description given by the question.

Answer 7:

A. This is true that it is impossible to share a page scoped variable with another JSP or Servlet.

Answer 8:

B. When you write a get method for a JavaBean property, use set or get followed by the first letter of the property name capitalized.

Previous Chapter: Quick Recap - Chapters 38 to 43

Next Chapter: Chapter 44 - JSP Tag Libraries

No comments:

Post a Comment

© 2013 by 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.


Google+ Followers