J2EE Questions
1. When using an HttpURLConnection object to establish a connection with a site, how do you tell if the page that you connected to issued a redirect?
A Call the getURL() method and check the value of that.
B Call the connection.getHeaderField() with "location" as a parameter to get the location field from the HTTP header, compare this with the URL that was connected too.
C Call the getRedirect() method from the HttpURLConnection class and check the return for null.
D Call the connection.getHeaderField() and check to see if the location is null.
E Call the setInstanceFollowRedirects() with a value of false.
2.The typical object returned by a JDBC SQL query is a Java ResultSet
object.
Which of the following is true regarding Java ResultSet objects?
A Whenever code is written to process ResultSets, the developer needs to check the size of the ResultSet prior to processing. An attempt to process a row when no rows are returned, will result in an exception.
B A ResultSet cursor is initially positioned on the first row of the set returned.
C In the JDBC API ResultSet objects are not scrollable meaning that rows in a ResultSet need to be processed in ascending order.
D In order to get data from individual columns within a ResultSet the developer must use the column name in the get() method.
E A method of controlling the behavior of the ResultSet returned from a query is to provide type and concurrency parameters to the method: Connection.createStatement(int, int) which returns an appropriate Statement object used for executing queries.
3. The developer has a session bean the needs to call the methods on another session bean, passing a reference to the caller to the callee. How can the caller session bean pass a reference to itself?
A Pass the reference with the this keyword
B Use the SessionContext's getEJBObject() method.
C The callee must use the home interface to get a reference to the caller, just as a client would.
D An Entity bean must be set up as a proxy to handle the communication between the session beans.
E Use the this.getEJBReference() method
F A stateful session bean cannot pass a reference of itself to another bean.
4. How can an HTTP servlet communicate the size of the response data to a client?
A Use the ServletResponse.setContentLength() method after committing the output.
B Use the ServletResponse.setByteCount() method after committing the output.
C Use the ServletResponse.setContentLength() method before committing the output.
D The client can calculate the content length based on the length of the transmission.
E The first data in the output stream should be a serialized integer count of the number of bytes to follow.
5. Which of the following best describes the differences between a Statement object and a PreparedStatement object?
A The PreparedStatement object extends the Statement object and therefore should be used with databases for which there is no JDBC driver.
B The PreparedStatement object should only be used when there are no parameters for the query, while the statement object should be used for parameterized queries.
C For each SQL query sent to the database the Statement object will go through a compilation/optimization phase whereas the PreparedStatement only does this when directed to do so by a parameter.
D The PreparedStatement object is pre-compiled and optimized. The PreparedStatement object supports parameterized queries while the Statement is compiled with every call and does not support parameters in the query.
E The Statement object is serializable while the PreparedStatement is not
6. Which of the following best describes the mechanisms for having an object receive notification when it is added to or removed from the current HttpSession?
A The object can implement a notify() method, which will be called by the servlet engine when the object is added to or removed from the session.
B The object can implement the HttpSessionBindingListener interface. The servlet engine calls the load() method of all objects that implement this interface when session data changes.
C The object can implement the HttpSessionBindingListener interface. The valueBound() or valueUnbound() methods are called when the object is added to or removed from the session.
D The object can register with the Servlet engine through a properties file.
E The object can implement the HttpSession interface and the notify() method from this class is called by the servlet engine.
7. Which of the following best describes a complete home interface for a stateless session bean?
A The create method for a stateless session bean must take no arguments and the find method must take the name of the bean.
B The home interface of a stateless session bean can be empty because these beans do not maintain any state.
C The create method for a stateless session bean takes no arguments there should be no find method and the behavior of the remove method is server dependent.
D The create method in the home interface for a stateless session bean must take one argument the name of the bean.
E The home interface of a stateless session bean must contain a create method a remove method and a find method.
8. Some servlets are frequently used or may require some time to initialize. These servlets should be loaded on web server startup to minimize latency. Others are rarely used or quick to initialize and would be better loaded when they are first referenced. How do you control whether servlets are loaded when the server starts or on demand?
A The servlet engine must be configured for the desired behavior.
B There is no way to control this behaviour programmatically.
C Call the Servlet.setPreload() method with an argument of true.
D Add the name of the servlet class to the list of preloaded servlets by calling Servlet.setPreloadedServletPath().
E Implement the PreloadedServlet marker interface.
9. You are writing a order tracking application where customers, sales, and inventory are the primary focus of the application. You are developing an EJB that encapsulates Customer information that must write records into a database using a combination of stored procedures. What type of bean(s) should be used to accommodate this requirement?
A An Entity bean with bean-managed persistence
B A Stateless Session bean
C An Entity bean with container-managed persistence
D A combination of 2 Stateless Session beans
E An entity bean with CallableStatment persistence
F An Entity bean with a customized Deployment Descriptor
10. The developer is writing a database applet that uses an ODBC driver and the Type 1, JDBC-ODBC bridge database driver. What special considerations must be taken to accommodate the database driver?
A No special considerations need to be taken
B The ODBC driver and JDBC-ODBC drivers must be installed on the client machine
C The database must reside on the same machine as the web server
D The Type 1 driver cannot be used with applets
E The JDBC-ODBC port on the web server must be opened
F A proxy server must be set up to marshall database calls back to the web server
11. Some servlet engines can optimize their use of resources by storing some inactive sessions to disk or load balancing by transmitting session data to another server. What can the servlet writer do to best facilitate this functionality?
A Make objects bound to sessions be subclasses of SerializableServlet.
B Bind no objects to sessions.
C Make the servlet implement the SerializableServlet interface.
D Make the servlet throw a ServletException in doSerialize().
E Make objects bound to sessions implement the Serializable interface.
12. When you create a URL object using the new operator, what type of exception is capable of being thrown by the URL constructor?
A MalformedURLException
B BadURLException
C CreateURLException
D ConnectException
E ProtocolException
13. The developer is designing a large scale series of untrusted applets that must connect to JDBC databases. What type of JDBC driver(s) provides the most flexibility in terms of where the database can be located in relation to the web server?
A JDBC Type 3
B JDBC Type 3 and Type 4
C JDBC Type 1
D JDBC Type 2
E JDBC Type 4
F None of the JDBC drivers work with untrusted applets
14. The developer is porting an existing 2-tier client server system to a multi-tier EJB system. Much of the logic in the existing system needs to be reused in the new system. In general, what is the most suitable type of bean to model this new system?
A Stateful Session beans
B An Entity bean with container-managed persistence
C An entity bean with bean-managed persistence.
D No particular bean type models 2 tier systems easily -- the application must be redesigned.
E An entity bean that calls stored procedures to reuse existing business logic.
F Stateless session beans
15. The developer writes an application that uses a stateful session bean to control access to a database through stored procedures. How can a transaction be started in one method and committed in another?
A The session bean must use the database's transaction control by writing SQL to control the transaction.
B Use the ejbContext.commit() method.
C The SessionSynchronization interface returns a UserTransaction object whose commit() method can be called.
D Use the ejbContext.getUserTransaction().commit() method.
E This scenario cannot be done within stateless session beans.
F Use a JNDI lookup to gain access to the transaction manager and call its commit() method.