OCEJWCD 6 Mock Exam – 4

1 . Consider the following web.xml code:

<servlet>

        <servlet-name>BankServlet</servlet-name>

        <servlet-class>com.abc.bankapp.BankServlet</servlet-class>

        <security-role-ref>

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

            <role-link>supervisor</role-link>

        </security-role-ref>

    </servlet>

Which of the following statements are correct?

Choose the one below:

  1. The servlet code should use “manager” as a parameter in request.isUserInRole() method
  2. The servlet code can use “manager” or “supervisor” as a parameter in request.isUserInRole() method
  3. The servlet code should use”supervisor” as a parameter in request.isUserInRole() method
  4. The role of “manager” must be defined in the servlet container
  5. None of these

2 . You are designing a complex webapp that uses multi tier architecture.The application must provide interfaces for HTML as well as XML and should be maintainable.Which design pattern would you use?

  1. Data Access Object
  2. Business Deligate
  3. MVC
  4. Remote Method Invocation
  5. Transfer Object

3 . Which of the following directives are applicable ONLY for tag files?

  1. attribute
  2. variable
  3. page
  4. include
  5. import
  6. tag

4 . Which of the following are correct about FORM based authentication mechanism?

  1. HTML FORM is used to capture the username and password of the user
  2. Password is transmitted as plain text
  3. Password is transmitted in an encrypted form
  4. Password is transmitted either in encrypted text or in plain text depending on the browser
  5. This mechanism can be used over HTTPS

5 . Which pattern allows you to replace the presentation logic without much impact on the data representation?

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

6 . Identify the elements that help describe the attribute characteristics of a JSP custom tag in a TLD file?

  1. value
  2. name
  3. description
  4. rtexprvalue
  5. class

7 . Select the correct return types for ServletContext.getResource() and ServletContext.getResourceAsStream() methods?

  1. java.io.Resource and java.io.InputStream
  2. java.io.Resource and java.io.BufferedInputStream
  3. java.net.URL and java.io.InputStream
  4. java.io.File and java.io.InputStream
  5. java.net.URL and java.io.FileInputStream

8 . What will be the output?

<html>

 <body>

   <% String a = "aaa"; %>

   <%! String a = "AAA"; %>

   <% String b = "bbb"; %>

   <%! String b = "BBB"; %>

   <% out.println(a+b); %>

 </body>

</html>

Choose the one below:

  1. aaabbb
  2. aaaBBB
  3. AAAbbb
  4. AAABBB
  5. Compilation error!

9 . Which of the following are valid values for the <transport-guarantee> element?

  1. CONFIDENTIAL
  2. INTEGRAL
  3. SECURE
  4. ENCRYPTED
  5. NONE

10 . Write the parent element of <session-timeout> element?

11 . Consider the tag handler class shown in exhibit.What will be printed when the above tag is used as follows in a jsp page?

Hello <mylib:mytag> World!</mylib:mytag>

public class MyTag extends TagSupport

{

    public int doAfterBody()

    {

        try

        {

            pageContext.getOut().println("In doAfterBody()");

        }

        catch(Exception e)

        {

        }

        return SKIP_BODY;

    }

}

Choose the one below:

  1. Hello
  2. Hello World!
  3. Hello In doAfterBody() World!
  4. Hello In doAfterBody()
  5. None of the above

12 . Which of the following HTTP protocol methods is eligible to produce unintended side effects upon multiple identical invocations beyond those caused by single invocation?

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

13 . Which method of ServletResponse would you use to set its content type?

  1. setParameter
  2. setHeader
  3. setAttribute
  4. setContentType
  5. None of the above

14 .

<jsp:useBean id="mybean" beanName="my.app.MyBean" class="my.app.MyBean" />

is a valid useBean declaration?

Choose the one below:

  1. True
  2. False

15 . Which of the following lines can be used to retrieve a servlet initialization parameter “dbname” from the init() method of a servlet?

public void init()

{

 String dbname = //1 : Insert line here

}

Choose the one below:

  1. getServletConfig().getParameter(“dbname”);
  2. getServletConfig().getInitParameter(“dbname”);
  3. getServletContext().getInitParameter(“dbname”);
  4. getInitParameter(“dbname”);
  5. getInitParameterValue(“dbname”);

16 . Consider the following description of a tag in a TLD?

