Tuesday, January 16, 2007

SCWCD 1.4 Mock Questions - 3

SCWCD 1.4 Mock Exams and Priactice Questions

1.Consider the following web.xml code snippet:

<servlet>

<servlet-name>BankServlet</servlet-name>

<servlet-class>com.abc.bankapp.BankServlet</servlet-class>

<security-role-ref>

<role-name>manager</role-name>

<role-link>supervisor</role-link>

</security-role-ref>

</servlet>

Which of the following statements are correct?

Select 1 correct option.
A.The servlet code should use "manager" as a parameter in request.isUserInRole() method.
B.The servlet code can use "manager" or "supervisor" as a parameter in request.isUserInRole() method.
C.The servlet code should use"supervisor" as a parameter in request.isUserInRole() method.
D.The role of "manager" must be defined in the servlet container.
E.None of these.

ANS : A

2.You are designing a complex webapp that uses multi tier architecture. The application must provide interfaces for HTML as well as XML and
should be maintainable.Which design pattern would you use?

Select 1 correct option.
A.Data Access Object
B.Business Deligate
C.MVC
D.Remote Method Invocation
E.Transfer Object

ANS : C

3.Which of the following directives are applicable ONLY for tag files?

Select 3 correct options.
A.attribute
B.variable
C.page
D.include
E.import
F.tag

ANS : A,B,F

4.Which of the following are correct about FORM based authentication mechanism?

Select 3 correct options.
A.HTML FORM is used to capture the username and password of the user.
B.Password is transmitted as plain text.
C.Password is transmitted in an encrypted form.
D.Password is transmitted either in encrypted text or in plain text depending on the browser.
E.This mechanism can be used over HTTPS.

ANS :A,B,E

5.Which pattern allows you to replace the presentation logic without much impact on the data representation?

Select 1 correct option.
A.Model View Controller
B.Business Delegate
C.Transfer Object
D.Data Access Object
E.Bimodal DataAccess

ANS : A

6.Identify the elements that help describe the attribute characteristics of a JSP custom tag in a TLD file.

Select 3 correct options.
A.value
B.name
C.description
D.rtexprvalue
E.class

ANS : B,C,D

7.Select the correct return types for ServletContext.getResource() and ServletContext.getResourceAsStream() methods.

Select 1 correct option.
A.java.io.Resource and java.io.InputStream
B.java.io.Resource and java.io.BufferedInputStream
C.java.net.URL and java.io.InputStream
D.java.io.File and java.io.InputStream
E.java.net.URL and java.io.FileInputStream

ANS :C

8.Consider the following jsp code:

<html>

<body>

<% String a = "aaa"; %>

<%! String a = "AAA"; %>

<% String b = "bbb"; %>

<%! String b = "BBB"; %>

<% out.println(a+b); %>

</body>

</html>

What will be the output?

Select 1 correct option.
A.aaabbb
B.aaaBBB
C.AAAbbb
D.AAABBB
E.Compilation error!

ANS :A

9.Which of the following are valid values for the <transport-guarantee> element?

Select 3 correct options.
A.CONFIDENTIAL
B.INTEGRAL
C.SECURE
D.ENCRYPTED
E.NONE

ANS : A,B,E

10.Write the parent element of <session-timeout> element.
ANS : session-config

11.Consider the tag handler class shown in exhibit.
What will be printed when the above tag is used as follows in a jsp page:

Hello <mylib:mytag> World!</mylib:mytag>

public class MyTag extends TagSupport

{

public int doAfterBody()

{

try

{

pageContext.getOut().println("In doAfterBody()");

}

catch(Exception e)

{

}

return SKIP_BODY;

}

}

Select 1 correct option.
A.Hello
B.Hello World!
C.Hello In doAfterBody() World!
D.Hello In doAfterBody()
E.None of the above.

ANS : A

12.Which of the following HTTP protocol methods is eligible to produce unintended side effects upon multiple identical invocations beyond
those caused by single invocation?

Select 1 correct option.
A.GET
B.POST
C.HEAD
D.PUT
E.OPTIONS

ANS : B

13.Which method of ServletResponse would you use to set its content type?

Select 1 correct option.
A.setParameter
B.setHeader
C.setAttribute
D.setContentType
E.None of the above.

ANS :D

14.<jsp:useBean id="mybean" beanName="my.app.MyBean" class="my.app.MyBean" /> is a valid useBean declaration.
Options.
A.True
B.False

ANS :B

15.Which of the following lines can be used to retrieve a servlet initialization parameter "dbname" from the init() method of a servlet?
public void init()

{

String dbname = //1 : Insert line here

}
Select 2 correct options.
A.getServletConfig().getParameter("dbname");
B.getServletConfig().getInitParameter("dbname");
C.getServletContext().getInitParameter("dbname");
D.getInitParameter("dbname");
E.getInitParameterValue("dbname");

ANS :B,D

16.Consider the following description of a tag in a TLD:
<tag>

<name>SmilyTag</name>

<tag-class>com.enthuware.ctags.SmilyTag</tag-class>

<description>

Replaces emoticons such as :), :D, and :( with images.

</description>

<body-content>tagdependent</body-content>

<attribute>

<name>name</name>

<required>false</required>

<rtexprvalue>true</rtexprvalue>

</attribute>

</tag>
Which of the following statements regarding the above tag are correct?

Select 2 correct options.
A.It is an empty tag.
B.It may be used as an empty tag.
C.It must have a body
D.It must implement BodyTag interface.
E.It may take an attribute named 'name'. But if present, its value must be dynamic.

ANS : B,D

17.Which of the following jsp fragments will print all the parameters and their values present in a request?

1.

<% Enumeration enum = request.getParameterNames();

while(enum.hasMoreElements()) {

Object obj = enum.nextElement();

out.println(request.getParameter(obj));

} %>



2.

<% Enumeration enum = request.getParameters();

while(enum.hasMoreElements()) {

String obj = (String) enum.nextElement();

out.println(request.getParameter(obj));

} %>



3.

<% Enumeration enum = request.getParameterNames();

while(enum.hasMoreElements()) {

String obj = (String) enum.nextElement();

out.println(request.getParameter(obj));

} %>



4.

<% Enumeration enum = request.getParameterNames();

while(enum.hasMoreElements()) {

Object obj = enum.nextElement(); %>

<%=request.getParameter(obj); %>

<% } %>



5.

<% Enumeration enum = request.getParameterNames();

while(enum.hasMoreElements()) {

String obj = (String) enum.nextElement(); %>

<%=request.getParameter(obj)%>

<% } %>

Select 2 correct options.

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

ANS : C,E

18.Which of the following statements are valid JSP directive?
Select 2 correct options.
A.<%! int k = 10 %>
B.<% int k = 10; %>
C.<%=somevariable%>
D.<%@ taglib uri="http://www.abc.com/tags/util" prefix="util" %>
E.<%@ page language="java" import="com.abc.*"%>

ANS : D,E

19.How can you ensure the continuity of the session while using HttpServletResponse.sendRedirect() method when cookies are not
supported by the client?

Select 1 correct option.
A.By using hidden parameters.
B.By enconding the redirect path with HttpServletResponse.encodeRedirectURL() method.
C.By using HttpSession.encodeURL() method.
D.By using HttpServletRequest.encodeURL() method.
E.By using HttpServletResponse.encodeURL() method.

ANS : B

20.Which of the following are valid implicit variables in a JSP page?

Select 2 correct options.
A.error
B.page
C.this
D.root
E.context

ANS :B,C

21.A Tag Handler implements BodyTag interface. How many times its doAfterBody method may be called?

Select 1 correct option.
A.BodyTag does not support doAfterBody.
B.0
C.1
D.0 or 1
E.Any number of times.

ANS : E

22.Given: You have configured a listener class (see exhibit) in web.xml of a web application.
Now, consider the following code for the doGet() method of a servlet for the same web application.

public void doGet(HttpServletRequest req, HttpServletResponse res)

{

System.out.println(this.getServletContext().getAttribute("key"); //2

}
Which option can be inserted at //1 in the listener code so that servlet code at //2 prints 100?

import javax.servlet.*;

public class MyListener implements ServletContextListener

{

public void contextInitialized(ServletContextEvent sce)

{

Integer key = new Integer(100);

// 1 Insert code here.

}

public void contextDestroyed(ServletContextEvent sce)

{

}

}
Select 1 correct option.

A.this.setAttribute("key", key);
B.this.getServletContext().setAttribute("key", key);
C.this.getContext().setAttribute("key", key);
D.sce.getContext().setAttribute("key", key);
E.sce.getServletContext().setAttribute("key", key);

ANS : E

23.Which of the following interfaces declares the methods jspInit() and jspDestroy()?

Select 1 correct option.
A.javax.servlet.jsp.JSP
B.javax.servlet.jsp.JspServlet
C.javax.servlet.jsp.JspPage
D.javax.servlet.jsp.HttpJspPage
E.javax.servlet.jsp.HttpJspServlet

ANS :C

24.Which of the following statements are correct JSP directives?

Select 2 correct options.
A.<%@ page %>
B.<%! taglib uri="http://www.abc.com/tags/util" prefix="util" %>
C.<% include file="/copyright.html"%>
D.<%@ taglib uri="http://www.abc.com/tags/util" prefix="util" %>
E.<%$ page language="java" import="com.abc.*"%>

ANS :A.D

25.Which of the following classes hides the implementation details and provides a standard API to the services provided by the servlet
container to a jsp page?

Select 1 correct option.
A.HttpSession
B.Servlet
C.JspPage
D.ServletContext
E.PageContext

ANS : E

26.Which of the following are true regarding the parameters defined using the <context-param> element of a deployment descriptor?

Select 2 correct options.
A.They are thread safe.
B.They are accessible from multiple threads simultaneously and from any servlet of the web application.
C.They can be modified using the setAttribute() method.
D.They can be modified using the setParameter() method.
E.They can be modified using the setInitParameter() method.

ANS : A,B

27.How can you explicitly expunge the session object?

Select 1 correct option.
A.You cannot. It can only be expunged automatically after session timeout expires.
B.By calling invalidate() on session object.
C.By calling expunge() on session object.
D.By calling delete() on session object
E.By calling finalize() on session object.

ANS : B

28.You have declared a useBean tag as:
<jsp:useBean id="man" class="animal.Human" scope="application"/>
In which type of object will this bean be kept?

Select 1 correct option.
A.Servlet
B.HttpSession
C.ServletContext
D.ServletConfig
E.ApplicationContext

ANS : C

29.Which of the following is a sensible way of sending an error page to the client in case of a business exception that extends from
java.lang.Exception?

Select 2 correct options.
A.Catch the exception and use RequestDispatcher to forward the request to the error page.
B.Don't catch the exception and define the 'exception to error-page' mapping in web.xml
C.Catch the exception, wrap it into ServletException and define the 'business exception to error-page' mapping in web.xml
D.Catch the exception, wrap it into ServletException, and define the 'ServletException to error-page' mapping in web.xml
E.Don't do anything, the servlet container will automatically send a default error page

ANS : A,C

30.Business delegate pattern should be used to enable communication between the JSP code and the enterprise javabeans.
Options.
A.True
B.False

ANS : A












No comments: