• 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 – 2

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

1 . You are using a tag library with prefix “generator”, which supports a tag named “random”.This tag generates a random number and sets it to a variable named “value”.Which of the following will output this value in the page?

  1. <generator:random>value</generator:random>
  2. <generator:random><%=value%></generator:random>
  3. <generator:random><% int value;%> <%=value%></generator:random>
  4. <generator:random><%getParameter(“value”)%></generator:random>
  5. None of the above

2 . Which of the following pairs of HTTP method and HttpServlet class method are a valid combination for a request and the request handler method?

  1. GET – service()
  2. POST – doPost()
  3. GET – doPost()
  4. GET – doGet()
  5. POST – service()

3 . You want to get notified whenever there is a change in the attribute list of the ServletContext of your web application. Which listener interface would you implement?

  1. ServletListener
  2. ServletContextListener
  3. ServletContextAttributeListener
  4. HttpServletContextListener
  5. HttpServletListener

4 . A JSP page myerror.jsp has been invoked as a result of an exception from another JSP page. How can you access the Throwable object that refers to the exception in myerror.jsp?

  1. Using the implicit variable error
  2. Using the implicit variable request.error
  3. Using the implicit variable exception
  4. Using the implicit variable throwable
  5. None of these because the class of the implicit variable is not java.lang.Throwable

5 . Which of the following are valid return values for doStartTag() method?

  1. BodyTag.SKIP_BODY
  2. Tag.SKIP
  3. Tag.EVAL_BODY_INCLUDE
  4. Tag.EVAL_BODY_AGAIN
  5. BodyTag.EVAL_BODY_BUFFERED

6 . Which of the following statements are correct for a custom tag that can take any number of arbitrary attributes?

  1. The body-content element for the tag in the TLD file must have a value of JSP
  2. The tag handler must implement the method setAttribute(String key, String value)
  3. The tag element in the TLD file for the tag must have <dynamic-attributes>true</dynamic-attributes>
  4. The class implementing the tag must implement javax.servlet.jsp.tagext.DynamicAttributes interface
  5. Dynamic attributes cannot have request time expression values
  6. A JSP page sets a dynamic attribute using <jsp:setDynamicAttribute> action

7 . Assuming that occurs before the use of the custom tags of the tag library named utils, identify the possibly valid empty custom tag declarations. (Assume that transpose is a valid tag in the given tag library.)

  1. <util:transpose/>
  2. <util:transpose></util:transpose>
  3. <util:transpose>200</util:transpose>
  4. <taglib:util:transpose />
  5. None of the above is correct as every tag has to have a body

8 . Which of the following defines the class name of a tag in a TLD?

  1. tag-class-name
  2. tag-class
  3. class-name
  4. class

9 . What should be the value of subelement of element in a TLD file if the tag should not have any contents as its body?

  1. blank
  2. empty
  3. null
  4. false
  5. The <body-content> subelement itself should be absent

10 . Which interface and method should be used to retrieve a servlet initialization parameter value?

  1. ServletConfig : getParameter(String name)
  2. ServletConfig : getInitParameter(String name)
  3. ServletContext: getInitParameter(String name))
  4. ServletConfig : getInitParameters(String name)
  5. ServletConfig : getInitParameterNames(String name)

11 . You need to put a com.enthu.User bean referred by ‘userBean’ variable in request scope with an ID of “user” from within a servlet. Which of the following statements accomplishes this task?

  1. request.put(“user”, userBean);
  2. request.add(userBean, “user”);
  3. request.putAttribute(“user”, userBean);
  4. request.setAttribute(“user”, userBean);
  5. request.setParameter(userBean, “user”);
  6. request.put(userBean, “user”);

12 . Consider the following code:

public class MyTagHandler extends TagSupport

{

  public int doStartTag() throws JspException

  {

    try

    {

      //insert code here

    }

    catch(Exception e){ }

    return super.doStartTag();

  }

}

Which of the following options, when inserted in the above code causes the value “hello” to be output?
Choose the one below:

  1. JspWriter out = pageContext.getOut();
    out.print(“hello”);
  2. JspWriter out = pageContext.getWriter();
    out.print(“hello”);
  3. JspWriter out = getPageContext().getWriter();
    out.print(“hello”);
  4. JspWriter out = new JspWriter(pageContext.getWriter());
    out.print(“hello”);
  5. JspWriter out = getPageContext().getOut();
    out.print(“hello”);

13 . Which of the following is a correct JSP declaration for a variable of class java.util.Date?

  1. <%! Date d = new Date() %>
  2. <%@ Date d = new Date() %>
  3. <%! Date d = new Date(); %>
  4. <%$ Date d = new Date() %>

14 . Which method can be invoked on a session object so that it is never invalidated by the servlet container automatically?

  1. setTimeOut(-1)
  2. setTimeOut(Integer.MAX_INT)
  3. setTimeOut(0)
  4. setMaxInactiveInterval(-1)
  5. setMaxInactiveInterval(Integer.MAX_INT)

15 . Which of the following elements are mandatory under the element of a deployment descriptor?

  1. <doctype>
  2. <app-name>
  3. <servlet>
  4. <doc-root>
  5. None of these

16 . Which of the following implicit variables should be used by a jsp page to access a page initialization parameter?

  1. pageContext
  2. application
  3. config
  4. context
  5. page

17 . You are given a tag library that has:

1. A tag named getMenu that takes an attribute 'subject' which can be a dynamic value.
2. A tag named getHeading that takes an attribute 'report'.

Which of the following are correct uses of this library?

Choose the one below:

  1. <myTL:getMenu subject=”Finance”/>
  2. <myTL:getMenu subject=”<myTL:getHeading report=1/>”/>
  3. <myTL:getMenu subject='<myTL:getHeading report=”1″/>’/>
  4. <% String subject=”HR”;%> <myTL:getMenu subject=”<%=subject%>”/>
  5. <myTL:getHeading report=”2″/>

18 . You are working with a tag library which is packaged in a jar file named htmlutil.jar.This jar file also contains a META-INF/htmlutil.tld file which has a uri element as follows:

<uri>http://www.xyzcorp.com/htmlLib</uri>

What can you do to access this library from your JSP pages?

Choose the one below:

  1. You must define the <taglib> element in the web.xml to specify the mapping for <taglib-uri> to the location of this jar file
  2. There is no need for the <taglib> element in the web.xml, however, you need the taglib directive in the JSP pages
  3. You can directly access the tags of this library from the JSP pages without any taglib directive
  4. You do not need the taglib directive, but you do need to specify the <taglib> element in the web.xml
  5. None of these

19 . Which of the following are valid iteration mechanisms in jsp?

1.
  <% int i = 0;
  while(i<5)
  {
     "Hello World"
      i++;
  } %>

2.
  <jsp:for loop='5'>
     "Hello World"
  </jsp:for>

3.
  <% int i = 0;
   for(;i<5; i++)
   { %>
     "Hello World";
  <%  i++;
    }
  %>

