OCEJWCD 6 Mock Exam – 6

SHARE & COMMENT :

1 . Which constant is used to notify the container to reevaluate the custom tag’s body?

  1. EVAL_BODY
  2. EVAL_BODY_TAG
  3. EVAL_BODY_AGAIN
  4. EVAL_BODY_INCLUDE

2 . Which of the following statements regarding the JSP action tag are TRUE?

  1. Provides translation-time instructions to the JSP engine
  2. Can be used to declare a JavaBean instance in a JSP page
  3. Can be used to generate HTML code to embed an applet on a web page
  4. User-defined actions can be created
  5. Language is a standard JSP action

3 . Which of the following methods can be used to pass request to another servlet to handle by using the RequestDispatcher?

  1. request(ServletRequest req, ServletResponse res)
  2. include(ServletRequest req, ServletResponse res)
  3. dispatch(ServletRequest req, ServletResponse res)
  4. forward(ServletRequest req, ServletResponse res)
  5. process(ServletRequest req, ServletResponse res)

4 . What will be the output?

import javax.servlet.*;
    import javax.servlet.http.*;

    public class MyServlet extends GenericServlet {

        public void init() {                      //1
            // Do something
        }

        public void init(ServletConfig config)    //2
        throws ServletException{
            // Do something
            super.init(config);                   //3
        }

        public void destroy() {                   //4
            // Do something
        }

        public void service(ServletRequest req,   //5
        ServletResponse res) {
            // Do something
        }
    }

Choose the one below:

  1. Method //1 is necessary for this code to compile
  2. Method //2 is necessary for this code to compile
  3. Line //3 is necessary for this code to run
  4. Method //4 is necessary for this code to compile
  5. Method //5 is necessary for this code to compile

5 . Which pattern is normally used to encapsulate database SQL statement?

  1. Value Object
  2. Data Value Object
  3. Data Access Object
  4. Business Object
  5. Business Delegate

6 . For special character used in request URI, which of the following statements are correct?

  1. The ampersand (&) is used to separate name/value pairs
  2. The plus sign (+) is used to fill blank space
  3. The dash sign (-) is used to separate the name and value
  4. The percent sign (%) is used to start a query string

7 . Which statements are TRUE regarding the HttpServlet method doPost(HttpServletRequest req, HttpServletResponse res)?

  1. The method is called by the server (via the service method) to allow a servlet to handle a POST or PUT request
  2. The method is called by the server (via the service method) to allow a servlet to handle a POST or GET request
  3. The method is called by the server (via the service method) to allow a servlet to handle a POST request
  4. The method is called by the server (via the service method) to allow a servlet to handle a GET request
  5. The method allows the client to send data of unlimited length to the Web server a single time
  6. Operations requested through this method will NEVER have side effects

8 . Which of the following design pattern is used to reduce the amount of network traffic when transferring data?

  1. Model View Controller
  2. Data Access Object
  3. Business Delegate
  4. Value Object

9 . What is the authentication type which uses digital certificates as a security mechanism for a web based application?

10 . Which of the following method is used to retrieve the value associated to the init parameter defined in the init-param tag?

  1. getParameter(String name)
  2. getInitParameter(String name)
  3. getParameters()
  4. getInitParameterValue(String name)

11 . Which of the following statements are TRUE for the code given below?

    int MAX_AGE;
    Cookie cookie = new Cookie("user", user);
    cookie.setMaxAge(MAX_AGE);
    response.addCookie(cookie);

Choose the one below:

  1. If MAX_AGE = 10; the cookie will expire after 10 seconds
  2. If MAX_AGE = 10; the cookie will expire after 600 seconds
  3. If MAX_AGE = 0; the cookie will be deleted
  4. If MAX_AGE = -1; the cookie is not stored persistently
  5. If MAX_AGE = -1; the code will generate run-time error

12 . In which directory you will most likely find the file myBaseUtil.jar?

  1. example/WEB-INF
  2. example/lib
  3. example/WEB-INF/lib
  4. example/WEB-INF/classes
  5. example/META-INF/lib

13 . Which of the following requirements are needed for FORM based authentication in a web based application?

  1. The session attribuite j_sessionid must be set
  2. The action or url must be j_security_check
  3. The name attribute for the username must be j_username
  4. The form method must be POST
  5. The name attribute for the password must be j_password
  6. Client side cookie must be enabled

14 . Which of the following deployment descriptor snippet will map the following request URI:

/tech/hello/index.jsp

for web application with context path as “tech”?

1.  <servlet-mapping>
    <servlet-name>HelloWorldServlet</servlet-name>
    <url-pattern>/hello/*</url-pattern>
    </servlet-mapping>

2.  <servlet-mapping>
    <servlet-name>HelloWorldServlet</servlet-name>
    <url-pattern>/hello/*.jsp</url-pattern>
    </servlet-mapping>

3.  <servlet-mapping>
    <servlet-name>HelloWorldServlet</servlet-name>
    <url-pattern>/hello/index.jsp</url-pattern>
    </servlet-mapping>

4.  <servlet-mapping>
    <servlet-name>HelloWorldServlet</servlet-name>
    <url-pattern>hello/*</url-pattern>
    </servlet-mapping>

Choose the one below:

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

15 . Which of the following methods will enable you to get one or more values from a request object?

  1. getParameter(String name)
  2. getParameters(String name)
  3. getAllParameters()
  4. getParameterValues(String name)
  5. getAllAttributes()

16 . Is the following statement TRUE or FALSE?

The four methods for session management in the context of web-based application are: Cookie, HttpSession object, URL rewriting and Hidden value.

Choose the one below:

  1. True
  2. False

17 . Which of the following packages are implicitly imported in the JSP page?

  1. java.lang.*
  2. java.util.*
  3. javax.servlet.*
  4. javax.servlet.jsp.*
  5. javax.servlet.jsp.tagext.*

18 . Which of the following is NOT an authentication method used by a web container?

  1. BASIC
  2. DIGEST
  3. SSL
  4. FORM

19 . Which methods can be used for writing logging message to servlet log file?

  1. log(String msg)
  2. log(int code, String msg)
  3. log(String msg, Throwable t)
  4. log(int code, String msg, Throwable t)

20 . Which tag is used in web.xml to mark a web application to be suitable for running between multiple systems?

  1. multiple
  2. distributable
  3. resource-ref
  4. transferrable
  5. splitable

21 . Which of the following are VALID servlet error attributes?

  1. javax.servet.error.status_code
  2. javax.servet.error.exception
  3. javax.servet.error.uri
  4. javax.servet.error.message
  5. javax.servet.error.query

22. Which statement is TRUE about the following jsp code snippet?

<%
    String theKey = "key";
    String theValue = "value";
    session.removeAttribute(theKey);         //1
%>

    session.setAttribute("<%= theKey %>",
                         "<%= theValue %>"); //2

    session.getAttribute("<%= theKey %>");   //3

<%= session.getAttribute(theKey) %>          //4

Choose the one below:

  1. The code compiles but might have runtime NullPointerException at //1
  2. There will have compilation error at //2 and //3
  3. There will have output as null at //4
  4. There will have output as theValue at //4

23 . Which of the following are VALID taglib configuration?

1.  <taglib>
        ...
        <tag>
            <name>myTag</name>
            <tag-class>MyTag</tag-class>
        </tag>
        ...
    </taglib>

2.  <taglib>
        ...
        <tag>
            <name>myTag</name>
            <tag-class>MyTag</tag-class>
            <body-content>SERVLET</body-content>
        </tag>
        ...
    </taglib>

3.  <taglib>
        ...
        <tag>
            <name>myTag</name>
            <tag-class>MyTag</tag-class>
            <attribute>
                <name>name</name>
            </attribute>
        </tag>
        ...
    </taglib>

4.  <taglib>
        ...
        <tag>
            <name>myTag</name>
            <tei-class>MyTagInfo</tei-class>
            <body-content>JSP</body-content>
        </tag>
        ...
    </taglib>

5.  <taglib>
        ...
        <tag>
            <name>myTag</name>
            <tag-class>MyTag</tag-class>
            <tei-class>MyTagInfo</tei-class>
            <body-content>JSP</body-content>
            <attribute>
                <name>name</name>
                <required>true</required>
                <rtexprvalue>true</rtexprvalue>
                <type>java.lang.String</type>
            </attribute>
        </tag>
        ...
    </taglib>

Choose the one below:

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

24 . Which of the following statement is FALSE regarding JSP page directive attributes default value?

  1. The session attribute has default value as true
  2. The buffer attribute has default value as 8kb
  3. The autoflush attribute has default value as false
  4. The isThreadSafe attribute has default value as true
  5. The isErrorPage attribute has default value as false
  6. The pageEncoding attribute has default value as ISO-8859-1

25 . Which of the following deployment descriptor tags are used for context level parameter initialization?

  1. param-name
  2. context-name
  3. context-param
  4. param-value
  5. context-value
  6. context-attrib

26 . What will be the output?

// Calling servlet:

    public void doGet(HttpServletRequest req,
    HttpServletResponse res) throws ServletException, IOException
    {
        res.setContentType("text/html");
        PrintWriter out = res.getWriter();
        out.println("<HTML><BODY>");
        out.println("I am calling others!");
        RequestDispatcher rd= req.getRequestDispatcher("/MyServlet");
        rd.include(req, res);
        out.println("</BODY></HTML>");
        out.close();
    }

    // Target servlet:

    protected void doGet(HttpServletRequest req,
    HttpServletResponse res) throws ServletException, IOException
    {
        PrintWriter out = res.getWriter();
        out.println("I am called by others!");

Choose the one below:

  1. “I am calling others!”
  2. “I am called by others!”
  3. Both “I am calling others!” and “I am called by others!”
  4. An IllegalStateException is thrown
  5. An IOException is thrown

27 . Which statement is NOT true about the SingleThreadModel interface?

  1. By implementing this interface it ensures that servlets handle only one
  2. If a servlet implements this interface, no two threads will execute concurrently in the servlet’s service method
  3. This interface has no methods
  4. The servlet container will ensure there will be only one instance of the servlet at a time if the servlet implements this interface
  5. Class variables are not protected by this interface, but instance variables are protected

28 . Which of the following method is called upon the initialization of a servlet context?

  1. contextInitializing(ServletContextEvent e)
  2. contextInitial(ServletContext e)
  3. contextInitialize(ServletContext e)
  4. contextInitialize(ServletContextEvent e)
  5. contextInitialized(ServletContextEvent e)

29 . Which of the following statements are TRUE?

  1. XML equivalent for JSP expression <%= expression %> is <jsp:expression>expression</jsp:expression>
  2. XML equivalent for JSP scriptlet <% scriptlet %> is <jsp:scriptlet>scriptlet</jsp:scriptlet>
  3. XML equivalent for JSP declaration <%! declaration %> is <jsp:declaration>declaration</jsp:declaration>.
  4. XML equivalent for JSP include directive <%@ include file=”url” %> is <jsp:include file=”url”/>, where url must be relative
  5. XML equivalent for JSP page directive <%@ page buffer=”16kb” %> is <jsp:page buffer=”16kb”/>

30 . Please select Correct JSP useBean declaration methods?

  1. <jsp:useBean id=”user” beanName=”TestUser” type=”com.test.model.User” />
  2. <jsp:useBean id=”user” beanName=”TestUser” class=”com.test.model.User” />
  3. <jsp:useBean beanName=”TestUser” class=”com.test.model.User” />
  4. <jsp:useBean beanName=”TestUser” class=”com.test.model.User” />
  5. <jsp:useBean id=”user” type=”com.test.model.User” />

31 . Which statement is TRUE regarding the following code?

import javax.servlet.*;
    import javax.servlet.http.*;

    public class MyHttpServlet extends HttpServlet
    implements SingleThreadModel {

        StringBuffer bufferOne = new StringBuffer();            //1

        static StringBuffer bufferTwo = new StringBuffer();     //2

        protected void doGet(HttpServletRequest req,            //3
        HttpServletResponse res) throws java.io.IOException{

            HttpSession session = req.getSession();             //4

            res.setContentType("text/html");
            java.io.PrintWriter out = res.getWriter();
            out.println("<html>");
            out.println("<head>");
            out.println("<title>This is my servlet!</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("</body>");
            out.println("</html>");
            out.close();
        }

Choose the one below:

  1. Variable bufferOne at //1 is NOT thread-safe
  2. Variable bufferTwo at //2 is NOT thread-safe
  3. Both A and B
  4. Variable req at //3 is NOT thread-safe
  5. Variable session at //4 is NOT thread-safe
  6. Both D and E

32 . Select sample web application file listing with appropriate directory structure?

1.  index.html
   /login.jsp
   /images/logo.gif
   /WEB-INF/web.xml
   /WEB-INF/lib/basic.jar
   /WEB-INF/classes/Test.class

2.  /index.html
    /login.jsp
    /images/logo.gif
    /WEB-INF/web.xml
    /WEB-INF/jar/basic.jar
    /WEB-INF/classes/Test.class

3.  /index.html
    /login.jsp
    /images/logo.gif
    /WEB-INF/web.xml
    /WEB-INF/classes/basic.jar
    /WEB-INF/classes/Test.class

4.  /index.html
    /login.jsp
    /images/logo.gif
    /META-INF/web.xml
    /WEB-INF/jar/basic.jar
    /WEB-INF/classes/Test.class

5.  /index.html
    /login.jsp
    /images/logo.gif
    /META-INF/web.xml
    /WEB-INF/lib/basic.jar
    /WEB-INF/classes/Test.class

6.  index.html
    /images/logo.gif
    /WEB-INF/web.xml
    /WEB-INF/jsp/login.jsp
    /WEB-INF/lib/basic.jar
    /WEB-INF/classes/Test.class

Choose the one below:

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

33 . Which of the following data element will definitely be thread-safe?

  1. Local variables
  2. Instance variables
  3. Static variables
  4. Class variables
  5. Context attributes

34 . Select the correct order that JSP methods are invoked by servlet container?

  1. jspInit(), jspService(), jspDestroy()
  2. jspInit(), _jspService(), jspDestroy()
  3. _jspInit(), jspService(), _jspDestroy()
  4. _jspInit(), _jspService(), _jspDestroy()

35 . Which of the following element is not included in a URL?

  1. Client ip
  2. Protocol
  3. Server Name
  4. Query string
  5. Port name

36 . Which of the following listeners is notified when a session is initialized?

  1. HttpSessionBindingListener
  2. SessionBindingListener
  3. HttpSessionListener
  4. HttpSessionListener
  5. HttpSessionChangedListener

37 . Which of the following best describes the life cycle of a JSP?

1.  JSP page is translated into a servlet code
    Servlet code is compiled
    Servlet is loaded into memory
    Servlet instance is created

2.  JSP page is translated into a servlet code
    Servlet is loaded into memory
    Servlet code is compiled
    Servlet instance is created

3.  JSP is compiled
    JSP is translated into a servlet code
    Servlet is loaded into memory
    Servlet instance is created

4.  JSP is loaded into memory
    Servlet code is compiled
    Servlet instance is created
    Servlet is loaded into memory

5.  JSP page is translated into a servlet code
    Servlet code is compiled
    Servlet instance is created
    Servlet is loaded into memory

Choose the one below:

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

38 . Please identify the three methods declared in javax.servlet.Filter?

  1. service
  2. init
  3. destroy
  4. filter
  5. doFilter

39 . Which of the following deployment descriptor segments are VALID for security-related configuration of a web application?

1.  <login-config>
    <auth-method>FORM</auth-method>
    <login-config>
        <form-login-page>/login.jsp</form-login-page>
        <form-error-page>/error.jsp</form-error-page>
    </login-config>
    </login-config>

2.  <security-role>
    <description>My description.</description>
    <role-name>Manager</role-name>
    </security-role>

3.  <security-constraint>
    <web-resource-collection>
        <web-resource-name>SecureStuff</web-resource-name>
        <url-mapping>/servlet/secure</url-mapping>
        <http-method>POST</http-method>
    </web-resource-collection>
    </security-constraint>

4.  <security-constraint>
    <auth-constraint>
        <role-name>Broker</role-name>
    </auth-constraint>
    </security-constraint>

5.  <security-constraint>
    <web-resource-collection>
        <web-resource-name>SecureStuff</web-resource-name>
    </web-resource-collection>
    <auth-constraint>
        <role-name>Broker</role-name>
    </auth-constraint>
    </security-constraint>

Choose the one below:

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

40 . Based on the following information, please construct the full path for the servlet?

docbase = c:/temp/
    context path = /test
    alias name = MyMail
    servlet-name = com.jiris.common.util.MailServlet
    url-pattern = /mail/*

Choose the one below:

  1. c:/temp/mail/com/jiris/common/util/MailServlet.class
  2. c:/temp/test/com/jiris/common/util/MailServlet.class
  3. c:/temp/mail/test/com/jiris/common/util/MailServlet.class
  4. c:/temp/test/mail/com/jiris/common/util/MailServlet.class

41 . The ServletContext object are accessible from which of the following objects?

  1. HttpServlet
  2. GenericServlet
  3. HttpSession
  4. ServletConfig
  5. ServletResponse

42 . Which of the following method is used to store object into a request object?

  1. addAttribute(String name, String obj)
  2. putAttribute(String name, Object obj)
  3. setAttribute(String name, String obj)
  4. setAttribute(String name, Object obj)
  5. addObject(String name, Object obj)

43 . Which request method will be invoked for the following code?

<html>
        <body>
            <form action=´/servlet/comment´>
                <p>Please provide your comment here:</p>
                <input type=´text´ size=´40´ name=´Comment´>
                <input type=´submit´ value=´Submit´>
            </form>
        </body>
</html>

Choose the one below:

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

44 . Which of the following method might be invoked more than one time?

  1. doStartTag()
  2. doInitBody()
  3. doAfterBody()
  4. doEndTag()

45 . Which of the following methods are used to send an error page to the client?

  1. log(String msg)
  2. log(String msg, Throwable t)
  3. sendError(int code)
  4. sendError(int code, String msg)
  5. sendError(int code, String msg, Throwable t)

46 . Which of the following requests should be performed by using a POST method?

  1. Inserting a record into a database
  2. Accessing a static page
  3. Retrieving an image
  4. Sending credit card number
  5. Searching record in a database

47 . Which of the following are Correct ways to define inactive period of 5 minutes of a session before the server invalidates it?

  1. <session-timeout>5</session-timeout>
  2. <session-timeout>300</session-timeout>
  3. session.setMaxInactiveInterval(5);
  4. session.setMaxInactiveInterval(300);
  5. session.invalidate(5);

48 . Which are the two mandatory attributes for JSP taglib directive?

  1. uri
  2. id
  3. name
  4. prefix
  5. value
  6. location

49 . A session can be invalidated by which of the following?

  1. After a default period of inactivity, say 30 minutes
  2. Client side user closes the browser
  3. After a specified period of inactivity, say 10 minutes
  4. Client side user machine crashes
  5. Explicitly invalidate a session through method calls

50 . What is the method declaration for the method used in the HttpServlet class that handles the HTTP GET request?

  1. doGet(ServletRequest req, ServletResponse res)
  2. getPage(ServletRequest req, ServletResponse res)
  3. doGet(HttpServletRequest req, HttpServletResponse res)
  4. service(HttpServletRequest req, HttpServletResponse res)

Answers

1 : 3 is correct.
Explanation: To notify the container to reevaluate the custom tag’s body, you must return a value of IterationTag.EVAL_BODY_AGAIN in the doAfterBody() method.

2 : 2,3 & 4 is correct.
Explanation: jsp:bean declares the use of a JavaBean instance in a JSP page.
jsp:plugin instructs the JSP engine to generate appropriate HTML code for embedding applets on a web page.
Custom tags (taglibs) allow user-defined actions to be created.
Answer 1 is incorrect because the action JSP tag provides request-time instructions to the JSP engine.
Standard action types : jsp:include, jsp:forward, jsp:useBean, jsp:setProperty, jsp:getProperty, jsp:plugin

3 : 2 & 4 is correct.
Explanation: You can use either forward(…) or include(…) method to pass the request to another servlet to handle. While for forward(…), the control is passing to target servlet, for include(…), the control is still with the current servlet.

4 : 3 & 5 is correct.
Explanation: You need to override the service() method when you extends GenericServlet.
You need to call super.init(config) if you override this method.

5 : 2 is correct.
Explanation: A Data Access Object pattern is used to encapsulate database access functions. By putting database-specific SQL code into a separate layer as DAO layer, it is easy to modify it without affecting business logic layer, thus increase code manageability.

6 : 1 & 2 is correct.

7 : 3 & 5 is correct.

8 : 4 is correct.

9 : Client-Cert.
Explanation: The correct answer is CLIENT-CERT which stands for client certificate. It requires the client to provide a digital certificate containing information about the issuer, signature, serial number, key type, etc

10 : 2 is correct.

11 : 1,3 & 4 is correct.

12 : 3 is correct.

13 : 2,3,4 & 5 is correct.

14 : 3 is correct.

15 : 1 & 4 is correct.

16 : 1 is correct.

17 : 1,3 & 4 is correct.

18 : 3 is correct.

19 : 1 & 3 is correct.

20 : 2 is correct.

21 : 1,2 & 4 is correct.

22 : 3 is correct.

23 : 1,3 & 5 is correct.

24 : 3 is correct.

25 : 1,3 & 4 is correct.

26 : 3 is correct.

27 : 4 is correct.

28 : 5 is correct.

29 : 1,2 & 3 is correct.

30 : 1,4 & 5 is correct.

31 : 2 is correct.

32 : 1 & 6 is correct.

33 : 1 is correct.

34 : 2 is correct.

35 : 1 is correct.

36 : 3 is correct.

37 : 1 is correct.

38 : 2,3 & 5 is correct.

39 : 2 & 5 is correct.

40 : 2 is correct.

41 : 1,3 & 4 is correct.

42 : 4 is correct.

43 : 1 is correct.

44 : 3 is correct.

45 : 3 & 4 is correct.

46 : 1 & 4 is correct.

47 : 1 & 4 is correct.

48 : 1 & 4 is correct.

49 : 1,3 & 5 is correct.

50 : 3 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.

Speak Your Mind

*

Close
Please support the site
By clicking any of these buttons you help our site to get better