<tag>

    <name>SmilyTag</name>

    <tag-class>com.enthuware.ctags.SmilyTag</tag-class>

    <description>

    Replaces emoticons such as :), :D, and :(   with images.

    </description>

    <body-content>tagdependent</body-content>

    <attribute>

    <name>name</name>

    <required>false</required>

    <rtexprvalue>true</rtexprvalue>

    </attribute>

</tag>

Which of the following statements regarding the above tag are correct?

Choose the one below:

  1. It is an empty tag
  2. It may be used as an empty tag
  3. It must have a body
  4. It must implement BodyTag interface
  5. It may take an attribute named ‘name’.But if present,its value must be dynamic

17 . Which of the following jsp fragments will print all the parameters and their values present in a request?

1. <% Enumeration enum = request.getParameterNames();

   while(enum.hasMoreElements()) {

   Object obj = enum.nextElement();

   out.println(request.getParameter(obj));

   } %>

2. <% Enumeration enum = request.getParameters();

   while(enum.hasMoreElements()) {

   String obj = (String) enum.nextElement();

   out.println(request.getParameter(obj));

   } %>

3. <% Enumeration enum = request.getParameterNames();

   while(enum.hasMoreElements()) {

   String obj = (String) enum.nextElement();

   out.println(request.getParameter(obj));

   } %>

4. <% Enumeration enum = request.getParameterNames();

   while(enum.hasMoreElements()) {

   Object obj = enum.nextElement(); %>

   <%=request.getParameter(obj); %>

   <% } %>

5. <% Enumeration enum = request.getParameterNames();

   while(enum.hasMoreElements()) {

   String obj = (String) enum.nextElement(); %>

   <%=request.getParameter(obj)%>

   <% } %>

Choose the one below:

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

18 . Which of the following statements are valid JSP directive?

  1. <%! int k = 10 %>
  2. <% int k = 10; %>
  3. <%=somevariable%>
  4. <%@ taglib uri=”http://www.abc.com/tags/util” prefix=”util” %>
  5. <%@ page language=”java” import=”com.abc.*”%>

19 . 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

20 . Which of the following are valid implicit variables in a JSP page?

  1. error
  2. page
  3. this
  4. root
  5. context

21 . A Tag Handler implements BodyTag interface.How many times its doAfterBody method may be called?

  1. BodyTag does not support doAfterBody
  2. 0
  3. 1
  4. 0 or 1
  5. Any number of times

22 . You have configured a listener class (see exhibit) in web.xml of a web application?
Now, consider the following code for the doGet() method of a servlet for the same web application?

public void doGet(HttpServletRequest req, HttpServletResponse res)

{

    System.out.println(this.getServletContext().getAttribute("key"); //2

}

Which option can be inserted at //1 in the listener code so that servlet code at //2 prints 100?

import javax.servlet.*;

public class MyListener implements ServletContextListener

{

    public void contextInitialized(ServletContextEvent sce)

    {

        Integer key = new Integer(100);

        // 1 Insert code here.

    }

    public void contextDestroyed(ServletContextEvent sce)

    {

    }

}

Choose the one below:

  1. this.setAttribute(“key”, key);
  2. this.getServletContext().setAttribute(“key”, key);
  3. this.getContext().setAttribute(“key”, key);
  4. sce.getContext().setAttribute(“key”, key);
  5. sce.getServletContext().setAttribute(“key”, key);

23 . Which of the following interfaces declares the methods jspInit() and jspDestroy()?

  1. javax.servlet.jsp.JSP
  2. javax.servlet.jsp.JspServlet
  3. javax.servlet.jsp.JspPage
  4. javax.servlet.jsp.HttpJspPage
  5. javax.servlet.jsp.HttpJspServlet

24 . Which of the following statements are correct JSP directives?

  1. <%@ page %>
  2. <%! taglib uri=”http://www.abc.com/tags/util” prefix=”util” %>
  3. <% include file=”/copyright.html”%>
  4. <%@ taglib uri=”http://www.abc.com/tags/util” prefix=”util” %>
  5. <%$ page language=”java” import=”com.abc.*”%>

25 . Which of the following classes hides the implementation details and provides a standard API to the services provided by the servlet container to a jsp page?

  1. HttpSession
  2. Servlet
  3. JspPage
  4. ServletContext
  5. PageContext

26 . Which of the following are true regarding the parameters defined using the <context-param> element of a deployment descriptor?

  1. They are thread safe
  2. They are accessible from multiple threads simultaneously and from any servlet of the web application
  3. They can be modified using the setAttribute() method
  4. They can be modified using the setParameter() method
  5. They can be modified using the setInitParameter() method

27 . How can you explicitly expunge the session object?

  1. You cannot. It can only be expunged automatically after session timeout expires
  2. By calling invalidate() on session object
  3. By calling expunge() on session object
  4. By calling delete() on session object
  5. By calling finalize() on session object

28.You have declared a useBean tag as

<jsp:useBean id="man" class="animal.Human" scope="application"/>

In which type of object will this bean be kept?

Choose the one below:

  1. Servlet
  2. HttpSession
  3. ServletContext
  4. ServletConfig
  5. ApplicationContext

29 . Which of the following is a sensible way of sending an error page to the client in case of a business exception that extends from java.lang.Exception?

  1. Catch the exception and use RequestDispatcher to forward the request to the error page
  2. Don’t catch the exception and define the ‘exception to error-page’ mapping in web.xml
  3. Catch the exception, wrap it into ServletException and define the ‘business exception to error-page’ mapping in web.xml
  4. Catch the exception, wrap it into ServletException, and define the ‘ServletException to error-page’ mapping in web.xml
  5. Don’t do anything, the servlet container will automatically send a default error page

30 . Business delegate pattern should be used to enable communication between the JSP code and the enterprise javabeans?

Choose the one below:

  1. True
  2. False

Answers

1 : 1 is correct.

2 : 3 is correct.

3 : 1,2 & 6 is correct.

4 : 1,2 & 5 is correct.

5 : 1 is correct.

6 : 2,3 & 4 is correct.

7 : 3 is correct.

8 : 1 is correct.

9 : 1,2 & 5 is correct.

10 : session-config.

11 : 1 is correct.

12 : 2 is correct.

13 : 4 is correct.

14 : 2 is correct.

15 : 2 & 4 is correct.

16 : 2 & 4 is correct.

17 : 3 & 5 is correct.

18 : 4 & 5 is correct.

19 : 2 is correct.

20 : 2 & 3 is correct.

21 : 5 is correct.

22 : 5 is correct.

23 : 3 is correct.

24 : 1 & 4 is correct.

25 : 5 is correct.

26 : 1 & 2 is correct.

27 : 2 is correct.

28 : 3 is correct.

29 : 1 & 3 is correct.

30 : 1 is correct.

Comments

comments

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.