• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

OCEJWCD 6 Mock Exam – 5

February 7, 2014 //  by Krishna Srinivasan//  Leave a Comment

1 . Assume that the following header is present in a request sent to a servlet:

Accept: image/gif, image/jpeg, image/bmp

What will be returned when the servlet code calls request.getHeader(“Accept”)?

Choose the one below:

  1. A Header object containing, name as “Accept” and value as “image/gif”
  2. A Header object containing, name as “Accept” and value as “image/gif, image/jpeg, image/bmp”
  3. A String array containing “image/gif””
  4. A String containing “image/gif, image/jpeg, image/bmp”
  5. A String array containing “image/gif”, “image/jpeg”, image/bmp”

2 . You need to send large amount of binary data from the browser to a servlet to be processed?
(Say, you want to attach a file while sending email through a web based system)
What HTTP method would you use?

  1. GET
  2. POST
  3. HEAD
  4. HIDDEN
  5. PUT

3 . Which of the following is a possible way to configure an HttpSessionAttributeListener?

  1. By calling HttpSession.addAttributeListener(…)
  2. By calling HttpSession.addHttpSessionAttributeListener(…)
  3. An object of a class implementing this interface is automatically configured when it is added to the session
  4. None of these

4 . Servlet Container calls the init method on a servlet instance…?

  1. For each request to the servlet
  2. For each request to the servlet that causes a new session to be created
  3. For each request to the servlet that causes a new thread to be created
  4. Only once in the life time of the servlet instance
  5. If the request is from the user whose session has expired
  6. Initialy when the servlet instance is create and then at request time if the request is from the user whose session has expired

5 . Which of the following methods may be called on a custom tag handler that implements IterationTag interface?

  1. doStartTag
  2. doBodyTag
  3. doAfterBody
  4. doInitBody
  5. doEvalBody

6 . Which of the following elements of web.xml defines a mapping between a servlet and a URL pattern?

  1. mapping
  2. servlet-url
  3. url_mapping
  4. url_pattern
  5. servlet-mapping

7 . Following is the code for doGet() method of TestServlet. Which of the given statements about it are correct?

public void doGet(HttpServletRequest req, HttpServletResponse res)

{

    try

    {

        RequestDispatcher rd = this.getServletContext().getRequestDispatcher("Login.jsp"); // 1

        rd.forward(req, res); // 2

    }

    catch(Exception e)

    {

        e.printStackTrace();

    }

}

Choose the one below:

  1. This will not compile
  2. This will compile but will not work as expected
  3. This code will work just fine
  4. It will compile but not work properly if //1 is replaced with:
    RequestDispatcher rd = req.getRequestDispatcher(“Login.jsp”);
  5. It will compile and will work properly if //1 is replaced with:
    RequestDispatcher rd = req.getRequestDispatcher(“Login.jsp”);

8 . Consider the web.xml snippet shown in the exhibit? Now consider the code for a jsp file named unprotected.jsp:

<html>

    <body>

        <jsp:include page="/jsp/protected.jsp" />

    </body>

</html>

Which of the following statements hold true when unprotected.jsp is requested by an unauthorized user?

<web-app>

    ...

    <security-constraint>

        <web-resource-collection>

            <web-resource-name>test</web-resource-name>

            <url-pattern>/jsp/protected.jsp</url-pattern>

        </web-resource-collection>

        <auth-constraint>

            <role-name>manager</role-name>

        </auth-constraint>

    </security-constraint>

    ...

</web-app>

Choose the one below:

  1. The user will be prompted to enter user name and password
  2. An exception will be thrown
  3. protected.jsp will be executed but it’s output will not be included in the response
  4. The call to include will be ignored
  5. None of these

9 . Which of the following JSP elements can have a <jsp:param …> element in its body?

  1. <jsp:include …>
  2. <%@ include …>
  3. <jsp:directive.include …/>
  4. <%@ forward …>
  5. <jsp:action …>

10 . Which of the following implicit variables should be used by a jsp page to access a resource and to forward a request to another jsp page?

  1. pageContext and config
  2. application and config
  3. config and pageContext
  4. application for both
  5. config for both

11 . In which of the following situations will a session be definitely invalidated?

  1. The container is shutdown and brought up again
  2. No request comes from the client for more than “session timeout” period
  3. A servlet explicitly calls invalidate() on a session object
  4. A servlet explicitly calls invalidate() on a session object

12 . Your jsp page uses classes from java.util package. Which of the following statement would allow you to import the package?

  1. <%@import java.util.* %>
  2. <%import=”java.util.*”@%>
  3. <%@ page import=”java.util.*”%>
  4. <%@ page java=”java.util.*”@%>
  5. <%@ page import=”java.util.*”@%>

13 . Consider the following contents for two JSP files:

In file companyhome.jsp:

<html><body>

Welcome to ABC Corp!

<%@ page errorPage="simpleerrorhandler.jsp" %>

<%@ include file="companynews.jsp" %>

</body></html>
In file companynews.jsp:

<%@ page errorPage="advancederrorhandler.jsp" %>

