Tuesday, January 16, 2007

SCWCD 1.4 Mock Questions - 4

SCWCD 1.4 Mock Exams and Priactice Questions

1. Regarding the processing of a BodyTag handler, in which of the following cases a BodyContent object will be "pushed" into the pageContext?

Select 1 correct option.
A.If the doStartTag() returns EVAL_BODY_INCLUDE
B.If the doStartTag() returns EVAL_BODY_BUFFERED
C.If the doStartTag() returns SKIP_BODY
D.If the doStartTag() DOES NOT return SKIP_BODY
E.A BodyContent object it is always created and pushed no matter what doStartTag() returns

ANS : B

2.Which of the following apply to Transfer Object design pattern?

Select 2 correct options.
A.It increases complexity by increasing the number of remote interfaces.
B. It increases network performance by introducing one coarse grained remote call for multiple finer grained network calls
C.It reduces network traffic by introducing one coarse grained remote call for multiple finer grained network calls
D.It increase server throughput by utilizing the CPU better
E.It increases design overhead due to versioning issues

ANS : B,C

3.Which of the following deployment descriptor snippets would you use to declare the use of a tag library?

1.

<tag-lib>

<uri>http://abc.net/ourlib.tld</uri>

<location>/WEB-INF/ourlib.tld</location>

</tag-lib>



2.

<taglib>

<uri>http://abc.net/ourlib.tld</uri>

<location>/WEB-INF/ourlib.tld</location>

</taglib>



3.

<taglib>

<taglib-uri>http://abc.net/ourlib.tld</taglib-uri>

<taglib-location>/WEB-INF/ourlib.tld</taglib-location>

</taglib>



4.

<taglib>

<tagliburi>http://abc.net/ourlib.tld</uri>

<tagliblocation>/WEB-INF/ourlib.tld</location>

</taglib>



5.

<taglibmap>

<uri>http://abc.net/ourlib.tld</uri>

<location>/WEB-INF/ourlib.tld</location>

</taglibmap>

Select 1 correct option.

A.1
B.2
C.3
D.4
E.5

ANS : C

4.Which of the following design patterns is used to separate the task of writing the GUI screens and business logic?

Select 1 correct option.
A.View Logic
B.Front Controller
C.Model View Controller
D.Business View
E.Business Delegate

ANS : B

5. For this jsp code to compile and run which of the given options should be true?
<jsp:useBean class="com.bookstore.Book" type="java.lang.Object" id="book" />

Select 1 correct option.
A.This statement is wrong as type attribute is invalid.
B.Book must have a public no args constructor
C.Book must have a public constructor but there is no requirement on arguments.
D.Book must have a public getInstance() method.
E.This statement will always throw an exception at runtime no matter what you do to Book class.

ANS : B

6.Your servlet may throw IOException while processing a request. You want
to define an error page in your deployment descriptor so that whenever
IOException is thrown, this page is serviced to the browser. Which of
the following XML fragments correctly specify the mapping:

1.

<error-page>

<exception>java.io.IOException</exception>

<location>/html/Test.html</location>

</error-page>



2.

<error-page>

<exception-class>java.io.IOException</exception-class>

<location>/html/Test.html</location>

</error-page>



3.

<error-page>

<exception-type>java.io.IOException</exception-type>

<page-location>/html/Test.html</page-location>

</error-page>



4.

<error-page>

<exception-type>java.io.IOException</exception-type>

<location>/Enthuse/html/Test.html</location>

</error-page>



5.

<exception>

<exception-type>java.io.IOException</exception-type>

<location>/Enthuse/html/Test.html</location>

</exception>

Select 1 correct option.

A.1
B.2
C.3
D.4
E.5

ANS : D

7.Select the tag that comes directly under the <web-app> tag of a
web.xml and that is used to specify a class whose object will be sent
notifications when changes occur to the SevletContext?

Select 1 correct option.
A.servlet-context-listener
B.listener
C.context-listener-class
D.listener-class
E.context-listener

ANS : B

8.Consider the following JSP code (See exhibit).
What will it print for the very first request to this page as well as the web application that contains this page?

<html><body>

<%

Integer count = (Integer) request.getSession(false).getAttribute("count");

if(count != null )

{

out.println(count);

}

else request.getSession(false).setAttribute("count", new Integer(1));

%>

Hello!

</body></html>

Select 1 correct option.
A.It will print Hello!
B.It will print Hello and will set the count attribute in the session.
C.It will throw a NullPointerException at request time.
D.It will not compile.

ANS : B

9. The following line of code exists in the doGet method of Servlet:
String sid = request.getParameter("jsessionid");
Which of the options will retrieve the HttpSession associated with
the request? (Assume that the session has already been created.)

Select 3 correct options.
A.HttpSession session = request.getSession();
B.HttpSession session = HttpSession.getSession(sid);
C.HttpSession session = request.getSession(sid);
D.HttpSession session = request.getSession(true);
E.HttpSession session = request.getSession(false);

ANS : A,D,E

10.Given that a tag testlib:myFirstSimpleTag extends SimpleTagSupport.
What should be done so that scriptlet code can be used in the body of this tag?

Select 1 correct option.
A.body-content should be set to JSP in the TLD for this tag.
B.scripting-enabled should be set to true in the TLD for this tag.
C.Create a classic tag adapter for this tag that has the body-content of JSP.
D.This cannot be done because it is a Simple tag.
E.None of these.

ANS : D

11.Which of the following is NOT a technique used for maintaining sessions?

Select 1 correct option.
A.HttpSession objects
B.URL rewriting
C.Cookies
D.HttpSessionActivationListener
E.Hidden form fields

ANS : D

12.Identify the method of TagSupport class that can be used by an inner tag handler to access an outer tag handler that is not enclosing it
immediately...

Select 1 correct option.
A.findAncestorWithClass
B.findAncestor
C.findAncestorClass
D.findParentWithClass
E.findParentClass

ANS : A

13.Consider the following JSP page:

<%@page isELIgnored='false'%>

<html>

<body>

<h1>

<% request.setAttribute("pageContext", "pagecontext"); %>

pageContext = ${pageContext}

</h1>

</body>

</html>

Assuming that both - scripting and EL are allowed in the page, what will it print for ${pageContext}?

Select 1 correct option.

A.It will cause a translation error
B.It will print the string "pagecontext"
C.It will print nothing
D.It will throw an exception at request time
E.None of these.

ANS : E

14.What subelement of <attribute> tag defines the name of the attribute that might be passed to the tag handler?

Select 1 correct option.
A.<attribute-name>
B.<name>
C.<attributename>
D.<param-name>
E.No subelement is needed. 'name' attribute is used in <attribute> tag to define the name.

ANS : B

15.Consider the contents of the following two jsp files:
In File: test.jsp



<html>

<body>

<% int i = 10; %>

<%@include file="test2.jsp"%>

Hello World : <%=i%>

</body>

</html>

In File : test2.jsp

<% i = 15; %>
What will be the output when test.jsp is requested?

Select 1 correct option.
A.Hello world : 15
B.Hello world : 10
C.It will throw an exception because i is undefined in test2.jsp
D.test.jsp will not compile because syntax of include directive is incorrect.
E.None of the above

ANS : A

16.Which of the given options are equivalent?

Select 2 correct options.
A. <% Hashtable ht = new Hashtable(); %>
B.<%= Hashtable ht = new Hashtable() %>
C.<jsp:scriptlet>Hashtable ht = new Hashtable();</jsp:scriptlet>
D.<jsp:code>Hashtable ht = new Hashtable();</jsp:code>
E.<jsp:scriptlet>Hashtable ht = new Hashtable()</jsp:scriptlet>

ANS : A,C

17.Which of the following lines of code, in the doPost() method of a
servlet, uses the URL rewriting approach to maintaining sessions?

Select 1 correct option.
A.request.useURLRewriting();
B.out.println(response.rewrite("<a href='/servlet/XServlet'>Click here</a>"));
C.out.println("<a href=' "+request.rewrite("/servlet/XServlet")+" '>Click here</a>"));
D.out.println("<a href=' "+response.encodeURL("/servlet/XServlet")+" '>Click here</a>"));
E.out.println("<a href=' "+request.encodeURL("/servlet/XServlet")+" '>Click here</a>"));

ANS : D

18.Which of the following classes/interfaces provide methods to write messages to a log file?

Select 2 correct options
A.GenericServlet
B.ServletRequest
C.HttpServletRequest
D.ServletContext
E.Only GenericServlet

ANS : A,D

19.What are the implications of using the HTTP GET method for a form submission?

Select 3 correct options.
A.You cannot pass binary data to the server.
B.You cannot send unlimited (or a lot of) data to the server
C.You cannot send unlimited (or a lot of) data to the server
D.You can only reply with the HEADER information in the response
E.The parameters will be appended to the URL as a query string.

ANS : A,B,E

20.Which method would you use to acquire the stream to write binary data in response to a request to a servlet?

Select 1 correct option.
A.getOutputStream() of ServletResponse interface.
B.getOutputStream() of HttpServletResponse interface.
C.getFileOutputStream() of HttpServletResponse interface.
D.getWriter() of HttpServletResponse interface.
E.getWriter() of ServletResponse interface.

ANS : A

21.Which of the following are valid JSP scriptlets?

Select 2 correct options.
A.<% String uid = LoginHelper.login(request) %>
B.<% String uid = LoginHelper.login(request); %>
C.<%! String uid = LoginHelper.login(request) %>
D.<%@ String uid = LoginHelper.login(request) %>
E.<% for(int i=0; i< 10; i++) { out.println(i); } %>

ANS : B,E

22.Which of the following implicit variables should be used by a jsp page
Select 1 correct option.

A.pageContext and config
B.application and config
C.config and pageContext
D.application for both
E.config for both

ANS : D

23.Consider the following tag declaration in a TLD file:

<tag>

<name>simpleInterest</name>

<tag-class>SimpleInterestTag</tag-class>

//1

</tag>

SimpleInterestTag calculates simple interest for any amount and requires two attributes 'amount' and 'rate'.
Which of the following sub elements would you need to add inside

Select 1 correct option.
A.Two separate <attribute> elements.
B.One <amount> element and one <rate> element
C.One <attribute> element with sub-elements
D.One <attribute-list> element with sub-elements

ANS : A

24.Which of the statements regarding the following code are correct?

public void doPost(HttpServletRequest req, HttpServletResponse res)

throws IOException, ServletException

{

res.getWriter().print("Hello ");

RequestDispatcher rd = getServletContext().getRequestDispatcher("/test.jsp");

rd.include(req, res);

res.getWriter().print("World");

}

Select 1 correct option.
A.Only "Hello" will be a part of the output.
B.Only "World" will be a part of the output
C."Hello" and "World" both will be a part of the output.
D.Neither will be a part of the output

ANS : C

25.Given that a servlet has been mapped to /report/* .
Identity the various components of the URI: /myapp/report/daily/tradesummary as seen by the servlet
Drag and Drop the selected item to the following .

Context Path
Servlet Path
Path Info

select item :
1./myapp
2./myapp/report
3./myapp/report/daily
4./report
5./report/daily
6./report/daily/tradesummary
7./daily
8./daily/tradesummary

ANS :

Context Path -1
Servlet Path -4
Path Info -8

26.Which method is invoked when a ServletContext is initialized?

Select 1 correct option.
A.contextInitialized() on a ServletContextListener Object.by the servlet.
B.contextCreated() on a ServletContextListener Object.
C.contextStateChanged() on a ServletContextListener Object.
D.init() on a ServletContextListener Object
E.initialized() on a ServletContextListener Object.

ANS : A

27. Consider the following JSP page code:

<html>

<body>

<%! int MIN; %>

Value of MIN is: <% = MIN %>

</body>

</html>

What output will it generate for the browser?

Select 1 correct option.
A.Value of MIN is: Undefined.
B.Value of MIN is: 0
C.It will not compile
D.It'll print an arbittrary value for MIN.
E.None of the above

ANS : C

28.Consider the following code in hello.jsp:
<html>

<body>

<h1>Hello EL</h1>

${param.command}

</body>

</html>

Which of the following tags when added to web.xml ensures that the text ${param.command} is printed exactly as it is in the output?

Select 1 correct option.

A.<jsp-config>

<jsp-property-group>

<url-pattern>*.jsp</url-pattern>

<elignored>true</elignored>

</jsp-property-group>

</jsp-config>

B.<jsp-config>

<jsp-property-group>

<url-pattern>*.jsp</url-pattern>

<isELIgnored>true</isELIgnored>

</jsp-property-group>

</jsp-config>

C.<jsp-config>

<jsp-property-group>

<url-pattern>*.jsp</url-pattern>

<el-ignored>true</el-ignored>

</jsp-property-group>

</jsp-config>

D.<jsp-config>

<jsp-property-group>

<url-pattern>*.jsp</url-pattern>

<ignore-el>true</ignore-el>

</jsp-property-group>

</jsp-config>

ANS : C

For a tag in a tag library descriptor, an attribute is defined as follows:

<attribute>

<name>age</name>

<required>true</required>

</attribute>

Assume that the tag is being referred to as calc:insurance.
Which of the given options could be a valid use of the tag?

Select 2 correct options.
A.<calc:insurance age="25"></calc:insurance>
B.<calc:insurance age="<%=request.getParameter("age")%>"></calc:insurance>
C.<calc:insurance></calc:insurance>
D.<calc:insurance><age>25</age></calc:insurance>
E.<calc:insurance age="30"><age>25</age></calc:insurance>

ANS : A,E

30. Consider the code for doGet method of a servlet (See exhibit). Which of
the given LOCs can be inserted at //1 to log the message as well as the exception's stack trace?

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException

{

String userId = null;

try

{

userId = loginUser(req);

}

catch(Exception e)

{

// 1 : log "Unknown User" and the exception to the log file.

}

if(userId != null)

{

//do something.

}

}

Select 1 correct option.
A.req.log(e, "Unknown User");
B.this.log(e, "Unknown User");
C.this.getServletContext().log("Unknown User", e);
D.this.getServletContext().log(e, "Unknown User");
E.The stack trace of the exception cannot be logged using log(...) methods.

ANS : C














No comments: