final study material 9/6 -2


1. When a JSP page is compiled, what is it turned into?
 A.
Applet
 B.
Servlet
 C.
Application
 D.
Mailet

Blank X
When a JSP page is compiled, what is it turned into?
Answer (B): Compiled JSP pages are turned into Servlets. See JSP Architecture for more information on this translation phase.
2. Which of the following is not a standard method called as part of the JSP life cycle?

 A.
jspInit()


 B.
jspService()


 C.
_jspService()


 D.
jspDestroy()

Blank X
Which of the following is not a standard method called as part of the JSP life cycle?
Answer (B): The standard service method for JSP has an _ in its name. See JSP Architecture.





3. If you want to override a JSP file's initialization method, within what type of tags must you declare the method?

 A.
<@ @>


 B.
<%@ %>


 C.
<% %>


 D.
<%! %>

Blank X
If you want to override a JSP file's initialization method, within what type of tags must you declare the method?
Answer (D): Declarations are placed within a set of <%! %> tags. See Declarations.





4. Which of the following can not be used as the scope when using a JavaBean with JSP?

 A.
application


 B.
session


 C.
request


 D.
response


 E.
page

Blank X
Which of the following can not be used as the scope when using a JavaBean with JSP?
Answer (D): Response is not a valid object scope for JavaBeans (or anything else). See Object Scopes.





5. The implicit JSP objects like request, response, and out are only visible in the _jspService() method.
 A.
True
 B.
False

Blank X
The implicit JSP objects like request, response, and out are only visible in the _jspService() method.
Answer: (A) Unless passed in as arguments to other methods, the implicit JSP arguments are only visible in the jspService() method. See JSP Implicit Objects.
6. What is the key difference between using a <jsp:forward> and HttpServletResponse.sendRedirect()?
 A.
forward executes on the client while sendRedirect() executes on the server.
 B.
forward executes on the server while sendRedirect() executes on the client.
 C.
The two methods perform identically.

Blank X
What is the key difference between using a <jsp:forward> and HttpServletResponse.sendRedirect()?
Answer (B): When you forward a request, the forwarding is done within the server, and limited in scope to where you can forward. Redirections are done on the client and thus don't have these limitations. See Including Requests.
7. Which of the following statements makes your compiled JSP page implement the SingleThreadModel interface?
 A.
<%@ page isThreadSafe="false" %>
 B.
<%@ page isThreadSafe="true" %>

Blank X
Which of the following statements makes your compiled JSP page implement the SingleThreadModel interface?
Answer (A): If you flag the JSP page as not being thread safe, it will implement the interface. See Synchronization Issues.
8. Of the following four valid comment styles that can be used within JSP pages, which can the end user see?
 A.
<%--
  My comments
  <% out.println("Hello World"); %>
--%>
 B.
<!-- (c)2000 jGuru.com -->
 C.
<% // For Loop
  for (int i=1; i<=4; i++) {
%>
  <H<%=i%>>Hello</H<%=i%>>
<% } %>
 D.
<% /** yet another comment */
  JavaDoc Rules
%>

Blank X
Of the following four valid comment styles that can be used within JSP pages, which can the end user see?
Answer (B): Only the JavaScript comment can be seen from the generated page. The other comments will be buried in the source for the generated servlet. See Comments.
9. How can a servlet call a JSP error page?
 A.
This capability is not supported.
 B.
When the servlet throws the exception, it will automatically be caught by the calling JSP page.
 C.
The servlet needs to forward the request to the specific error page URL. The exception is passed along as an attribute named "javax.servlet.jsp.jspException".
 D.
The servlet needs to redirect the response to the specific error page, saving the exception off in a cookie.

Blank X
How can a servlet call a JSP error page?
Answer (C): D will get the browser to display the appropriate page, it just doesn't preserve the state information requiring an unnecessary round trip to the browser. C is the direct approach. See Exception Handling and the jGuru JSP FAQ.
10. When using a JavaBean to get all the parameters from a form, what must the property be set to (??? in the following code) for automatic initialization?
<jsp:useBean id="fBean" class="govi.FormBean" scope="request"/>
<jsp:setProperty name="fBean" property="???" />
<jsp:forward page="/servlet/JSP2Servlet" />
 A.
*
 B.
all
 C.
@
 D.
=

Blank X
When using a JavaBean to get all the parameters from a form, what must the property be set to (??? in the following code) for automatic initialization?
Answer (A): The * character is used for this. See Using JavaBean Components.



1.     Which of the following ways will not load a JDBC driver?--D
 A.
Configure the list of drivers in the jdbc.driver system property
 B.
Call the driver's constructor
 C.
Pass the class name to the forName method of Class
 D.
Use JNDI to locate the Driver
3.     What does JDBC stand for? --B
 A.
