SCWCD-4 04/14/2008
 

Which of the following HTTP methods are not idempotent?
A POST
B GET
C HEAD
D PUT

Answer
A
HTTP 1.1 declares POST as non idempotent

If the web application is distributed across multiple JVMs, how many instances of the servlet will be created ?
A 1
B we cannot distribute a web-application in multiple JVMs.
C One instance per JVM
D None

Answer
C
There will be one instance per JVM in distributed web-apps. But there will be only one instance in a single JVM

What is the argument for init() method ? Select all that apply.
A ServletContext
B ServletConfig
C HttpServletConfig
D HttpServlet
E No arguments

Answer
B and E
The init() method is having two overloaded versions in GenericServlet class. The init() that takes a ServletConfig object and init without any parameter. The no-argument init method is simply calling the init with ServletConfig object.

public class MyServlet extends HttpServlet {
private int x = 0;
public MyServlet (int x) {
this.x = x;
}
public void doGet (HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
x++;
PrintWriter out = response.getWriter();
out.println(x);
}
}
What will be the output (assume all imports are done correctly), when invoking MyServlet ?


A
Compiler error

B
Runtime Exception

C
Prints 1 in browser window.

D
Prints the value of x in browser window , depending up on the value used to create the servlet.
Which method is used to retrieve a form value in a JSP or Servlet?
A request.getAttribute(String)
B response.getAttribute(String)
C request.getParameter(String)
D response.getParameter(String)

Answer
C
Option B and D are incorrect because , no such method exist. Option A is incorrect because we cannot use that method for receiving request parameters.

Which is the default HTTP form method?
A POST
B HEAD
C PUT
D GET

Answer
D
The default HTTP form method is GET

HTTP HEAD method is used for ?
A To get the header part of the URL
B To delete a resource from server
C To place a resource on the server
D To connect to the server

Answer
A
HEAD method is used to get only the header part of the requested URL. It will return only header, no body

If a single client makes two requests, how many threads will be created by the container ?
A 0
B 1
C 2
D 3

Answer
C
For each and every request , the container will create a separate thread.

All Servlets implement which interface ?
A HttpServlet
B Servlet
C ServletRequest
D GenericServlet

Answer
B
All Servlets must implement javax.servlet.Servlet interface either directly or indirectly

True or False ? A new servlet is created each time a client request a servlet ?
A True
B false

Answer
B
There will be only one servlet in a JVM (if your servlet is not SingleThreadModel). Each time a client makes the request, the container will create a new thread for handling that request

 
SCWCD-3 04/14/2008
 

What will be the output of the following code? Assume that all the variables are declared properly

String str= request.getDateHeader("Accept-Language");

out.println(str);
A Compiler error
B An IO Exception is thrown
C Null
D An IllegalArgumentException thrown

Answer

D
Answer D is the correct choice. If the header value cannot converted to date , then an IllegalArgumentException will be thrown. Since the header value is a String, it will throw the IllegalArgumentException

Which method is used to store file in the server ?
A GET
B PUT
C POST
D HEAD

Answer

B
A PUT method is used to store a file or data in the server. The request URI identifies the location in the server to store the file

Which character is used to separate the URI and query string ?
A ?
B &
C =
D ;

Answer

A
Choice A is correct. ? is used to separate the URI and query string. & is used to separate the name value pairs from each other


Which method is called when a context is initialized ?
A contextInitialize(ServletContextEvent)
B contextInitialized(HttpServletContextEvent)
C contextInitialized(ServletContextEvent)
D contextInitialized(SevletContext)

Answer

C
The contextInitialized(ServletContextEvent) method is called when a context is initialized

When a user clicks on a link in a page, which method will get invoked ?
A POST
B PUT
C GET
D HEAD

Answer

C
When the user types the request URL into the browser's location field or clicks on a hyperlink, the GET method is triggered. When the user submits the form with the method attribute as "GET" or without any method attribute, then also GET will invoked


Which interface is having method getSession() ?
A ServletSession.
B ServletRequest
C HttpServletRequest
D ServletResponse
E HttpServletResponse

Answer

C
The HttpServletRequest interface contains the method getSession().

Which exception will be thrown, when a servlet is unavailable temporarily ?
A ServletException
B UnavailableException
C IOException
D UnAccessibleException

Answer

B
The UnavailableException will be thrown, when a servlet is unavailable temporarily

What method will get executed on clicking the following code.?

<form method="GET" action="/TestServlet">

<input type="text" name="name">

<input type="submit" value="Submit">

</form>
A GET
B POST
C HEAD
D PUT


Answer

A

Which of the following listeners will be called when a context is destroyed?
A HttpServletContextListner
B HttpSessionListener
C ServletContextDestroyedListener
D ServletContextListener

Answer

D
The contextDestroyed(ServletContexEvent) method of ServletContextListener is called, when a context is destroyed

 
SCWCD-2 04/14/2008
 

Which of the following can be used to configure the JSP container to ignore EL expressions?
A <%@ page isELIgnored="true" %>
B <%@ page isELIgnored="false" %>
C <%@ import isELIgnored="false" %>
D None of the above.

Answer
D
Configuring the <el-ignored> tag inside the DD is the only way to ignore EL expressions. There was a isELIgnored attribute for page directive in the 2.0 draft version. But it is removed from the final version.

Which method is used to retrieve objects from session?
A getAttribute method of javax.servlet.ServletSession.
B getAtrribute method of javax.servlet.HttpSession
C getAttribute method of javax.servlet.http.Session
D getAttribute method of javax.servlet.http.HttpSession
E getAttribute method of javax.servlet.HttpSession

Answer
D
All other answers are invalid because no such classes present.

Which among the following will compile ?
A <% int x=10 %>
B <%= "hello how are you" %>
C <%= "hello" ;% >
D <%! int x=10 %>

Answer
B
Option B is the correct choice. A is in correct because there is no semi colon present. The same rule applies to option D also. Option C is in correct because of semi colon

Which of the following is the proper way to include java.util package in your jsp page?
A <%@page:import package="java.util">
B <%@ page import = "java.util.*" %>
C <%= import java.util.*; %>
D <%@ page import="java.util.*" %>

Answer
D
Answer A is incorrect because, there is no such thing called <%@page import package. Answer B is incorrect because , we cannot have space between page and = sign. Answer c is correct, because it is a JSP expression.

Consider the following code snippet of servlet code:
public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
String value = getValue ();
if (value == null)
response.sendError (HttpServletResponse.SC_NOT_FOUND, "Failed");
response.sendRedirect ("test.jsp");
}
If the getValue () method returns null , which of the following statements are true?
A The code will work without any errors or exceptions
B An IllegalStateException will be thrown
C An IOException will be thrown
D A NullPointerException will be thrown

Answer
B
Since the response is already committed by calling the sendError() , we cannot redirect it once again

To send binary output to response, which method of HttpServletResponse is used to get the Writer/ Stream object ?
A getStream
B getWriter
C getBinaryOutputStream
D getOutputStream
E getBinaryStream

Answer

D
The getOutputStream is used for sending binary data. The getWriter is used for sending character data only

<%@ page language ="java" session="false" isErrorPage="false" %> which of the following JSP implicit object will not be available to the JSP page ? Select two
A session
B request
C application
D exception

Answer
A and D
Since we are disabling the session by using session="false", session will not be available. And since this page is not an error page , so exception also will not be available.

What will be the output of the following JSP code?
<html>
<body>
<%! int a = 20; %> <% int a = 10; %> <%! int b = 30; %> Now b = <%= b * a %>
</body>
</html>

A Now b = 300
B Now b = 600
C The code will not compile
D Now b = 30
E Now b = 0

Answer
A
In the first declaration <%! int a = 20; %>, the variable "a" will be declared as an instance variable. In the second declaration <% int a = 10; %>, the variable "a" will be declared as a local variable inside the service method. And at the time of multiplication it will use the local variable.

What is the default scope for <jsp:useBean>
A application
B session
C page
D request

Answer
C
The default scope attribute for useBean is page

In a JSP custom tag , which method would you use to access JSP implicit variable that references application scope ?
A PageContext.getOut()
B jspFactory.getPageContext()
C TagSupport.getValue(String)
D pageContext.getServletContext()

Answer
D

 
SCWCD-1 04/14/2008
 

Which of the following files is the correct name and location of deployment descriptor of web application. Assume that the web application is rooted at \doc-root. Select the one correct answer ?
A \doc-root\dd.xml
B doc-root\web.xml
C \doc-root\WEB-INF\web.xml
D \doc-root\WEB_INF\web.xml
E \doc-root\WEB-INF\classes\web.xml

Answer
C
The deployment descriptor must be called web.xml and be placed in the directory named WEB-INF.

Which element of the deployment descriptor is used to specify the class of the Servlet. ?
A <servlet-class>
B <servlet-name>
C <servlet_name>
D <servlet_class>
E <servlet>

