1



1.     Struts was first developed --B
 A.
in an online exchange between several open source developers
 B.
over a long holiday weekend
 C.
as a commercial package
2.     The reset method on an ActionForm D
 A.
Sets all properties to their initial value
 B.
Sets all properties to null
 C.
Repopulates all properties from the request parameters
 D.
None of the above
3.     Each Struts Action element is uniquely identified by its----D
 A.
Input attribute
 B.
Name attribute
 C.
Page attribute
 D.
Path attribute
4.     The name of the Application Resources file is set by the servlet init-param named--A
 A.
application
 B.
resources
 C.
ApplicationResources
 D.
messages

5.     The validating init-param of the ActionServlet is used to---B
 A.
Bypass calls to the ActionForm validate method
 B.
Bypass validation of the Struts configuration file
 C.
Generate an error message if an unknown message key is used
6.     To specify an ActionMapping to use when a request doesn't match any other mapping, you can ---C
 A.
Use an asterisk for the path property
 B.
Set the "default" property of the mapping to "true"
 C.
Set the "unknown" property of the mapping to "true"
 D.
Set the "missing" init-param of the ActionServlet to the mapping's path
7.     If you have created a custom ActionMapping subclass with the property "service", you can initialize the value to "selectRecord" using ----B
 A.
<init-property name="service" value="selectRecord"/>
 B.
<set-property property="service" value="selectRecord"/>
 C.
<put-field key="service" content="selectRecord"/>
8.     In Struts 1.1, you can change how Struts populates a form by---B
 A.
Overriding the populate method of the ActionForm
 B.
Overriding the processPopulate method of the Request Processor
 C.
Overriding the populateBean method of the ActionMapping
9.     The <bean:write> tag is:----C
 A.
Always converts HTML markup to entity equivalents, like &lt;
 B.
Never converts HTML markup to entity equivalents
 C.
Converts markup when filter=true
 D.
Converts markup when markup=false
10.   To prevent possible security issues with the <html:password> tag, you should--B
 A.
Call the reset method if validation fails
 B.
Set the tag's redisplay property to false
 C.
Set the tag's reset property to false
 D.
Use a plain html tag instead
11.   To localize Tiles, you can ---A
 A.
Create separate configuration files for each locale
 B.
Specify an locale for a definition
 C.
Either A or B
12.   To localize Validator forms, you can---B
 A.
Create separate configuration files for each locale
 B.
Specify a locale for a form-set
 C.
Either A or B
13.   From a MVC perspective, Struts provides the---C
 A.
Model
 B.
View
 C.
Controller
1. If you need to use a stored procedure with output parameters, which of the following statement type should be used to call the procedure? ---C
 A.
Statement
 B.
PreparedStatement
 C.
CallableStatement

2. Which of the following will not cause a JDBC driver to be loaded and registered with the DriverManager? ---D
 A.
Class.forName(driverString);
 B.
new DriverClass();
 C.
Include driver name in jdbc.drivers system property
 D.
None of the above

3. From which object do you ask for DatabaseMetaData? ---A
 A.
Connection
 B.
ResultSet
 C.
DriverManager
 D.
Driver

4. SQLWarnings from multiple Statement method calls (like executeUpdate) will build up until you ask for them all with getWarnings and getNextWarning. ---B
 A.
True
 B.
False

5. If one intends to work with a ResultSet, which of these PreparedStatement methods will not work? ---C
 A.
execute()
 B.
executeQuery()
 C.
executeUpdate()

6. Can a ResultSet be reliably returned from a method that creates a Statement and executes a query? ---B
 A.
Yes
 B.
No

7. How can I use JDBC to create a database?---B
 A.
Include create=true at end of JDBC URL
 B.
Execute "CREATE DATABASE jGuru" SQL statement
 C.
Execute "STRSQL" and "CREATE COLLECTION jGuru" SQL statements
 D.
Database creation is DBMS specific

8. Which character is used to represent an input parameter in a CallableStatement? -C
 A.
%
 B.
*
 C.
?
 D.
#


9. Which one of the following will not get the data from the first column of ResultSet rs, returned from executing the following SQL statement: SELECT name, rank, serialNo FROM employee. --A
 A.
rs.getString(0);
 B.
rs.getString("name");
 C.
rs.getString(1);

10. Which of the following can you do with a JDBC 2.0 database driver that you cannot with a JDBC 1.x driver? ---D
 A.
Batch multiple statements, to be sent to the database together
 B.
Scroll through result sets bi-directionally
 C.
Work with SQL3 data types directly
 D.
All of the above

11. Which class contains the transaction control methods setAutoCommit, commit, and rollback? --A
 A.
Connection
 B.
Statement
 C.
ResultSet

1. If you need to use a stored procedure with output parameters, which of the following statement type should be used to call the procedure?

 A.
Statement


 B.
PreparedStatement


 C.
CallableStatement


Blank X
Answer (C): Output parameters are only available when working with a CallableStatement. See Store d Procedures





2. Which of the following will not cause a JDBC driver to be loaded and registered with the DriverManager?

 A.
Class.forName(driverString);


 B.
new DriverClass();


 C.
Include driver name in jdbc.drivers system property


 D.
None of the above


Blank X
Answer (D): A, B, and C will all cause the JDBC driver to be loaded and registerd with the DriverManager. See Conn ecting to the Database






3. From which object do you ask for DatabaseMetaData?
 A.
Connection
 B.
ResultSet
 C.
DriverManager
 D.
Driver


Blank X
Answer (A): The getMetaData of Connection allows you to get the database meta data. See Dat abase Metadata.

4. SQLWarnings from multiple Statement method calls (like executeUpdate) will build up until you ask for them all with getWarnings and getNextWarning.

 A.
True


 B.
False


Blank X
Answer (B): Statements clear warnings automatically on the next execution. See SQL Warnings.






5. If one intends to work with a ResultSet, which of these PreparedStatement methods will not work?
 A.
execute()
 B.
executeQuery()
 C.
executeUpdate()

Blank X
Answer: (C) While execute returns a boolean, you can get multiple ResultSets through getResultSet. See Statements, ResultSets, and Interacting with a Database.

6. Can a ResultSet be reliably returned from a method that creates a Statement and executes a query?
 A.
Yes
 B.
No

Blank X
Answer (B): No, closing the Statement, will close the result set.

7. How can I use JDBC to create a database?

 A.
Include create=true at end of JDBC URL

 B.
Execute "CREATE DATABASE jGuru" SQL statement

 C.
Execute "STRSQL" and "CREATE COLLECTION jGuru" SQL statements

 D.
Database creation is DBMS specific

Blank X
Answer (B): Execute "CREATE DATABASE jGuru" SQL statement







8. Which character is used to represent an input parameter in a CallableStatement?
 A.
%
 B.
*
 C.
?
 D.
#

Blank X
Answer (C): It is the ? character. See Par ameter INs and OUTs.

9. Which one of the following will not get the data from the first column of ResultSet rs, returned from executing the following SQL statement: SELECT name, rank, serialNo FROM employee.
 A.
rs.getString(0);
 B.
rs.getString("name");
 C.
rs.getString(1);

Blank X
Answer (A): Column numbers start at 1, not 0. See Data base Queries.

10. Which of the following can you do with a JDBC 2.0 database driver that you cannot with a JDBC 1.x driver?
 A.
Batch multiple statements, to be sent to the database together
 B.
Scroll through result sets bi-directionally
 C.
Work with SQL3 data types directly
 D.
All of the above

Blank X
Answer (D): All of these are new capabilities supported only when using a JDBC 2.0 driver and a database that supports them. See Batch Update Facility, Scrol lable Result Sets, and LOBs.



11. Which class contains the transaction control methods setAutoCommit, commit, and rollback?
 A.
Connection
 B.
Statement
 C.
ResultSet

Blank X
Answer (A): Transactions are controlled at the Connection level. See: Trans actions.

1. Choose the statement that best describes the relationship between JSP and servlets:
 A.
Servlets are built on JSP semantics and all servlets are compiled to JSP pages for runtime usage.
 B.
JSP and servlets are unrelated technologies.
 C.
Servlets and JSP are competing technologies for handling web requests. Servlets are being superseded by JSP, which is preferred. The two technologies are not useful in combination.
 D.
JSPs are built on servlet semantics and all JSPs are compiled to servlets for runtime usage.


1.

Blank X
Every JavaServer Pages (JSP) source page is compiled into a servlet before it is executed at runtime.

2. What is a benefit of using JavaBeans to separate business logic from presentation markup within the JSP environment?
 A.
It allows the JSP to access middleware.
 B.
It creates a cleaner role separation between the web-production team and the software development team, so that the web-production team can focus on presentation markup, while the software team can focus on building reusable software components for helping to generate dynamic displays.
 C.
It provides a dynamic markup environment, such that JavaBeans are integrated seamlessly with the template presentation content, in order to create the dynamic display for the client.
 D.
It provides the developer with full access to the Java 2 Platform Enterprise Edition (J2EE), which is unavailable from outside the JavaBean environment.

2.

Blank X
When large amounts of Java scriptlet code are mixed with HTML markup within a JSP page, not only do readability and reuse suffer, but often bugs are introduced as web-production team members, who may not be familiar with Java programming, need to modify the accompanying markup. Additionally, dependencies now exist among various teams competing for the same file, making the development process less efficient.

3. Why use RequestDispatcher to forward a request to another resource, instead of using a sendRedirect?
 A.
Redirects are no longer supported in the current servlet API.
 B.
Redirects are not a cross-platform portable mechanism.
 C.
The RequestDispatcher does not use the reflection API.
 D.
The RequestDispatcher does not require a round trip to the client, and thus is more efficient and allows the server to maintain request state.


Blank X
Doing an HTTP redirect requires a round-trip to the client. If this is not required, and the only desire is to forward the request to another resource, then this can be much more efficiently accomplished with the RequestDispatcher. Additionally, when using the dispatcher the state of the request object is maintained between resources, which will not be the case with the HTTP redirect.

4. What alternatives exist to embedding Java code directly within the HTML markup of your JSP page?
 A.
Moving the code into your session manager.
 B.
Moving the code into scriptlets.
 C.
Moving the code into JavaBeans and servlets.
 D.
Moving the code into a transaction manager.

Blank X
Business logic is better contained in a JavaBean or a servlet that is owned by a software developer. When lots of Java code is embedded directly within the JSP page as scriptlets, the "cut-and-paste" mentality tends to prevail when it comes to code reuse.

5. What type of scriptlet code is better-suited to being factored forward into a servlet?
 A.
Code that deals with logic that is common across requests.
 B.
Code that deals with logic that is vendor specific.
 C.
Code that deals with logic that relates to database access.
 D.
Code that deals with logic that relates to client scope.

Blank X
Since the servlet is the initial contact point for each request, it is well-suited to handle logic that is common across multiple requests. A good example of this type of logic is an authentication check.

6. Choose the statement that best describes how to connect JSP pages and Enterprise JavaBeans (EJBs):
 A.
Lookup the EJBs from within a JSP, but use the EJBs from within a basic JavaBean.
 B.
Lookup and use the EJBs from a separate business delegate. The JavaBeans that work with JSP pages are clients to these business delegates and know nothing about EJB specifics.
 C.
Lookup and use the EJBs from within a JSP page, but only as remote references.
 D.
Lookup the EJBs from within a servlet, delegating usage to specific JSP pages.


Blank X
Using a business delegate reduces coupling between the presentation and business tiers. The presentation tier has no knowledge of the EJB implementation details, such as Java Naming and Directory InterfaceTM lookup.

7. Are custom tags available in JSP 1.0? If not, how else might you implement iteration from within a JSP?
 A.
Yes, but the only tags available relate to database access.
 B.
No. To iterate over a collection of values, one must use scriptlet code.
 C.
No, but there is a standard <iterate> tag that may be used.
 D.
Yes, but custom tags will not help developers create tags for use in iterating over a collection.


Blank X
Using Java scriptlets is the accepted method of doing iteration in JSP 1.0. In JSPTM 1.1, a custom tag may be used, which will hide the implementation details of the iteration code.

8. What is the initial contact point for handling a web request in a Page-Centric architecture?
 A.
A JSP page.
 B.
A JavaBean.
 C.
A servlet.
 D.
A session manager.

The term Page-Centric is used to describe an architecture where the initial contact point for the request is a JSP page. An example is shown visually below:

9. What is the difference between doing an include or a forward with a RequestDispatcher?
 A.
The forward method transfers control to the designated resource, while the include method invokes the designated resource, substitutes its output dynamically in the display, and returns control to the calling page.
 B.
The two methods provide the same functionality, but with different levels of persistence.
 C.
The forward method is deprecated as of JSP 1.1 and the include method should be used in order to substitute portions of a dynamic display at runtime.
 D.
The include method transfers control to a dynamic resource, while the forward method allows for dynamic substitution of another JPS pages output, returning control to the calling resource.


Blank X
When the forward method is used, the invoking resource does not regain control. Multiple include invocations can be made from the same resource, while the invoking resource maintains execution control.


10. What line of code below might be combined in the same JSP page with a validation guard (for example, <% bean.validationGuard(); %> ), in order to create an alternate flow of control for scenarios in which exceptions arise. The validationGaurd method might throw an exception, which should cause the flow of control to continue in another user-defined page (assume JSP 1.0).
 A.
<jsp:error page="errorPage.jsp" guard="true" />
 B.
<%@ page language="java" buffer="8k" %>
 C.
<jsp:useBean id="bean" class="examples.Bean" scope="request" />
 D.
<%@ page language="java" errorPage="errorPage.jsp" buffer="8k" %>

Blank X
Error pages are invoked when there is an uncaught exception from within a particular page. In this case, we mention that the validationGaurd() method might throw an exception. If this exception is not caught within the page, then we vector control to errorPage, as stipulated in the attribute of the given page directive.

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.