4.
  <table>
  <% Iterator it = aSet.iterator();
     int i = 0;
     while(it.hasNext())
     {
        out.println("<tr><td>"+(++i)+"</td>");
        out.println("<td>"+it.next()+</td></tr>");
     }
  %>
  </table>

5.
  <jsp:scriptlet>
     for(int i=0; i<5; i++)
     {
  </jsp:scriptlet>
  <jsp:text>"Hello World!"</jsp:text>
  <jsp:scriptlet>
     }
  </jsp:scriptlet>

Choose the one below:

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

20 . Your web application wants to make use of a role named ‘manager’, which is defined in the servlet container. Which of the following XML fragments must occur in the deployment descriptor of your web application?

1. <role name='manager' />

2. <role>
    <role-name>manager</role-name>
   </role>

3. <role>manager</role>

4. <security-role>
    <role-name>manager</role-name>
   </security-role>

Choose the one below:

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

21 . Consider the class shown in exhibit. Which of the following statements are correct?

public class MyHSAListener implements HttpSessionAttributeListener
{
  public void attributeAdded(HttpSessionBindingEvent e){ }
  public void attributeRemoved(HttpSessionBindingEvent e){ }
}

Choose the one below:

  1. public void attributeReplaced(…){ } must be added
  2. public void attributeChanged(…){ } must be added
  3. The parameter class should be HttpSessionEvent
  4. The parameter class should be HttpSessionAttributeEvent
  5. It will compile as it is

22 . Identify the implicit objects available to EL expressions?

  1. request
  2. sessionScope
  3. paramValues
  4. params
  5. cookie
  6. initParam

23 . Which of the following statements are correct regarding tag libraries?

  1. The tag library descriptor for a tag library must be kept in META-INF/taglib.tld, if the tag library is packaged in a jar file
  2. The tag library descriptor for a tag library may be kept in WEB-INF/taglib.tld, if the tag library is packaged in a jar file
  3. A JSP 2.0 compliant container is guaranteed to generate implicating mapping for JSTL tag libraries
  4. A JSP 2.0 compliant container will automatically generate an implicit tag library for a set of tag files
  5. The tag library descriptor for a tag library not packaged as a jar file may be kept anywhere in /tld directory of the web application’s document root

24 . Consider the following usage of a custom tag in a JSP page:

<jsp:useBean id="student" scope = "session" class="com.xyz.Student" />
<mytaglib:studentTag student='student' />

Which of the following statements are correct?

Choose the one below:

  1. Application objects such as com.xyz.Student, cannot be passed as attributes to custom tags
  2. The Student object will be passed to the studentTag tag handler
  3. The Student object will NOT be passed because no variable named student is defined
  4. A Student object will not be created if it is not available it the session
  5. None of these

25 . Assuming that the Servlet Container has just called the destroy() method of a servlet instance, which of the following statements are correct?

  1. Any resources that this servlet might hold have been released
  2. The servlet container time out has exceeded for this servlet instance
  3. The init() method has been called on this instance
  4. None of the requests can EVER be serviced by this instance
  5. All threads created by this servlet are done

26 . For a tag to accept any valid jsp code as its body, what should be the value of for this tag’s taglib descriptor?

  1. JSP
  2. jsp
  3. any
  4. text
  5. The <body-content> subelement itself may be absent

27 . Which of the given options can be used in a servlet code that needs to access a binary file kept in WEB-INF/data.zip while servicing a request?
Assume that config refers to the ServletConfig object of the servlet and context refers to the ServletContext object of the servlet?

  1. InputStream is = config.getInputStream(“/WEB-INF/data.zip”);
  2. InputStream is = context.getInputStream(“data.zip”);
  3. InputStream is = context.getResourceAsStream(“/WEB-INF/data.zip”);
  4. InputStream is = context.getResourceAsStream(“WEB-INF/data.zip”);
  5. InputStream is = config.getResourceAsStream(“WEB-INF/data.zip”);

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

29 . Identify the implicit objects accessible to a jsp page that can store objects accessible across multiple requests?

  1. page
  2. request
  3. session
  4. application
  5. pageContext

30 . You are developing a jsp page named stockindices.jsp.This jsp page needs to use a HTML page named nasdaq.html in the middle of the page,which is updated every ten minutes by some other process.Which of the following lines,when added to stockindices.jsp,ensures that stockindices.jsp uses the latest nasdaq.html?

  1. <%@include page=’nasdaq.html’ %>
  2. <%@include file=’nasdaq.html’ %>
  3. <jsp:include page=’nasdaq.html’ />
  4. <jsp:include file=’nasdaq.html’ />
  5. <jsp:forward page=’nasdaq.html’ />

Answers

1 : 2 is correct.

2 : 2 & 4 is correct.

3 : 3 is correct.

4 : 3 is correct.

5 : 1,3 & 5 is correct.

6 : 3 & 4 is correct.

7 : 1 & 2 is correct.

8 : 2 is correct.

9 : 2 is correct.

10 : 2 is correct.

11 : 4 is correct.

12 : 1 is correct.

13 : 3 is correct.

14 : 4 is correct.

15 : 5 is correct.

16 : 3 is correct.

17 : 1,4 & 5 is correct.

18 : 2 is correct.

19 : 3,4 & 5 is correct.

20 : 4 is correct.

21 : 1 is correct.

22 : 2,3,5 & 6 is correct.

23 : 4 is correct.

24 : 5 is correct.

25 : 3 & 4 is correct.

26 : 5 is correct.

27 : 3 is correct.

28 : 4 is correct.

29 : 3 & 4 is correct.

30 : 3 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 – 1
Next Post: OCEJWCD 6 Mock Exam – 3 »

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