805 OCPJP 6 Questions 788 SCJP 5 questions 650 OCPJWCD 5 questions 600 OCAJP 7 questions 610 OCPJP 7 questions 510 Upgrade to OCPJP 7 questions 900 Java J2EE Qns

Tutorials

SCWCD 1.5 Mock Exam Practice Questions

Question -1 
If a servlet generates an error that is not handled by the error_page mechanism, the container must ensure to send a response with status ______?.



options A)500 B)404 C)400 D)401 Correct answer is : A Explanations : If a servlet generates an error that is not handled by the error_page mechanism , the container must ensure to send a response with status 500.
Question -2 
Web applications can be packaged and signed into a Web Archive format (WAR) file using the standard Java archive tools.
When packaged into such a form, a META-INF directory will be present which contains information useful to Java archive tools.
Any requests from the client to access the resources in META-INF/ directory MUST be returned with a  ________ ?



options A)SC_NOT_FOUND B)SC_INTERNAL_SERVER_ERROR C)ESC_BAD_REQUEST D)None of the above Correct answer is : A Explanations : Any requests from the client to access the resources in META-INF/ directory MUST be returned with a SC_NOT_FOUND (404) response.
Question -3 
The classes in _________ directory must be available to the application class loader ?



options A)/WEB-INF/classes/ B)/WEB-INF/lib/classes/ C)/root/classes/ D)/root/lib/classes/ Correct answer is : A Explanations : The /WEB-INF/classes/ directory for servlet and utility classes. The classes in this directory must be available to the application class loader.
Questions no -4 
A JSP file that uses a tag library must declare the tag library first. 
The tag library is defined using the taglib directive - taglib uri="..." prefix="..." 
Which of the following specifies the correct purpose of prefix attribute.





options A)The prefix defines the name of the tag that may be used for a tag library. B)The prefix attribute defines the location of the tag library descriptor file. C)The prefix attribute should refer to the short name attribute of the tag library file that is defined by the uri attribute of taglib directive D)The prefix attribute is used in front of a tagname of a tag defined within the tag library. Correct answer is : D Explanations : If the taglib directive directive defines a prefix of "test", and a tag is called "mtag", then the tag is used as "test:mtag".
Questions no -5 
Given a tag handler defined with JSP which implements TagSupport and ONLY overrides doAfterBody with the following lines:

public int doAfterBody() throws JspException {
  try { pageContext.getOut().print("Hi");}catch(IOException e) {}
  return SKIP_BODY;
}

What will be the result of a jsp with the following part?
<prefix:sufix>
<i>Hello</i> 
</prefix:sufix>



options A)The jsp page will print: Hello B)The jsp page will print: Hello Hi C)The jsp page will print: Hi Hello D)The jsp won't print anything Correct answer is : D Explanations : TagSupport.doStartTag by default returns SKIP_BODY and as it is not overridden the body is ignored.
Questions no -6 
What is the default value of session Attribute in JSP ?


options A)<%@ page session="true" %> B)<%@ page session="false" %> C)<%@ page session="yes" %> D)<%@ page session="no" %> Correct answer is : A Explanations : <%@ page session="true" %> is the default value.
Questions no -7 
A JSP page does not contain  page attribute and trying to acccess exception implicit valiable.


options A)exception implicit avaliable not available in the JSP page. B)exception implicit avaliable is available in the JSP page. C)No relation between isErrorPage attribute and exception implicit variable. D)None of the above Correct answer is : A Explanations : exception implicit valiable not available in all JSP pages. Need to add page attribute to the JSP to avaliable exception implicit in the JSP page.
Questions no -8 

If the servlet code

public class testServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
request.setAttribute("attribute1", "attribute1");
HttpSession session = request.getSession();
session.setAttribute("attribute2", "attribute2");
ServletContext application = getServletContext();
application.setAttribute("attribute3","attribute3");
RequestDispatcher dispatcher =
request.getRequestDispatcher("/test.jsp");
dispatcher.forward(request, response);
}
}