Java Database Connectivity
 B.
JDBC is not an acronym
5.             In a non-JNDI environment, through which class does one acquire a connection to a specific data source?--B
 A.
Driver
 B.
DriverManager
 C.
Connection
 D.
DatabaseMetaData
 E.
Context
               
7.             In a JNDI environment, through which class does one acquire a connection to a specific data source?--E
 A.
Driver
 B.
DriverManager
 C.
Connection
 D.
DatabaseMetaData
 E.
DataSource
9.     Which way of loading the database driver can create two instances of the class?-C
 A.
Specify the driver or set of drivers to use by setting the jdbc.drivers system property.
 B.
Pass the class name as a String to the forName method of Class.
 c.
Create an instance of the class.
1.     If you add an Integer to a Properties object via the put method of Hashtable as both the key and value [props.put(anInteger, anInteger)], what happens when you try to store the Properties set to a FileOutputStream?--C
 A.
The code won't compile
 B.
The toString method of Integer is called to write both the key and value as a String.
 C.
A ClassCastException is thrown because the key is not a String
 D.
A ClassCastException is thrown because the value is not a String
3.     Which interface does Hashtable not implement?--B
 A.
Cloneable
 B.
Comparable
 C.
Map
 D.
Serializable

5.     Which of the following would sort all the elements in a Properties set, including the defaults?---B
 A.
Create a new TreeMap, passing in the source Properties object to its constructor.
 B.
Create a new TreeMap and to the map each key reported by propertyNames and its associated value.
 C.
Call the toArray method of Properties and then call Arrays.sort on the result.
 D.
Call the sort method of Collections to sort the whole Map (Properties object).
7.     Of which of the following is Properties not a descendent class?--C
 A.
Object
 B.
Dictionary
 C.
HashMap
 D.
Hashtable
9.     What options are available for working with property files that require character encoding in other than the default character set?---D
 A.
Pass the encoding name to the load method of Properties.
 B.
Pass the encoding name to the InputStreamReader constructor and then pass that Reader on to the load method of Properties.
 C.
Pass the encoding name to the constructor call of the Properties object.
 D.
Use the native2ascii tool to convert property files to other character encoding.
10.   In the following class definition, which variables are inaccessible within the method of the inner class?--B

class Test1 {
   public static int a = 1;
   private static int b = 2;
   public int c = 3;
   private int d = 4;
   public static class Inner {
     int e = 5;
     public void aMethod(int f) {
       int g = 6;
       // What can't be accessed here?
     }
   }
}


 A.
b, c, d


 B.
c, d


 C.
b, c, d, f


 D.
None of them








11.   In the following class definition, which variables are inaccessible within the method of the inner class? ---E
class Test2 {
   public static int a = 1;
   private static int b = 2;
   public int c = 3;
   private int d = 4;
   public class Inner {
     int e = 5;
     public void aMethod(int f) {
       int g = 6;
       // What can't be accessed here?
     }
   }
}

 A.
b, c, d


 B.
c, d


 C.
c, d, f


 D.
b, c, d, f


 E.
None of them





12.   In the following class definition, which variables are inaccessible within the method of the inner class? ---B
class Test3 {
   public static int a = 1;
   private static int b = 2;
   public int c = 3;
   private int d = 4;
   public void aMethod(int e) {
     int f = 5;
     class Inner {
       int g = 6;
       public void anotherMethod(int h) {
       // What can?t be accessed here?
       }
     }
   }
}

 A.
c, d


 B.
e, f


 C.
c, d, e, f


 D.
e, f, g


 E.
None of them.





13.   What's wrong with the following code? ---D
class Test4 {
   public static void main(String args[]) {
     MouseListener listener = new MouseAdapter() {
       static int count;
       public void mouseEntered(MouseEvent e) {
         processIt(e);
       }
       private void processIt(MouseEvent f) {
         System.out.println("Got: " + f);
         System.out.println("Count: " + ++count);
       }
     };
   }
}

 A.
Anonymous inner classes can only implement interfaces.


 B.
Inner classes can't have support methods.


 C.
All the methods of MouseListener aren't implemented.


 D.
Inner classes can't have static declarations.


 E.
Nothing is wrong. The code compiles fine.





14.   Where were inner classes introduced into the Java programming language syntax?--B
 A.
1.0
 B.
1.1
 C.
1.2
 D.
1.3
 E.
1.4
15.  
16.  
1. What do you have to do to make an instance variable into a JavaBean property? ---B
 A.
Declare the instance variable public and static.
 B.
Define a get method and a set method for the variable.
 C.
Drop the Bean into the BeanBox property sheet.
 D.
Declare the instance variable private and let the BeanBox define get and set methods for the variable.


2. An application builder tool can analyze how JavaBeans work. Which mechanism does the tool use? ---C
 A.
Persistence
 B.
Method customization
 C.
Introspection
 D.
Event delegation

3. Properties control what aspects of a JavaBean? ---B
 A.
The communication between JavaBeans.
 B.
A JavaBean's appearance and behavior.
 C.
How a JavaBean is compiled and dropped into the BeanBox (or other tool).
 D.
The tools you can use to customize a JavaBean.

4. JavaBean methods are all ---D
 A.
Events
 B.
Properties
 C.
Event listeners
 D.
Identical to methods of other Java classes

5. A source Bean is a JavaBean that fires an event, while the Bean that receives the event is called a ---A
 A.
Listener Bean
 B.
Receiver Bean
 C.
Enterprise JavaBean
 D.
EventHandler Bean

6. JavaBeans and widgets are both considered to be reusable software components. However, JavaBeans differ from widgets because Beans ---B
 A.
Can be reused more rapidly than widgets.
 B.
Define a design-time interface that tools can query.
 C.
Take up less storage space that widgets.
 D.
Can be run by more tools on more platforms than widgets.

7. The BeanBox is a JavaBean testing tool that comes with the Bean Developer's Kit. The BeanBox has the following windows: ---A
 A.
ToolBox, BeanBox, and Properties windows.
 B.
ToolBox, BeanBox, and Garage windows.
 C.
BeanBox, ToolBox, and Windows98 windows.
 D.
Properties and ToolBox windows.

8. JavaBeans communicate with each other using events, such as action events. You establish the connection between Beans by: ---D
 A.
Writing a special adapter class.
 B.
Using the BeanBox Edit -> Events menu and resulting dialog box to hook up one Bean to another.
 C.
Having the BeanBox generate the special adapter class.
 D.
Any of the above choices.

9. You use the Property sheet in the BeanBox tool to ---C
 A.
Add new properties to a Bean.
 B.
Delete a Bean's property.
 C.
Change the value of a Bean's property.
 D.
All of the above.

10. The properties of a Bean ---D
 A.
May be inherited by the Bean from its superclass.
 B.
Are defined by the Bean itself.
 C.
Are analogous to instance variables.
 D.
All of the above.
 E.
None of the above.

11. Some JavaBeans are not meant to be visible and are referred to as invisible Beans. Such invisible Beans ---E
 A.
Have no GUI representation.
 B.
Are able to fire events and save persistent state.
 C.
Are invisible in builder tools.
 D.
All of the above.
 E.
A and B only.

12. A property defined in a JavaBean typically ---D
 A.
Is declared as a private type.
 B.
Has a corresponding get method and set method.
 C.
Can be saved and retrieved at a later time.
 D.
All of the above.
 E.
None of the above.

13. When you write the code for a new JavaBean, you can test it in the BeanBox. What do you have to do to be able to test the Bean in the BeanBox? ---E
 A.
Compile the Bean.
 B.
Create a manifest file for the Bean.
 C.
Create an executable JAR file for the Bean class and manifest file.
 D.
Load the JAR file into the BeanBox using the LoadJar menu option, or place the JAR file in the default directory from which the BeanBox initializes and loads its Beans.
 E.
All of the above.

14. When you write a get method for a JavaBean property, form the method name as follows: ---C
 A.
Use any name you want for the get method.
 B.
Use only the property name for the get method.
 C.
Use get followed by the property name, with the first letter of the property name capitalized.
 D.
None of the above.

15. A manifest file for a JavaBean contains the following information: ---D
 A.
The name of the JavaBean's class file.
 B.
An indicator that this is a JavaBean.
 C.
A list of the properties declared by the JavaBean.
 D.
A and B.
 E.
A, B, and C.

16. Which kinds of properties can a Bean contain? ---B
 A.
Complex properties and Event-handling properties
 B.
Constrained properties, Simple properties, Bound properties
 C.
All of the above

17. A JavaBean that defines bound properties typically calls what methods so that other Beans can be notified of changes to the bound property? ---E
 A.
The addPropertyChangeListener method so a Bean can register an interest in notification of changes to the property.
 B.
The reportChange method to send property change notification to interested Beans.
 C.
The firePropertyChange method to send property change notification to interested Beans.
 D.
The addActionListener method so a Bean can register an interest in notification of changes to the property.
 E.
A and C
 F.
D only
 G.
All of the above

18. Bound properties appear in the BeanBox with what kind of event in the Edit -> Events menu? ---B
 A.
actionPerformed event
 B.
propertyChange event
 C.
mouse pressed event
 D.
mouse moved event

19. Constrained properties are ---B
 A.
Identical to bound properties except that they are only used on certain platforms.
 B.
Identical to bound properties except that the listener Bean can veto the property change.
 C.
Identical to bound properties except that they are indexed.
 D.
None of the above.