JavaBeat Certification Kit
Certification Kits
SCJP 1.5 Exam Questions
SCJP 1.6 Exam Questions
SCWCD 1.4 Exam Questions
SCWCD 5.0 Exam Questions
new SCBCD 5.0 Exam Questions
Certification Links
SCJP 1.4
SCJP 1.5
SCJP 1.6
SCWCD 1.4
SCWCD 5.0
SCBCD 5.0
JavaBeat
Home
Articles
Tips
Code
QnA
Forums
300 Mock Questions on SCWCD 5.0 - JUST Rs.250 or 10 USD
Send us mail to sales@javabeat.net
Do you have paypal account? Click Here to pay now and get the questions.
contact our sales support team at 91-9886656774

1) A software company wants to develop a component that does many of the pre-processing stuffs like whether the requests are coming from authentic sources, filtering unwanted data in the request object. What type of pattern will be the best match for developing such a component?

  1. Front Controller
  2. Business Controller
  3. Business Delegate
  4. Intercepting Filter

2) A class wants to keep track of its number of objects being added to HttpSession objects. Which will be the ideal way to achieve this?

  1. Define a listener class implementing HttpSessionListener and whenever an object is added to Http Session object, keep track of the number of instances.
  2. Define a listener class implementing HttpSessionBindingListener and in the valueBound() method, keep track of the number of instances being added in a static variable.
  3. It is highly impossible to keep track the number of objects being added to a Http Session in a Web Application.
  4. The Servlet API provides direct support for keeping track the object instances.

3) What will be the output of the following JSP code snippet at run-time when it is accessed the third time?


<% int test = 0; %>
<% ++test; %>
The value of test is 
<%= test %>
  1. The value of the 'test' variable will be 2.
  2. The value of the 'test' variable will be 0.
  3. The value of the 'test' variable will be 1.
  4. The variable 'test' must be declared at global scope, else a run-time error will occur.

4) What method can be used to retrieve all the parameter names being sent as part of the request by the client?

  1. Use the method 'HttpServletRequest.getParameterNames()' which will return an enumeration of parameter names.
  2. Use the method 'HttpServletResponse.getParameterNames()' which will return an enumeration of parameter names.
  3. Use the method 'HttpServletRequest.getAllParameters()' which will return an enumeration of parameter names.
  4. There is no direct support in the Servlet API to retrieve the name of all the parameters sent by the client.

5) Given the deployment descriptor for a Web Application is


<web-app version="2.4">
	
    <servlet>
        <servlet-name>InitParamsServlet</servlet-name>
        <servlet-class>scwcd14.chap02.InitParamsServlet</servlet-class>
    </servlet>


    <servlet-mapping>
        <servlet-name>InitParamsServlet</servlet-name>
        <url-pattern>/InitParamsServlet</url-pattern>
        
        <init-param>
            <param-name>name</param-name>
            <param-value>javabeat</param-value>
        </init-param>

    </servlet-mapping>

</web-app>

What will be the output of the following Servlet?


package scwcd14.chap02;

import java.io.*;
import java.net.*;

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

public class InitParamsServlet extends HttpServlet {
    
    public void init(){
        
        ServletConfig config = getServletConfig();
        System.out.println(config.getInitParameter("name"));
        System.out.println(config.getInitParameter("no-name"));
    }  
    ...
}
  1. The Servlet will output 'javabeat null' in the Server Console.
  2. The Servlet will fail to load as the init param property 'no-name' is not mentioned in the deployment descriptor.
  3. A NullPointerException will be raised as calling getServletConfig() in the init() method will return a null reference.

6) Following is an excerpt taken from a Deployment Descriptor of some Web Application.


<web-app version="2.4">
    
    <context-param>
        <param-name>app-name</param-name>
        <param-value>MockQuestions</param-value>
    </context-param>

   <servlet>
        <servlet-name>ContextInfoServlet</servlet-name>
        <servlet-class>scwcd14.chap03.ContextInfoServlet</servlet-class>
        
        <init-param>
            <param-name>app-name</param-name>
            <param-value>ContextInfoServlet</param-value>
        </init-param>
    </servlet>

</web-app>

7)Which of the following code will output the message 'MockQuestions ContextInfoServlet' to the client browser (assuming that 'out' is a valid instance of type 'PrintWriter' class)?