and in the test.jsp 

attribute1: ${attribute1}
attribute2: ${attribute2}
attribute3: ${attribute3}

What is the value of attribute1, attribute2, attribute3 ?


options A)attribute1: attribute1 attribute2: attribute2 attribute3: attribute3 B)attribute1: attribute1 attribute2: null attribute3: null C)attribute1: null attribute2: null attribute3: attribute3 D)attribute1: attribute1 attribute2: null attribute3: attribute3 Correct answer is : A Explanations : ${attribute1} is same as pageContext.findAttribute("attribute1"). pageContext.findAttribute() find in request then session then application scope.
Questions no -9 

If in test.jsp

\${3+2-1} : ${3+2-1}

What is the output?


options A)\${3+2-1} : 4 B)\$4 : 4 C)4 : 4 D)\4 : 4 Correct answer is : A Explanations : adding \ before EL , does not execute the EL. \${3+2-1} : ${3+2-1} value is \${3+2-1} : 4
Questions no -10 
What is the sequence of method execution in Filter?


options A)init,doFilter,destroy B)doFilter,init,destroy C)destroy,doFilter,init D)destroy,doFilter Correct answer is : A Explanations : The init method is called by the container when the filter is instantiated. If you wish to pass initialization parameters to the filter, you retrieve them from the FilterConfig object passed to init. Then doFilter and last is destroy.
Questions no -11
Which of the following statement is true about servlet filter ?


options A)A filter is a reusable piece of code that can transform the content of HTTP requests, responses, and header information. B)Filters do not generally create a response or respond to a request as servlets do. C)Filters can act on dynamic or static content. D)All of the above Correct answer is : D Explanations : All statements are true.
Questions no -12 
Which of the following is not implicit object in JSP ?


options A)request B)response C)page D)system Correct answer is : D Explanations : JSP implicit objects are: (a) request, (b) response, (c) out, (d) session, (e) config, (f) application, (g) page, (h) pageContext, and (i) exception
Questions no -13 
What is the scope of response object?


options A)request B)response C)page D)session Correct answer is : C Explanations : scope of response object is page.
Questions no -14 
Which of the following elements can use the element jsp:param ?


options A)<jsp:include ...> B)<jsp:forward ...> C)<jsp:params > D)All of the above Correct answer is : D Explanations : All of the above elememts can use jsp:param inside it.
Questions no -15
Which of the following statements are correct about the following jsp lines:

<jps:useBean id="lname" class="java.lang.String" />

<%= lname%>


options A)It won't compile B)It is a valid jsp line and it will print the variable called lname. C)It will compile but it will always produce null as the output. D)None of the above Correct answer is : B Explanations : It will work properly .To have valid functionality you have to set an attribute of String type in the proper scope before it is accessed by <jsp:useBean ...> .
Questions no -16 
A  developer is designing a multi-tier web application and discovers " need to log each incoming client request ".
Which patterns, taken independently, provide a solution for this problem?

options A)Transfer Object B)Service Locator C)Front Controller D)Model-View-Controller Correct answer is : C Explanations : Front Controller is the best choice for this requirement because every request should go through the front controller. Front Controller provide "centralized controller for managing the handling of requests".
Questions no -17 
Which of the following design pattern "Reduces coupling between presentation tier and business services" ?

options A)Business Delegate B)Service Locator C)Front Controller D)Transfer Object Assembler Correct answer is : A Explanations : Business Delegate "Reduces coupling between presentation tier and business services".
Questions no -18 
After translation of a JSP source page into its implementation class, The jsp implementation class is ________ ?


options A)final B)static C)abstract D)private Correct answer is : A Explanations : After translation JSP page looks like : public final class test_jsp extends org.apache.jasper.runtime.HttpJspBase implements org.apache.jasper.runtime.JspSourceDependent { ... }
Questions no -19

What is the output of the below test.jsp ?

//test.jsp


<%!
 public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

	out.println("Hello");

   
}

%>

options A)Hello B)Compile Error - _jspService(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) is already defined in org.apache.jsp.test_jsp C)Runtime exception D)None of the above Correct answer is : D Explanations : After translation JSP page _jspService automatically created by JSP compiler. In the JSP page if you define method name _jspService(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) then compiler will complain _jspService(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) is already defined in org.apache.jsp.test_jsp.
Questions no -20

What get printed when the following JSTL code fragment is executed?

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<c:set var="item" value="2"/> 
<c:forEach var="item" begin="0" end="0" step="2">
<c:out value="${item}" default="abc"/>
</c:forEach>


options A)0 B)2 C)abc D)4 Correct answer is : A Explanations : forEach tag gets executed once, and prints zero.
Questions no -21 
What get printed when the following JSTL code fragment is executed?

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>  
<c:forEach var="item" begin="0" end="12" step="3"> 
${item} 
</c:forEach> 


options A)0,3,6,9,12 B)3,6,9,12 C)0,6,9,12 D)0,3,6,9 Correct answer is : A Explanations : start from 0 to end 12 and step is 3 so 0,3,6,9,12 printed.
Questions no -22 
Implementations of the ________ interface are notified of changes to the list of active sessions in a web application.


options A)HttpSessionListener B)HttpSessionAttributeListener C)HttpRequestListener D)HttpContextListener Correct answer is : A Explanations :Implementations of the HttpSessionListener interface are notified of changes to the list of active sessions in a web application.
Questions no -23 
All ____________ are notified of context initialization before any filter or servlet in the web application is initialized.


options A)ServletContextListeners B)HttpSessionListener C)ServletRequestListener D)All of the above Correct answer is : A Explanations : All ServletContextListeners are notified of context initialization before any filter or servlet in the web application is initialized. All servlets and filters have been destroyed before any ServletContextListeners are notified of context destruction.
Questions no -24 
Which of the following  is the mandatory sub-elements of login-config element ?


options A)realm-name B)auth-method C)form-login-config D)login-config doesn't have mandatory sub-elements Correct answer is : D Explanations : login-config doesn't have mandatory sub-elements.
Questions no -25 
Which of the following statement true about HTTP Digest Authentication ?


options A)Authentication is performed by transmitting the password in an ENCRYPTED . B)Authentication is performed by transmitting the password in an NOT ENCRYPTED C)SSL connection D)All of the above Correct answer is : A Explanations : Authentication is performed by transmitting the password in an ENCRYPTED in HTTP Digest Authentication . But not SSL.
Questions no -26
Name the class that includes the getSession method that is used to get the HttpSession object?



options A)HttpServletRequest B)HttpServletResponse C)SessionContext D)SessionConfig Correct answer is : A Explanations : The class HttpServletRequest defines the getSession method.
Questions no -27 
To send text outptut in a response, Which of the following method of HttpServletResponse 
may be used to get the appropriate Writer/Stream object



options A)getStream B)getOutputStream C)getBinaryStream D)getWriter Correct answer is : D Explanations : The getOutputStream method is used to get an output stream to send binary data. The getWriter method is used to get a PrintWriter object that can be used to send text data.
Questions no -28 
Which of the following statements are correct about the status of the Http response. 
Select the one correct answer.



options A)A status of 200 to 299 signifies that the request was succesful. B)A status of 300 to 399 are informational messages. C)A status of 400 to 499 indicates an error in the server. D)A status of 500 to 599 indicates an error in the client Correct answer is : A Explanations : The following table specifies the specific the status code of Http response. Status Code Purpose 100-199 Informational 200-299 Request was succesful 300-399 Request file has moved. 400-499 Client error 500-599 Server error.
Questions no -29 
The sendRedirect method defined in the HttpServlet class is equivalent to invoking 
the setStatus method with the following parameter and a Location header in the URL.
Select the one correct answer.



options A)SC_OK B)SC_MOVED_TEMPORARILY C)SC_NOT_FOUND D)SC_INTERNAL_SERVER_ERROR Correct answer is : B Explanations : sendRedirect(String URL) is equivalent to sending SC_MOVED_TEMPORARILY (302) response code and a location header in the URL.
Questions no -30 
Which of the following statement is true about URL Rewriting ?


options A)When a client will not accept a cookie, URL rewriting may be used by the server as the basis for session tracking B)URL rewriting involves adding data, a session ID, to the URL path that is interpreted by the container to associate the request with a session C)The session ID must be encoded as a path parameter in the URL string. The name of the parameter must be 'jsessionid' D)All of the above Correct answer is : D Explanations : URL rewriting is the lowest common denominator of session tracking. When a client will not accept a cookie, URL rewriting may be used by the server as the basis for session tracking. URL rewriting involves adding data, a session ID, to the URL path that is interpreted by the container to associate the request with a session. The session ID must be encoded as a path parameter in the URL string. The name of the parameter must be 'jsessionid' (lowercase !). Here is an example of a URL containing encoded path information: http://www.javacertifications.net/index.html;jsessionid=1234
Questions no -31 
The session-timeout element defines the session timeout interval for all sessions created in this web application.

Which of the below statement is true about session-timeout?


options A)The specified timeout must be expressed in a whole number of MINUTES B)If the timeout is 0 or less , sessions is NEVER to time out C)If this element is not specified, the container must set its default timeout period D)All of the above Correct answer is : D Explanations : The session-timeout element defines the default session timeout interval for all sessions created in this web application. The specified timeout must be expressed in a whole number of MINUTES. If the timeout is 0 or less, the container ensures the default behaviour of sessions is NEVER to time out. If this element is not specified, the container must set its default timeout period.
Questions no -32 
Can a jsp-file element present insted of servlet-class within a servlet element?


options A)jsp-file element can be present insted of servlet-class. and jsp file can be declared. B)No can't use jsp-file insted of servlet-class. C)jsp can't use in web.xml insted of servlet. D)None of the above Correct answer is : A Explanations : The servlet is used to declare a servlet. It contains the declarative data of a servlet. The jsp-file element contains the full path to a JSP file within the web application beginning with a "/". If a jsp-file is specified and the load-on-startup element is present, then the JSP should be precompiled and loaded.
Questions no -33 
Any requests from the client to access the resources in WEB-INF/ directory MUST be returned with a  ________ ?


options A)SC_NOT_FOUND B)SC_INTERNAL_SERVER_ERROR C)ESC_BAD_REQUEST D)BAD_REQUEST Correct answer is : A Explanations : Any requests from the client to access the resources in WEB-INF/ directory MUST be returned with a SC_NOT_FOUND (404) response.
Questions no -34 
The exception-type element specifies an exception type and is used to handle exceptions generated from a servlet. 
Which element of the deployment descriptor includes the exception-type as a sub-element?


options A)error-page B)error-path C)exception-page D)exception-page-info Correct answer is : A Explanations : The element error-page includes the element web-app. This is the page execute when any exception occurs.

  Upgrade to OCPJP 7 Java SE 7 Programmer (1Z0-805) Guide

  • Language Enhancements
  • Design Patterns
  • Describe the JDBC API
  • Concurrency
  • Localization
  • Java File I/O (NIO.2)


  • Mock Questions

      scwcd 1.5 mock questions

  • Servlet Basic
  • The Structure and Deployment of Web Applications
  • The Web Container Model
  • Servlet event listeners
  • Session Management,session listeners
  • Servlet Filter
  • Web Application Security
  • j2ee patterns
  • JSP Directives
  • JSP page life cycle
  • JSP implicit objects
  • JSP include
  • Expression Language (EL)
  • JSTL
  • Building a Custom Tag Library
  • scjp 1.5 | scjp 1.6 | scwcd 1.5
    Java Certifications
    www.javacertifications.net