Sun
Certified Web Component Developer for Java 2 Platform Practice Questions |
|
|
| |
|
|
| Q. No |
Question |
| 1 |
Which of the following files is the correct name and location of deployment
descriptor of a web application. Assume that the web application is rooted at
\doc-root. Select the one correct answer ? |
| |
| |
A |
\doc-root\dd.xml |
| |
B |
doc-root\web.xml |
| |
C |
\doc-root\WEB-INF\web.xml |
| |
D |
\doc-root\WEB_INF\web.xml |
| |
E |
\doc-root\WEB-INF\classes\web.xml |
| |
|
|
|
C |
 |
 |
|
The deployment descriptor must be called web.xml and be placed in the directory named WEB-INF.
|
 |
|
 |
|
|
| 2 |
Which element of the
deployment descriptor is used to specify the class of the Servlet. ?
|
| |
| |
A |
<servlet-class> |
| |
B |
<servlet-name> |
| |
C |
<servlet_name> |
| |
D |
<servlet_class> |
| |
E |
<servlet> |
| |
|
|
|
A |
 |
 |
|
The element servlet-class specifies the class of
servlet.
|
 |
|
 |
|
|
| 3 |
Which of the following statements is true regarding MyServlet?
import javax.servlet.*; import javax.servlet.http.*: import
java.io.*;
public class MyServlet extends HttpServlet implements
SingleThreadModel { String
myName;
public void service(HttpServletRequest
req, HttpServletResponse res) throws ServletException, IOException
{ response.setContentType("text/plain");
PrintWriter out = res.getWriter(); myName =
req.getParameter("name"); sayHello(out); out.close();
}
public void sayHello(PrintWriter out)
{ out.println("Hello " + myName);
} }
|
| |
| |
A |
MyServlet is thread safe |
| |
B |
MyServlet is not thread safe because
myName is an instance variable |
| |
C |
MyServlet is not thread safe because MyServlet implements SingleThreadModel. |
| |
D |
None of the above |
| |
|
|
|
A |
 |
 |
|
Choice A is correct. An application is thread
safe if it always behaves predictably regardless of the
number of concurrent threads running in its process
space. The simplest way to ensure that a servlet is
thread safe is to implement the SingleThreadModel
interface. By implementing this interface, the server
guarantees that no more than one thread can execute the
service(), doGet(), or doPost() method at a time for a
particular servlet instance. This makes the servlet
thread safe. Thus even if class MyServlet has
instance variables, it is thread safe. Thus A is the
correct choice and the other choices are incorrect.
|
 |
|
 |
|
|
| 4 |
Which of the following combinations regarding Design Patterns are correct? |
| |
| |
A |
Business Delegate -
Reduces the coupling between presentation-tier clients and business
services.
|
| |
B |
Data Access Object -
Allows for Multiple Views using the same model |
| |
C |
MVC - Enables easier
migration to different persistence storage implementations.
|
| |
D |
Value Object - Reduces
Network Traffic |
| |
|
|
|
A and D
|
 |
 |
|
Choices A and D are correct. In a normal scenario, presentation-tier components (e.g. a JSP) interact directly with business services. As a result, the presentation-tier components are vulnerable to changes in the implementation of the business services: when the implementation of the business services change, the code in the presentation tier must change. The goal of the Business Delegate object design pattern is to minimize the coupling between presentation-tier clients and the business service API, thus hiding the underlying implementation details of the service. Thus choice A is correct.
Choice B is incorrect as it's the MVC design pattern rather than the DAO (Data Access Object), which provides Multiple Views using the same model.
Choice C is incorrect as it's the DAO (Data Access Object) pattern, which enables easier migration to different persistence storage implementations.
The Value Object is used to encapsulate the business data. A single method call is used to send and retrieve the Value Object. When the client requests business data from an enterprise bean, the enterprise bean can construct the Value Object, populate it with its attribute values, and pass it by value to the client. Thus choice D is also correct.
|
 |
|
 |
|
|
| 5 |
Which of these is true about deployment descriptors. Select one correct answer. |
| |
| |
A |
The order of elements
in deployment descriptor is important. The elements must follow a
specific order. |
| |
B |
The elements of
deployment descriptor are not case insensitive |
| |
C |
The servlet-mapping element, if defined, must be included
within the servlet element. |
| |
D |
The web-app element
must include the servlet element |
| |
|
|
|
A |
 |
 |
|
The
servlet specifications specifies a specific order of
deployment descriptor. b is incorrect because elements
are case-sensitive. The servlet-mapping element should
be included within the <WEB-APP>element. So c is
incorrect. All the elements within the web-app element
are optional. So d is incorrect.
|
 |
|
 |
|
|
| 6 |
Which element of the deployment descriptor includes the exception-type as a sub-element ?
|
| |
| |
A |
<exception> |
| |
B |
<error-page> |
| |
C |
<error> |
| |
D |
<exception_type> |
| |
E |
<error_page> |
| |
|
|
|
B |
 |
 |
|
The
element error-page includes the element web-app.
|
 |
|
 |
|
|
| 7 |
Which of these is a correct fragment within the web-app element of
deployment descriptor. Select the two correct answer. |
| |
| |
A |
<error-page> <error-code>404</error-code>
<location>/error.jsp</location> </error-page>
|
| |
B |
<error-page>
<exception-type>mypackage.MyException</exception-type>
<error-code>404</error-code>
<location>/error.jsp</location> </error-page>
|
| |
C |
<error-page>
<exception-type>mypackage.MyException</exception-type>
<error-code>404</error-code> </error-page> |
| |
D |
<error-page>
<exception-type>mypackage.MyException</exception-type>
<location>/error.jsp</location> </error-page>
|
| |
|
|
|
A and D |
 |
 |
|
error-page element must include either
exception-type or error-code element but not both. It
must also include the location element.
|
 |
|
 |
|
|
| 8 |
Which element of the
deployment descriptor of a web application includes the welcome-file-list
element as a sub element.
|
| |
| |
A |
<welcome> |
| |
B |
<welcome-files> |
| |
C |
<list> |
| |
D |
<web-app> |
| |
E |
<context> |
| |
|
|
|
D |
 |
 |
|
The
<web-app> contains the
<welcome-file-list> element. |
 |
|
 |
|
|
| 9 |
Which of these is a correct example
of specifying a listener element resented by MyClass class. Assume myServlet element is
defined correctly. Select one correct answer. |
| |
| |
A |
<listener>MyClass</listener> |
| |
B |
<listener>
<listener-class>MyClass</listener-class></listener> |
| |
C |
<listener>
<listener-name>aListener</listener-name>
<listener-class>MyClass</listener-class>
</listener> |
| |
D |
<><listener>
<servlet-name>myServlet</servlet-name>
<listener-class>MyClass</listener-class>
</listener> |
| |
|
|
|
B |
 |
 |
|
The
element listener-class must be included within the
listener element.
|
 |
|
 |
|
|
| 10 |
Which of the following is legal JSP syntax to print the value
of i. Select the one correct answer |
| |
| |
A |
<<%int i = 1;%> <%= i; %> |
| |
B |
<%int i = 1; i;
%> |
| |
C |
<%int i =
1%> <%= i %> |
| |
D |
<%int i = 1;%> <%= i %> |
| |
E |
<%int i =
1%> <%= i; %> |
| |
|
|
|
D |
 |
 |
|
When using scriptlets (that is code included
within <% %>), the included code must have legal
Java syntax. So the first statement must end with a
semi-colon. The second statement on the other hand is a
JSP expression. So it must not end with a semi
colon.
|
 |
|
 |
|
|
|
|