out.println(config.getServletContext().getParameter("app-name"));
out.println(config.getInitParameter("app-name"));


out.println(config.getInitParameter("app-name"));
out.println(config.getServletContext().getInitParameter("app-name"));


out.println(config.getServletContext().getInitParameter("app-name"));
out.println(config.getInitParameter("app-name"));


out.println(config.getServletContext().getInitParameter("app-name"));
out.println(config.getParameter("app-name"));

7) Which of the following tag library definition is valid?



  1. <tag> <name>hello</name> <tag-class>test.HelloTag</tag-class > </tag> <tag> <name>anotherHello</name> <tag-class>test.AnotherHelloTag</tag-class> </tag>
  2. <tag> <name>hello</name> <tag-class>test.HelloTag</tag-class > </tag> <tag> <name>hello</name> <tag-class> test.HelloTag</tag-class> </tag>
  3. <tag> <name>root</name> <tag-class>test.RootTag</tag-class > <sub-tag> <name>child</name> <tag-class>test.ChildTag</tag-class> </sub-tag> </tag>

8) What is the equivalent action code for the following piece of JSP code snippet?


EmployeeBean harry = (EmployeeBean)request.getAttribute("harry");
if (harry == null)
{
harry = new EmployeeBean();
request.setAttribute("harry", harry);
}
  1. <jsp:declareBean id = "harry" class = "EmployeeBean" scope = "request" />
  2. <jsp:createBean id = "harry" class = "EmployeeBean" />
  3. <jsp:useBean id = "harry" class = "EmployeeBean" scope = "request" />
  4. <jsp:useBean id = "harry" class = "EmployeeBean" />

9) Which of the following is a valid declaration of a Tag Library in a Deployment Descriptor?


  1. <taglib> <uri>http://www.javabeat.net/studyKit</uri> <location>/studyKit.tld</location> </taglib>
  2. <taglib> <uri>http://www.javabeat.net/studyKit<uri> <location>/studyKit.tld</location> </taglib>
  3. <taglib> <taglib-uri>http://www.javabeat.net/studyKit</taglib-uri> <taglib-location>/studyKit.tld</taglib-location> </taglib>
  4. <taglib> <uri>http://www.javabeat.net/studyKit</uri> <path>/studyKit.tld</path> </taglib>

10) Which of the following EL expression retrieves the value of the attribute by name 'attribute' found in HTTP's request object

  1. ${request.getAttribute()}
  2. ${request.attribute}
  3. ${pageContext.request.getAttribute()}
  4. ${pageContext.request.attribute}

Answers

1) d.

Since all of the operations corresponds to some pre-processing stuff, an Intercepting filter will be the ideal pattern to achieve this.

2) b.

Option b is correct as a custom attribute, if want to be notified when objects of the class are being added to Http Session, should implement the HttpSessionBindingListener interface.

3) c.

The variable 'test' is declared with local scope as it is declared within the doGet() method. So, the number of times, this page is invoked doesn't really matter and the value of the variable 'test' at any point of time will be '1'.

4) a.

Using HttpServletRequest and by calling the method getParamterNames(), all the parameter names can be retrieved.

5) a.

Option a is correct. It will print the value of the init parameters in the Server console.

6) c.

Option c is correct as to retrieve data declared in the <context-param> tag, we need a reference to Servlet Context object and then to call the getInitParameter() method. The data in the init-param tag declared for a Servlet can be obtained directly by calling the getInitParamter() defined on the Servlet Config object.

7) a.

Option b is incorrect as the tag name must be unique with the tag definition file. Option c is incorrect as there is no such tag called 'sub-tag'.

8) c.

An employee object by name 'harry' is taken from the request object which is of type 'EmployeeBean'. Option c is the right one which is defining this.

9) c.

Option c is correct as valid elements for 'taglib' are 'taglib-uri' and 'taglib-location'.

10) d.

A request object can be obtained by calling ${pageContext.request}. Since java methods calls cannot be used (and shouldn't be), option c is incorrect as it uses the java method call syntax (getMethod()).
contact us at sales@javabeat.net
300 Mock Questions on SCWCD 5.0 - JUST Rs.250 or 10 USD
Send us mail to sales@javabeat.net