Answer
A
The element servlet-class specifies the class of servlet.

Which of the following statements is true regarding MyServlet?
import javax.servlet.*;
;import javax.servlet.http.*;
import java.io.*;
public class MyServlet extends HttpServlet implements SingleThreadModel{
String myName;
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
response.setContentType("text/plain");
PrintWriter out = res.getWriter();
myName = req.getParameter("name");
sayHello(out);
out.close();
}
public void sayHello(PrintWriter out) {
out.println("Hello " + myName);
}
}
A MyServlet is thread safe
B MyServlet is not thread safe because myName is an instance variable
C MyServlet is not thread safe because MyServlet implements SingleThreadModel.
D None of the above

Answer
A
Choice A is correct. A application is thread safe if it always behaves predictably regardless of the number of concurrent threads running in its process space. The simplest way to ensure that a servlet is thread safe is to implement the SingleThreadModel interface. By implementing this interface, the server guarantees that no more than one thread can execute the service(), doGet(), or doPost() method at a time for a particular servlet instance. This makes the servlet thread safe. Thus even if class MyServlet has instance variables, it is thread safe. Thus A is the correct choice and the other choices are incorrect.

Which of the following combinations regarding Design Patterns are correct?
A Business Delegate - Reduces the coupling between presentation-tier clients and business services.
B Data Access Object - Allows for Multiple Views using the same model
C MVC - Enables easier migration to different persistence storage implementations.
D Value Object - Reduces Network Traffic

Answer
A and D
Choices A and D are correct. In a normal scenario, presentation-tier components (e.g. a JSP) interact directly with business services. As a result, the presentation-tier components are vulnerable to changes in the implementation of the business services: when the implementation of the business services change, the code in the presentation tier must change. The goal of the Business Delegate object design pattern is to minimize the coupling between presentation-tier clients and the business service API, thus hiding the underlying implementation details of the service. Thus choice A is correct. Choice B is incorrect as it's the MVC design pattern rather than the DAO (Data Access Object), which provides Multiple Views using the same model. Choice C is incorrect as it's the DAO (Data Access Object) pattern, which enables easier migration to different persistence storage implementations. The Value Object is used to encapsulate the business data. A single method call is used to send and retrieve the Value Object. When the client requests business data from an enterprise bean, the enterprise bean can construct the Value Object, populate it with its attribute values, and pass it by value to the client. Thus choice D is also correct.

Which of these is true about deployment descriptors. Select one correct answer.
A The order of elements in deployment descriptor is important. The elements must follow a specific order.
B The elements of deployment descriptor are not case insensitive
C The servlet-mapping element, if defined, must be included within the servlet element.
D The web-app element must include the servlet element

Answer
A
The servlet specifications specifies a specific order of deployment descriptor. b is incorrect because elements are case-sensitive. The servlet-mapping element should be included within the element. So c is incorrect. All the elements within the web-app element are optional. So d is incorrect.

Which element of the deployment descriptor includes the exception-type as a sub-element ?
A <exception>
B <error-page>
C <error>
D <exception_type>
E <error_page>

Answer
B
The element error-page includes the element web-app.

Which of these is a correct fragment within the web-app element of deployment descriptor. Select the two correct answer.
A 404 /error.jsp
B mypackage.MyException 404 /error.jsp
C mypackage.MyException 404
D mypackage.MyException /error.jsp

Answer
A and D
error-page element must include either exception-type or error-code element but not both. It must also include the location element.

Which element of the deployment descriptor of a web application includes the welcome-file-list element as a sub element.
A <welcome>
B <welcome-files>
C <list>
D <web-app>
E <context>

Answer
D
The contains the element.

Which of these is a correct example of specifying a listener element resented by MyClass class. Assume myServlet element is defined correctly. Select one correct answer.
A MyClass
B MyClass
C aListener MyClass
D <> myServlet MyClass

Answer
B
The element listener-class must be included within the listener element.

Which of the following is legal JSP syntax to print the value of i. Select the one correct answer
A <%int i = 1;%><%= i; %>
B <%int i = 1;i; %>
C <%int i = 1%><%= i %>
D <%int i = 1;%><%= i %>
E <%int i = 1%><%= i; %>

Answer
D
When using scriptlets (that is code included within ), the included code must have legal Java syntax. So the first statement must end with a semi-colon. The second statement on the other hand is a JSP expression. So it must not end with a semi colon.

 
    SCWCD Sets


    Archives

    May 2008
    April 2008