<h3>Todays News</h3>

Which of the following statements are correct?

Choose the one below:

  1. When companyhome.jsp is requested, the output will contain “welcome…” as well as “Todays News”
  2. companyhome.jsp will not compile
  3. companynews.jsp will not compile
  4. Both the files will compile but will throw an exception at runtime
  5. None of these

14 . Which method of RegisterServlet will be called when the user clicks on “Submit” button for the following form?
Assume that RegisterServlet

<html>

<body>

  <form action="/myapp/RegisterServlet">

    <input type="text" name="method" value="POST">

    <input type="text" name="name">

    <input type="password" name="password">

    <input type="submit" value="POST">

  </form>

</body>

</html>

Choose the one below:

  1. servicePost(HttpRequest, HttpResponse);
  2. doPOST(HttpRequest, HttpResponse);
  3. post(HttpRequest, HttpResponse);
  4. doPost(HttpRequest, HttpResponse);
  5. None of the above

15 . You are building the server side of an application and you are finalizing the interfaces that you will provide to the client side. But you have not yet decided whether the business rules will be fully implemented as stored procedures or in the java code. Which design pattern you should use to mitigate this concern?

  1. Model View Controller
  2. Data Access Object
  3. Business Delegate
  4. Facade
  5. Transfer Object

16 . Which of the following XML frgaments correctly define the <login-config> element of web.xml?

1.  <login-config>

    <auth-method>CLIENT-CERT</auth-method>

    <realm-name>test</realm-name>

    </login-config>

2.  <login-config>

    <auth-method>CLIENT-CERT</auth-method>

    <realm-name>test</realm-name>

    <form-login-config>

        <form-login-page>/jsp/login.jsp</form-login-page>

        <form-error-page>/jsp/error.jsp</form-error-page>

    </form-login-config>

    </login-config>

3.  <login-config>

    <auth-method>FORM</auth-method>

    <realm-name>test</realm-name>

    <form-login-config>

        <form-login-page>/jsp/login.jsp</form-login-page>

        <form-error-page>/jsp/error.jsp</form-error-page>

    </form-login-config>

    </login-config>

4.  <login-config>

    <auth-method>FORM</auth-method>

    <realm-name>test</realm-name>

    </login-config>

5.  <login-config>

    <auth-method>SECURE</auth-method>

    <realm-name>test</realm-name>

    </login-config>

Choose the one below:

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5

17 . What are the following deployment descriptor elements used for
<login-config> <security-constraint> <security-role>?

  1. Authorization
  2. Authentication
  3. Privacy
  4. Authentication and Authorization
  5. Data integrity

18 . You want to do some calculations within the object whenever it is added to the session. What would you do to accomplish this?

  1. Make the class of the object implement HttpSessionBindingListener
  2. Configure a HttpSessionAttributeListener in deployment descriptor
  3. Make the class of the object implement HttpSessionListener
  4. Configure a HttpSessionActivationListener in deployment descriptor
  5. Only way is to configure a HttpSessionAttributeListener in the deployment descriptor

19 . GET method is not suitable for which of the following operations?

  1. Retrieving an image
  2. Retrieving a zip file
  3. Submitting a form not containing login or other critcal information
  4. Submitting a login form
  5. Updating a database

20 . In the case of JSP pages, what is the type of the implicit variable ‘out’?

  1. OutputStream
  2. PrintStream
  3. PrintWriter
  4. JspWriter
  5. DataOutputStream

21 . Match the following?

Comment
directive
declaration
scriptlet
Custom tag
expression

Choose the one below:

  1. <tags:simple name=’bob’ />
  2. <%=request.getParameter(“name”)%>
  3. <%request.getParameter(“name”);%>
  4. <jsp:directive.include file=’hello.jsp’ />
  5. <%– String x = “123” –%>
  6. <%!String x = “123”; %>

22 . Consider the following tag occuring in a JSP page:

<%@page import="java.util.*"%>;

Which of the following is the XML equivalent of the above tag?

Choose the one below:

  1. <directive.page import=”java.util.*”/>
  2. <page import=”java.util.*”/>
  3. <%jsp:directive.page import=”java.util.*”%>
  4. <sp:page import=”java.util.*”/>
  5. <jsp:directive.page import=”java.util.*”/>

23 . Your servlet may throw IOException while processing a request.You want to define an error page in your deployment descriptor so that whenever IOException is thrown,this page is serviced to the browser. Which of the following XML fragments correctly specify the mapping?

1.  <error-page>

    <exception>java.io.IOException</exception>

    <location>/html/Test.html</location>

    </error-page>

2.  <error-page>

    <exception-class>java.io.IOException</exception-class>

    <location>/html/Test.html</location>

    </error-page>

3.  <error-page>

    <exception-type>java.io.IOException</exception-type>

    <page-location>/html/Test.html</page-location>

    </error-page>

4.  <error-page>

    <exception-type>java.io.IOException</exception-type>

    <location>/Enthuse/html/Test.html</location>

    </error-page>

5.  <exception>

    <exception-type>java.io.IOException</exception-type>

    <location>/Enthuse/html/Test.html</location>

    </exception>

Choose the one below:

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5

24 . How can you ensure the continuity of the session while using HttpServletResponse.sendRedirect() method when cookies are not supported by the client?

  1. By using hidden parameters
  2. By enconding the redirect path with HttpServletResponse.encodeRedirectURL() method
  3. By using HttpSession.encodeURL() method
  4. By using HttpServletRequest.encodeURL() method
  5. By using HttpServletResponse.encodeURL() method

25 . Which of the following XML fragments correctly defines a role named “manager” in web.xml?

1.  <security-role>manager</security-role>

2.  <security-role rolename=manager></security-role>

3.  <security>

    <role-name>manager</role-name>

    </security>

4.  <security-role>

    <role-name>manager</role-name>

    </security-role>

Choose the one below:

  1. 1
  2. 2
  3. 3
  4. 4

26 . Which of the following methods of HttpServletRequest can be used to retrieve the parameter values sent from the browser?

  1. getParameter(String name);
  2. getParameter(String name, String defaultValue);
  3. getParameterNames();
  4. getParameterValues(String name);
  5. getParameters(String name);

27 . Consider the code for the web.xml for a web application (See exhibit)?
Assume that a request: http://localhost:8080/test/aaa/abc.a is sent to this web application named test?

<?xml version="1.0" encoding="ISO-8859-1"?>

<!-- Assume that DOCTYPE is valid -->

<!DOCTYPE web-app

    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.4//EN"

    "http://java.sun.com/dtd/web-app_2_4.dtd">

<web-app>

    <servlet>

        <servlet-name>TestServlet</servlet-name>

        <jsp-file>/requestinfo.jsp</jsp-file>

    </servlet>

    <servlet-mapping>

        <servlet-name>TestServlet</servlet-name>

        <url-pattern>*.a</url-pattern>

    </servlet-mapping>

</web-app>

Choose the one below:

  1. Path Info of the request will be /aaa/abc.a
  2. RequestPath of this request will be /test//aaa/abc.a
  3. ContextPath of this request will be /test/aaa
  4. This request will be serviced by requestinfo.jsp
  5. None of these

28 . You are using a tag library with prefix “sequenceengine” which supports a tag named “fib”. This tag expects a parameter named “limit” of type int. Which of the following is a correct use of this tag?

  1. <sequenceengine:fib>20</sequenceengine:fib>
  2. <fib:sequenceengine>20</fib:sequenceengine>
  3. <sequenceengine:fib attribute-name=”limit” attribute-value=”20″></sequenceengine:fib>
  4. <sequenceengine:fib limit=”20″></sequenceengine:fib>
  5. <fib:sequenceengine limit=”20″></fib:sequenceengine>

29 . How can you redirect the request from a servlet to another resource if the servlet encounters an exception?

  1. This cannot be done unless the exception is caught in the servlet
  2. By specifying a mapping between exception class and the resource in web.xml
  3. This can be done only if the exception is a subclass of javax.servlet.ServletException
  4. This can be done even if the exact class of the exception is not known at compile time

30 . Which of the given options correctly declare a useBean tag?

  1. <jsp:useBean id=”user” class=”myco.util.User” />
  2. <jsp:useBean id=”user” type=”myco.interfaces.IUser” />
  3. <jsp:useBean name=”user” class=”myco.util.User” />
  4. <jsp:useBean id=”user” beanName=”myco.User” class=”myco.util.User” />
  5. <jsp:useBean id=”user” beanName=”myco.User” type=”myco.interfaces.IUser” />

Answers

1 : 4 is correct.

2 : 2 is correct.

3 : 4 is correct.

4 : 4 is correct.

5 : 1 & 3 is correct.

6 : 5 is correct.

7 : 3 & 5 is correct.

8 : 5 is correct.

9 : 1 is correct.

10 : 4 is correct.

11 : 2,3 & 4 is correct.

12 : 3 is correct.

13 : 2 is correct.

14 : 5 is correct.

15 : 3 is correct.

16 : 1,2 & 3 is correct.

17 : 4 is correct.

18 : 1 is correct.

19 : 4 & 5 is correct.

20 : 4 is correct.

21 :
comment – <%– String x = “123” –%>
directive – <jsp:directive.include file=’hello.jsp’ />
declaration – <%!String x = “123”; %>
scriptlet – <%request.getParameter(“name”);%>
custom tag – <tags:simple name=’bob’ />
expression – <%=request.getParameter(“name”)%>
22 : 5 is correct.

23 : 4 is correct.

24 : 2 is correct.

25 : 4 is correct.

26 : 1 & 4 is correct.

27 : 4 is correct.

28 : 4 is correct.

29 : 2 & 4 is correct.

30 : 1,2 & 5 is correct.

Category: CertificationsTag: OCEJWCD, OCEJWCD 6

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: « OCEJWCD 6 Mock Exam – 4
Next Post: OCEJWCD 6 Mock Exam – 6 »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

New Features in Spring Boot 1.4

Difference Between @RequestParam and @PathVariable in Spring MVC

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact