Let us test out our knowledge of JavaBeans that we learnt in the past chapters.
Which one of the following interfaces is implemented when declaring a JavaBean?
E. None of the above.
Which one of the following objects is passed to a JavaBean when one of its properties is set via a JSP action?
E. None of the above.
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?
C. One per session
D. None of the above
Which of the following cannot be used as the scope when using a JavaBean with JSP?
Which of the following are used by servlet containers to set JavaBean properties?
B. form fields
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?”
Is it impossible to share a page scope variable with another JSP or servlet?
Given a form field named lastName, what is the get method for the associatedJavaBean property?
public String getFirstName ()
public String getFirstName (boolean returnValue)
public String getFirstname ()
public String get("FirstName")
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.
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
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.
A. The response object cannot be used as the scope when using a JavaBean with JSP.
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.
D. The request scope best fits the description given by the question.
A. This is true that it is impossible to share a page scoped variable with another JSP or Servlet.
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
© 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.