Tuesday, January 16, 2007

SCWCD 1.4 Mock Questions - 1

SCWCD 1.4 Mock Exams and Priactice Questions

1.Which constant is used to notify the container to reevaluate the custom tag's body?
Please select one correct answer.
A. EVAL_BODY
B. EVAL_BODY_TAG
C. EVAL_BODY_AGAIN
D. EVAL_BODY_INCLUDE

ANS :C
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. Which of the following statements regarding the JSP action tag are TRUE?
Please select three correct answers.
A. Provides translation-time instructions to the JSP engine.
B. Can be used to declare a JavaBean instance in a JSP page
C. Can be used to generate HTML code to embed an applet on a web page
D. User-defined actions can be created
E. language is a standard JSP action.

ANS :B,C,D

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 A 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.Which of the following methods can be used to pass request to another servlet to handle by using the RequestDispatcher?
Please select two correct answers.
A. request(ServletRequest req, ServletResponse res)
B. include(ServletRequest req, ServletResponse res)
C. dispatch(ServletRequest req, ServletResponse res)
D. forward(ServletRequest req, ServletResponse res)
E. process(ServletRequest req, ServletResponse res)

ANS :B,D
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. Given the following code snippet, what would be the output you can expect to see on the web page?
Please select one correct answer.

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
}
}

A. Method //1 is necessary for this code to compile
B. Method //2 is necessary for this code to compile
C. Line //3 is necessary for this code to run
D. Method //4 is necessary for this code to compile
E. Method //5 is necessary for this code to compile

ANS :C,E
You need to override the
service() method when you extends GenericServlet.

You need to call super.init(config) if you override this method.



5. Which pattern is normally used to encapsulate database SQL statement?
Please select one correct answer.
A. Value Object
B. Data Value Object
C. Data Access Object
D. Business Object
E. Business Delegate

ANS :B
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.For special character used in request URI, which of the following statements are correct?

Please select two correct answers.
A. The ampersand (&) is used to separate name/value pairs.
B. The plus sign (+) is used to fill blank space
C. The dash sign (-) is used to separate the name and value.
D. The percent sign (%) is used to start a query string.

ANS : A,B

7.Which statements are TRUE regarding the HttpServlet method doPost(HttpServletRequest req, HttpServletResponse res)?
Please select two correct answers.
A.The method is called by the server (via the service method) to allow a servlet to handle a POST or PUT request
B.The method is called by the server (via the service method) to allow a servlet to handle a POST or GET request.
C.The method is called by the server (via the service method) to allow a servlet to handle a POST request
D.The method is called by the server (via the service method) to allow a servlet to handle a GET request
E.The method allows the client to send data of unlimited length to the Web server a single time.
F. Operations requested through this method will NEVER have side effects.

ANS :C,E

8.Which of the following design pattern is used to reduce the amount of network traffic when transferring data?
Please select one correct answer
A. Model View Controller
B. Data Access Object
C. Business Delegate
D. Value Object

ANS :D

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

ANS :Client-Cert
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.Which of the following method is used to retrieve the value associated to the init parameter defined in the init-param tag?
Please select one correct answer.
A. getParameter(String name)
B. getInitParameter(String name)
C. getParameters()
D. getInitParameterValue(String name)

ANS : B

11. Which of the following statements are TRUE for the code given below?
Please select three correct answers.
    int MAX_AGE;
Cookie cookie = new Cookie("user", user);
cookie.setMaxAge(MAX_AGE);
response.addCookie(cookie);

A. If MAX_AGE = 10 the cookie will expire after 10 seconds.
B. If MAX_AGE = 10 the cookie will expire after 600 seconds.
C. If MAX_AGE = 0 the cookie will be deleted.
D. If MAX_AGE = -1 the cookie is not stored persistently
E. If MAX_AGE = -1; the code will generate run-time error.

ANS : A,C,D

12. In which directory you will most likely find the file myBaseUtil.jar?
Please select two correct answers.
A. example/WEB-INF
B. example/lib
C. example/WEB-INF/lib
D. example/WEB-INF/classes
E. example/META-INF/lib

ANS : C

13.Which of the following requirements are needed for FORM based authentication in a web based application?
Please select four correct answers.
A. The session attribuite j_sessionid must be set.
B. The action or url must be j_security_check.
C. The name attribute for the username must be j_username
D. The form method must be POST.
E. The name attribute for the password must be j_password.
F. Client side cookie must be enabled.

ANS : B,C,D,E

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"?
Please select one correct answer.
A. <servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/hello/*</url-pattern>
</servlet-mapping>
B. <servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/hello/*.jsp</url-pattern>
</servlet-mapping>
C. <servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/hello/index.jsp</url-pattern>
</servlet-mapping>
D. <servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>hello/*</url-pattern>
</servlet-mapping>

ANS : C

15. Which of the following methods will enable you to get one or more values from a request object?
Please select two correct answers.
A. getParameter(String name)
B. getParameters(String name)
C. getAllParameters()
D. getParameterValues(String name)
E. getAllAttributes()

ANS : A,D

16. Is the following statement TRUE or FALSE?
Please select one correct answer.
The four methods for session management in the context of web-based application are: Cookie, HttpSession object, URL rewriting and Hidden value.
A.True
B.False

ANS : A

17. Which of the following packages are implicitly imported in the JSP page?
Please select three correct answers.
A. java.lang.*
B. java.util.*
C. javax.servlet.*
D. javax.servlet.jsp.*
E. javax.servlet.jsp.tagext.*

ANS : A,C,D

18.Which of the following is NOT an authentication method used by a web container?
Please select one correct answer.
A. BASIC
B. DIGEST
C. SSL
D. FORM

ANS : C

19. Which methods can be used for writing logging message to servlet log file?
Please select two correct answers.
A. log(String msg)
B. log(int code, String msg)
C. log(String msg, Throwable t)
D. log(int code, String msg, Throwable t)

ANS : A.C

20.Which tag is used in web.xml to mark a web application to be suitable for running between multiple systems.
Please select one correct answer.
A. multiple
B. distributable
C. resource-ref
D. transferrable
E. splitable

ANS : B

21. Which of the following are VALID servlet error attributes?
Please select three correct answers.
A. javax.servet.error.status_code
B. javax.servet.error.exception
C. javax.servet.error.uri
D. javax.servet.error.message
E. javax.servet.error.query

ANS : A,B.D

22. Which statement is TRUE about the following jsp code snippet?
Please select one correct answer.
<%
String theKey = "key";
String theValue = "value";
session.removeAttribute(theKey); //1
%>

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

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

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

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

ANS : C

23. Which of the following are VALID taglib configuration?
Please select three correct answers.
A.
<taglib>
...
<tag>
<name>myTag</name>
<tag-class>MyTag</tag-class>
</tag>
...
</taglib>
B.
<taglib>
...
<tag>
<name>myTag</name>
<tag-class>MyTag</tag-class>
<body-content>SERVLET</body-content>
</tag>
...
</taglib>
C.
<taglib>
...
<tag>
<name>myTag</name>
<tag-class>MyTag</tag-class>
<attribute>
<name>name</name>
</attribute>
</tag>
...
</taglib>
D.
taglib>
...
<tag>
<name>myTag</name>
<tei-class>MyTagInfo</tei-class>
<body-content>JSP</body-content>
</tag>
...
</taglib>
E.
<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>

ANS : A,C,E

24.Which of the following statement is FALSE regarding JSP page directive attributes default value?
Please select one correct answer..
A. The session attribute has default value as true
B. The buffer attribute has default value as 8kb
C. The autoflush attribute has default value as false
D. The isThreadSafe attribute has default value as true
E. The isErrorPage attribute has default value as false
F. The pageEncoding attribute has default value as ISO-8859-1

ANS : C

25.Which of the following deployment descriptor tags are used for context level parameter initialization?
Please select three correct answers.
A. param-name
B. context-name
C. context-param
D. param-value
E. context-value
F. context-attrib

ANS : A,C,D

26. Given the following code snippet, what would be the output you can expect to see on the web page?
Please select one correct answer.
// 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!");

A."I am calling others!"
B."I am called by others!"
C.Both "I am calling others!" and "I am called by others!"
D.An IllegalStateException is thrown
E.An IOException is thrown

ANS : C

27.Which statement is NOT true about the SingleThreadModel interface?
Please select one correct answer
A.By implementing this interface it ensures that servlets handle only one
B.If a servlet implements this interface, no two threads will execute concurrently in the servlet's service method
C.This interface has no methods
D.The servlet container will ensure there will be only one instance of the servlet at a time if the servlet implements this interface
E.Class variables are not protected by this interface, but instance variables are protected.
ANS : D

28.Which of the following method is called upon the initialization of a servlet context?
Please select one correct answer
A. contextInitializing(ServletContextEvent e)
B. contextInitial(ServletContext e)
C. contextInitialize(ServletContext e)
D. contextInitialize(ServletContextEvent e)
E. contextInitialized(ServletContextEvent e)

ANS : E

29. Which of the following statements are TRUE?
Please select three correct answers
A.XML equivalent for JSP expression <%= expression %> is <jsp:expression>expression</jsp:expression>
B.
XML equivalent for JSP scriptlet <% scriptlet %> is <jsp:scriptlet>scriptlet</jsp:scriptlet>
C.
XML equivalent for JSP declaration <%! declaration %> is <jsp:declaration>declaration</jsp:declaration>.
D. XML equivalent for JSP include directive <%@ include file="url" %> is <jsp:include file="url"/>, where url must be relative
E. XML equivalent for JSP page directive <%@ page buffer="16kb" %> is <jsp:page buffer="16kb"/>

ANS : A,B.C

30.
Please select CORRECT JSP useBean declaration methods
Please select three correct answers
A.<jsp:useBean id="user" beanName="TestUser" type="com.test.model.User" />
B.<jsp:useBean id="user" beanName="TestUser" class="com.test.model.User" />
C. <jsp:useBean beanName="TestUser" class="com.test.model.User" />
D. <jsp:useBean beanName="TestUser" class="com.test.model.User" />
E. <jsp:useBean id="user" type="com.test.model.User" />

ANS : A,D,E

31. Which statement is TRUE regarding the following code?
Please select one correct answer.
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();
}
A.Variable bufferOne at //1 is NOT thread-safe.
B.Variable bufferTwo at //2 is NOT thread-safe
C.Both A and B
D.Variable req at //3 is NOT thread-safe
E.Variable session at //4 is NOT thread-safe
F.Both D and E

ANS : B

32.Select sample web application file listing with appropriate directory structure
Please select two correct answers.
A.
index.html
/login.jsp
/images/logo.gif
/WEB-INF/web.xml
/WEB-INF/lib/basic.jar
/WEB-INF/classes/Test.class
B.
/index.html
/login.jsp
/images/logo.gif
/WEB-INF/web.xml
/WEB-INF/jar/basic.jar
/WEB-INF/classes/Test.class
C.
/index.html
/login.jsp
/images/logo.gif
/WEB-INF/web.xml
/WEB-INF/classes/basic.jar
/WEB-INF/classes/Test.class
D.
/index.html
/login.jsp
/images/logo.gif
/META-INF/web.xml
/WEB-INF/jar/basic.jar
/WEB-INF/classes/Test.class
E.
/index.html
/login.jsp
/images/logo.gif
/META-INF/web.xml
/WEB-INF/lib/basic.jar
/WEB-INF/classes/Test.class
F.
index.html
/images/logo.gif
/WEB-INF/web.xml
/WEB-INF/jsp/login.jsp
/WEB-INF/lib/basic.jar
/WEB-INF/classes/Test.class

ANS : A,F

33. Which of the following data element will definitely be thread-safe?
Please select one correct answer
A. Local variables
B. Instance variables
C. Static variables
D. Class variables
E. Context attributes

ANS : A

34. Select the correct order that JSP methods are invoked by servlet container
Please select one correct answer.
A. jspInit(), jspService(), jspDestroy()
B. jspInit(), _jspService(), jspDestroy()
C. _jspInit(), jspService(), _jspDestroy()
D. _jspInit(), _jspService(), _jspDestroy()

ANS : B

35. Which of the following element is not included in a URL?
Please select one correct answer
A. Client ip
B.Protocol
C.Server Name
D.Query string
E.Port name

ANS : A

36. Which of the following listeners is notified when a session is initialized?
Please select one correct answer.
A. HttpSessionBindingListener
B. SessionBindingListener
C. HttpSessionListener
D. HttpSessionListener
E. HttpSessionChangedListener

ANS : C

37. Which of the following best describes the life cycle of a JSP?
Please select one correct answer.
A.
JSP page is translated into a servlet code
Servlet code is compiled
Servlet is loaded into memory
Servlet instance is created
B.
JSP page is translated into a servlet code
Servlet is loaded into memory
Servlet code is compiled
Servlet instance is created
C.
JSP is compiled
JSP is translated into a servlet code
Servlet is loaded into memory
Servlet instance is created
D.
JSP is loaded into memory
Servlet code is compiled
Servlet instance is created
Servlet is loaded into memory
E.
JSP page is translated into a servlet code
Servlet code is compiled
Servlet instance is created
Servlet is loaded into memory

ANS : A

38. Please identify the three methods declared in javax.servlet.Filter
Please select three correct answers.
A.service
B.init
C.destroy
D.filter
E.doFilter

ANS : B,C,E

39.Which of the following deployment descriptor segments are VALID for security-related configuration of a web application?
Please select two correct answers.
A.
<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>
B.
<security-role>
<description>My description.</description>
<role-name>Manager</role-name>
</security-role>
C.
<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>
D.
<security-constraint>
<auth-constraint>
<role-name>Broker</role-name>
</auth-constraint>
</security-constraint>
E.
<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>
ANS : B,E
40.Based on the following information, please construct the full path for the servlet.
Please select one correct answer
docbase = c:/temp/
context path = /test
alias name = MyMail
servlet-name = com.jiris.common.util.MailServlet
url-pattern = /mail/*

A.c:/temp/mail/com/jiris/common/util/MailServlet.class
B.c:/temp/test/com/jiris/common/util/MailServlet.class
C.c:/temp/mail/test/com/jiris/common/util/MailServlet.class
D.c:/temp/test/mail/com/jiris/common/util/MailServlet.class

ANS : B

41.The ServletContext object are accessible from which of the following
objects?
Please select three correct answers.
A.HttpServlet
B.GenericServlet
C.HttpSession
D.ServletConfig
E.ServletResponse

ANS : A,C,D

42.Which of the following method is used to store object into a request
object?
Please select one correct answer

A. addAttribute(String name, String obj)

B. putAttribute(String name, Object obj)

C. setAttribute(String name, String obj)

D. setAttribute(String name, Object obj)

E. addObject(String name, Object obj)

ANS : D

43. Which request method will be invoked for the following code?
Please select one correct answer.
<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>
A.GET
B.POST
C.HEAD
D.TRACE
E.PUT

ANS : A

44.Which of the following method might be invoked more than one time?
Please select one correct answer
A.doStartTag()
B.doInitBody()
C.doAfterBody()
D.doEndTag()

ANS : C

45.Which of the following methods are used to send an error page to the
client?
Please select two correct answers
A.log(String msg)
B.log(String msg, Throwable t)
C.sendError(int code)
D.sendError(int code, String msg)
E.sendError(int code, String msg, Throwable t)

ANS : C,D

46.Which of the following requests should be performed by using a POST method?
Please select two corretion.
A.Inserting a record into a database
B.Accessing a static page
C.Retrieving an image
D.Sending credit card number
E.Searching record in a database

ANS : A,D

47.Which of the following are CORRECT ways to define inactive period of 5
minutes of a session before the server invalidates it?
Please select two correct answers
A.<session-timeout>5</session-timeout>
B.<session-timeout>300</session-timeout>
C.session.setMaxInactiveInterval(5);
D.session.setMaxInactiveInterval(300);
E.session.invalidate(5);

ANS : A,D

48.Which are the two mandatory attributes for JSP taglib directive?
Please select two correct answers.
A.uri
B.id
C.name
D.prefix
E.value
F.location

ANS : A,D

49.A session can be invalidated by which of the following:
Please select three correct answers
A.After a default period of inactivity, say 30 minutes
B.Client side user closes the browser
C.After a specified period of inactivity, say 10 minutes
D.Client side user machine crashes
E.Explicitly invalidate a session through method calls

ANS : A,C,E

50.What is the method declaration for the method used in the HttpServlet
class that handles the HTTP GET request?
Please select one correct answer
A.doGet(ServletRequest req, ServletResponse res)
B.getPage(ServletRequest req, ServletResponse res)
C.doGet(HttpServletRequest req, HttpServletResponse res)
D.service(HttpServletRequest req, HttpServletResponse res)

ANS : C








No comments: