Tuesday, January 16, 2007

SCWCD 1.4 Mock Questions - 5

SCWCD 1.4 Mock Exams and Priactice Questions

1.you are using a tag library with prefix "generator", which supports a tag named "random". This tag generates a random number and sets it to a variable named "value". Which of the following will output this value in the page?

Select 1 correct option.
A.<generator:random>value</generator:random>
B.<generator:random><%=value%></generator:random>
C.<generator:random><% int value;%> <%=value%></generator:random>
D.<generator:random><%getParameter("value")%></generator:random>
E.None of the above

ANS : B

2. Which of the following pairs of HTTP method and HttpServlet class method are a valid combination for a request and the request handler method?

Select 2 correct options.
A.GET - service()
B.POST - doPost()
C.GET - doPost()
D.GET - doGet()
E.POST - service()

ANS : B,D

3.You want to get notified whenever there is a change in the attribute list of the ServletContext of your web application. Which listener interface would you implement?

Select 1 correct option
A.ServletListener
B.ServletContextListener
C.ServletContextAttributeListener
D.HttpServletContextListener
E.HttpServletListener

ANS : C

4.A JSP page myerror.jsp has been invoked as a result of an exception from another JSP page. How can you access the Throwable object that refers to the exception in myerror.jsp?

Select 1 correct option.
A.Using the implicit variable error
B.Using the implicit variable request.error
C.Using the implicit variable exception
D.Using the implicit variable throwable
E.None of these because the class of the implicit variable is not java.lang.Throwable

ANS : C

5.Which of the following are valid return values for doStartTag() method?

Select 3 correct options.
A.BodyTag.SKIP_BODY
B.Tag.SKIP
C.Tag.EVAL_BODY_INCLUDE
D.Tag.EVAL_BODY_AGAIN
E.BodyTag.EVAL_BODY_BUFFERED

ANS : A,C,E

6.Which of the following statements are correct for a custom tag that can take any number of arbitrary attributes?

Select 2 correct options.
A.The body-content element for the tag in the TLD file must have a value of JSP.
B.The tag handler must implement the method setAttribute(String key, String value).
C.The tag element in the TLD file for the tag must have <dynamic-attributes>true</dynamic-attributes>.
D.The class implementing the tag must implement javax.servlet.jsp.tagext.DynamicAttributes interface.
E.Dynamic attributes cannot have request time expression values
F.A JSP page sets a dynamic attribute using <jsp:setDynamicAttribute> action

ANS : C,D

7.Assuming that <%@ taglib uri="/utils" prefix="util" %> occurs before the use of the custom tags of the tag library named utils, identify the possibly valid empty custom tag declarations. (Assume that transpose is a valid tag in the given tag library.)

Select 2 correct options.
A.<util:transpose/>
B.<util:transpose></util:transpose>
C.<util:transpose>200</util:transpose>
D.<taglib:util:transpose />
E.None of the above is correct as every tag has to
have a body

ANS : A,B

8.Which of the following defines the class name of a tag in a TLD?

Select 1 correct option.
A.tag-class-name
B.tag-class
C.class-name
D.class

ANS : B

9.What should be the value of <body-content> subelement of element <tag> in a TLD file if the tag should not have any contents as its body?

Select 1 correct option.
A.blank
B.empty
C.null
D.false
E.The <body-content> subelement itself should be absent

ANS : B

10.Which interface and method should be used to retrieve a servlet initialization parameter value?

Select 1 correct option.
A.ServletConfig : getParameter(String name)
B.ServletConfig : getInitParameter(String name)
C.ServletContext : getInitParameter(String name))
D.ServletConfig : getInitParameters(String name)
E.ServletConfig : getInitParameterNames(String name)

ANS : B

11. You need to put a com.enthu.User bean referred by 'userBean' variable in request scope with an ID of "user" from within a servlet. Which of the following statements accomplishes this task?

Select 1 correct option.
A.request.put("user", userBean);
B.request.add(userBean, "user");
C.request.putAttribute("user", userBean);
D.request.setAttribute("user", userBean);
E.request.setParameter(userBean, "user");
F.request.put(userBean, "user");

ANS : D

12.Consider the following code:
public class MyTagHandler extends TagSupport 

{

public int doStartTag() throws JspException

{

try

{

//insert code here

}

catch(Exception e){ }

return super.doStartTag();

}

}
Which of the following options, when inserted in the above code causes the value "hello" to be output?

Select 1 correct option.
A.JspWriter out = pageContext.getOut();
out.print("hello");
B.JspWriter out = pageContext.getWriter();
out.print("hello");
C.JspWriter out = getPageContext().getWriter();
out.print("hello");
D.JspWriter out = new JspWriter(pageContext.getWriter());
out.print("hello");
E.JspWriter out = getPageContext().getOut();
out.print("hello");

ANS : A

13.Which of the following is a correct JSP declaration for a variable of class java.util.Date?

Select 1 correct option.

A.<%! Date d = new Date() %>
B.<%@ Date d = new Date() %>
C.<%! Date d = new Date(); %>
D.<%$ Date d = new Date() %>

ANS : C

14.Which method can be invoked on a session object so that it is never invalidated by the servlet container automatically?

Select 1 correct option.
A.setTimeOut(-1)
B.setTimeOut(Integer.MAX_INT)
C.setTimeOut(0)
D.setMaxInactiveInterval(-1)
E.setMaxInactiveInterval(Integer.MAX_INT)

ANS : D

15.Which of the following elements are mandatory under the <web-app> element of a deployment descriptor?

Select 1 correct option.
A.<doctype>
B.<app-name>
C.<servlet>
D.<doc-root>
E.None of these.

ANS : E

16.Which of the following implicit variables should be used by a jsp page to access a page initialization parameter?

Select 1 correct option.
A.pageContext
B.application
C.config
D.context
E.page

ANS : C

17.You are given a tag library that has:
1. A tag named getMenu that takes an attribute 'subject' which can be a dynamic value.
2. A tag named getHeading that takes an attribute 'report'.
Which of the following are correct uses of this library?

Select 3 correct options.
A.<myTL:getMenu subject="Finance"/>
B.<myTL:getMenu subject="<myTL:getHeading report=1/>"/>
C.<myTL:getMenu subject='<myTL:getHeading report="1"/>'/>
D.<% String subject="HR";%> <myTL:getMenu subject="<%=subject%>"/>
E.<myTL:getHeading report="2"/>

ANS : A,D,E

18.You are working with a tag library which is packaged in a jar file named htmlutil.jar.
This jar file also contains a META-INF/htmlutil.tld file which has a uri element as follows:
<uri>http://www.xyzcorp.com/htmlLib</uri>
What can you do to access this library from your JSP pages
Select 1 correct option.
A.You must define the <taglib> element in the web.xml to specify
the mapping for <taglib-uri> to the location of this jar file.
B.There is no need for the <taglib> element in the web.xml, however, you need the taglib directive in the JSP pages.
C.You can directly access the tags of this library from the JSP pages without any taglib directive.
D.You do not need the taglib directive, but you do need to specify the <taglib> element in the web.xml.
E.None of these.

ANS : B

19.Which of the following are valid iteration mechanisms in jsp?
1.
<% int i = 0;
while(i<5)
{
"Hello World"
i++;
} %>

2.
<jsp:for loop='5'>
"Hello World"
</jsp:for>

3.
<% int i = 0;
for(;i<5; i++)
{ %>
"Hello World";
<% i++;
}
%>

4.
<table>
<% Iterator it = aSet.iterator();
int i = 0;
while(it.hasNext())
{
out.println("<tr><td>"+(++i)+"</td>");
out.println("<td>"+it.next()+</td></tr>");
}
%>
</table>

5.
<jsp:scriptlet>
for(int i=0; i<5; i++)
{
</jsp:scriptlet>
<jsp:text>"Hello World!"</jsp:text>
<jsp:scriptlet>
}
</jsp:scriptlet>

Select 3 correct option.

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

ANS : C,D,E

20. Your web application wants to make use of a role named 'manager', which is defined in the servlet container.
Which of the following XML fragments must occur in the deployment descriptor of your web application?
1.
<role name='manager' />
2.
<role>
<role-name>manager</role-name>
</role>
3.
<role>manager</role>
4.
<security-role>
<role-name>manager</role-name>
</security-role>

Select 1 correct option.
A.1
B.2
C.3
D.4

ANS : D

21.Consider the class shown in exhibit. Which of the following statements are correct?

public class MyHSAListener implements HttpSessionAttributeListener
{
public void attributeAdded(HttpSessionBindingEvent e){ }
public void attributeRemoved(HttpSessionBindingEvent e){ }
}

Select 1 correct option.
A.public void attributeReplaced(...){ } must be added.
B.public void attributeChanged(...){ } must be added.
C.The parameter class should be HttpSessionEvent.
D.The parameter class should be HttpSessionAttributeEvent.
E.It will compile as it is.

ANS : A

22.Identify the implicit objects available to EL expressions

Select 4 correct options.
A.request
B.sessionScope
C.paramValues
D.params
E.cookie
F.initParam

ANS : B,C,E,F

23.Which of the following statements are correct regarding tag libraries?

Select 1 correct option.
A.The tag library descriptor for a tag library must be kept in META-INF/taglib.tld, if the tag library is packaged in a jar file.
B.The tag library descriptor for a tag library may be kept in WEB-INF/taglib.tld, if the tag library is packaged in a jar file.
C.A JSP 2.0 compliant container is guaranteed to generate implicating mapping for JSTL tag libraries.
D.A JSP 2.0 compliant container will automatically generate an implicit tag library for a set of tag files.
E.The tag library descriptor for a tag library not packaged as a jar file may be kept anywhere in /tld directory of the web application's
document root

ANS : D

24.Consider the following usage of a custom tag in a JSP page:

<jsp:useBean id="student" scope = "session" class="com.xyz.Student" />
<mytaglib:studentTag student='student' />

Which of the following statements are correct?

Select 1 correct option.
A.Application objects such as com.xyz.Student, cannot be passed as attributes to custom tags.
B.The Student object will be passed to the studentTag tag handler.
C.The Student object will NOT be passed because no variable named student is defined.
D.A Student object will not be created if it is not available it the session.
E.None of these.

ANS : E

25.Assuming that the Servlet Container has just called the destroy()
method of a servlet instance, which of the following statements are
correct?

Select 2 correct options.
A.Any resources that this servlet might hold have been released.
B.The servlet container time out has exceeded for this servlet instance.
C.The init() method has been called on this instance.
D.None of the requests can EVER be serviced by this instance.
E.All threads created by this servlet are done.

ANS : C,D

26.For a tag to accept any valid jsp code as its body, what should be the
value of <body-content> for this tag's taglib descriptor?

Select 1 correct option.
A.JSP
B.jsp
C.any
D.text
E.The <body-content> subelement itself may be absent.

ANS : E

27.Which of the given options can be used in a servlet code that needs to access a binary file kept in WEB-INF/data.zip while servicing a request?
Assume that config refers to the ServletConfig object of the servlet and context refers to the ServletContext object of the servlet.

Select 1 correct option.
A.InputStream is = config.getInputStream("/WEB-INF/data.zip");
B.InputStream is = context.getInputStream("data.zip");
C.InputStream is = context.getResourceAsStream("/WEB-INF/data.zip");
D.InputStream is = context.getResourceAsStream("WEB-INF/data.zip");
E.InputStream is = config.getResourceAsStream("WEB-INF/data.zip");

ANS : C

28.Servlet Container calls the init method on a servlet instance ...

Select 1 correct option.
A.For each request to the servlet.
B.For each request to the servlet that causes a new session to be created.
C.For each request to the servlet that causes a new thread to be created.
D.Only once in the life time of the servlet instance.
E.If the request is from the user whose session has expired.
F.Initialy when the servlet instance is create and then at request time if the request is from the user whose session has expired.

ANS : D

29.Identify the implicit objects accessible to a jsp page that can store objects accessible across multiple requests.

Select 2 correct options.
A.page
B.request
C.session
D.application
E.pageContext

ANS:C,D

30.You are developing a jsp page named stockindices.jsp. This jsp page needs to use a HTML page named nasdaq.html in the middle of the page,
which is updated every ten minutes by some other process. Which of the following lines, when added to stockindices.jsp, ensures that
stockindices.jsp uses the latest nasdaq.html?

Select 1 correct option.
A.<%@include page='nasdaq.html' %>
B.<%@include file='nasdaq.html' %>
C.<jsp:include page='nasdaq.html' />
D.<jsp:include file='nasdaq.html' />
E.<jsp:forward page='nasdaq.html' />

ANS : D























No comments: