Servlet JSP
Servlet JSP
Servlet JSP
No Question 1 Which of the following files is the correct name and location of deployment descriptor of a 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
2 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>
import javax.servlet.*;
import javax.servlet.http.*:
import java.io.*;
2
5 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
7 Which of these is a correct fragment within the web-app element of deployment descriptor. Select the
two correct answer.
A <error-page> <error-code>404</error-code> <location>/error.jsp</location> </error-page>
<error-page> <exception-type>mypackage.MyException</exception-type> <error-code>404</error-code>
B
<location>/error.jsp</location> </error-page>
<error-page> <exception-type>mypackage.MyException</exception-type> <error-code>404</error-code>
C
</error-page>
<error-page> <exception-type>mypackage.MyException</exception-type> <location>/error.jsp</location>
D
</error-page>
3
8 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>
9 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 <listener>MyClass</listener>
B <listener> <listener-class>MyClass</listener-class></listener>
C <listener> <listener-name>aListener</listener-name> <listener-class>MyClass</listener-class> </listener>
D <><listener> <servlet-name>myServlet</servlet-name> <listener-class>MyClass</listener-class> </listener>
10 Which of the following is legal JSP syntax to print the value of i. Select the one correct answer
<<%int i = 1;%>
A
<%= i; %>
<%int i = 1;
B
i; %>
<%int i = 1%>
C
<%= i %>
<%int i = 1;%>
D
<%= i %>
<%int i = 1%>
E
<%= i; %>
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.
4
The second statement on the other hand is a JSP expression. So it must not end
with a semi colon.
No Question 11 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
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
13 Which of the following can be used to configure the JSP container to ignore EL expressions?
A <%@ page isELIgnored="true" %>
B <%@ page isELIgnored="false" %>
5
C <%@ import isELIgnored="false" %>
D None of the above.
B session
C page
D request
15 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.*" %>
16 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
6
17 <%@ 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
19 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()
7
20 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
B PUT
C POST
D HEAD
22 When a user clicks on a link in a page, which method will get invoked ?
A POST
B PUT
C GET
D HEAD
8
<input type="submit" value="Submit">
</form>
A GET
B POST
C HEAD
D PUT
B &
C =
D ;
25 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
9
26 Which of the following listeners will be called when a context is destroyed?
A HttpServletContextListner
B HttpSessionListener
C ServletContextDestroyedListener
D ServletContextListener
B contextInitialized(HttpServletContextEvent)
C contextInitialized(ServletContextEvent)
D contextInitialized(SevletContext)
B HttpListener
C HttpSessionAttributeListener
D HttpSessionActivationListener
10
29 Which exception will be thrown, when a servlet is unavailable temporarily ?
A ServletException
B UnavailableException
C IOException
D UnAccessibleException
B ServletRequest
C HttpServletRequest
D ServletResponse
E HttpServletResponse
34 What is the argument for init() method ? Select all that apply.
A ServletContext
B ServletConfig
C HttpServletConfig
D HttpServlet
E No arguments
12
35 If a single client makes two requests, how many threads will be created by the container ?
A 0
B 1
C 2
D 3
36 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
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.
Q. No Question 41 What is the return type of request.getParameterValues()
A String
B Vector
C String[]
D ArrayList
14
42 What methods are used to get the header information from the client ? Select all that apply.
A request.getHeader(String)
B request.getFormHeader(String)
C request.getIntHeader(String)
D request.getDateHeader(String)
44 Which methods are used to set a header? Choose all that apply.
A response.setHeader()
B response.addHeader()
C response.addStringHeader()
D response.setDateHeader()
E response.addDateHeader()
15
B response.sendRedirect(String)
C response.sendURL(java.net.URL)
D response.sendURL(String)
46 Which method is used for finding out what the server is receiving ?
A GET
B POST
C PUT
D TRACE
A Hello..
B System.out.println("Hello..")
C Compiler Error
D java.io.PrintStream@1ccf82Hello
import javax.servlet.http.*;
16
}
A Blank Screen
B Runtime Error
C Compiler Error
D HTTP 405, error message.
D HTTP 404, error message.
The <login-config> element does not define any mandatory sub element.
Q. No Question 51 What of the following will correctly add a context initialization parameter in web.xml
?
A <servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>mypack.MyServlet</servlet-class>
<init-param>
<param-name>adminmail</param-name>
<param-value>[email protected]</param-value>
</init-param>
17
</servlet>
B <init-param>
<param-name>mymail</param-name>
<param-value>[email protected]</param-value>
</init-param>
C <context-param>
<param-name>mymail</param-name>
<param-value>[email protected]</param-value>
</context-param>
D <context>
<param-name>mymail</param-name>
<param-value>[email protected]</param-value>
</context>
18
53 When servlet init parameter will be read ?
A When client makes a request.
B When starting server
C When container initializes the servlet
D When container shuts down.
54 Which method is used to read the context initialization parameter ? Select two
A getServletConfig().getInitParameter();
B getServletContext().getInitParameter();
C getServletConfig().getContextParameter();
D getServletContext().getServletParameter();
E getServletConfig().getServletContext().getInitParameter();
19
56 What getInitParameterNames() of ServletContext does ?
A Returns the init parameters for a servlet
B Returns the init parameter names of a servlet
C Returns the init parameter names of the context
D All of the above.
58 Which of the following code snippet will correctly add a ServletContextListener to your web
application?
A <listener><listener-class>MyClass</listener-class></listener>
B <context-listener><listener-class>MyClass</listener-class></context-listener>
C <listener><context-listener><listener-class>MyClass</listener-class></context-listener></listener>
D <listener><listener-name>Context</listener-name><listener-class>MyClass</listener-class></listener>
20
60 Which method is used to know when a request is created ?
A RequestListener
B ServletRequestListener
C ServletRequestAttributeListener
D servletListener
21
B session
C request
D page
64 Which of the following code snippet is thread safe ? Assume all imports and declarations are done
correctly.
A public void doGet (HttpServletRequest request, HttpServletResponse response) throws IOException,
ServletException {
getServletContext().setAttribute("name","Albin");
}
B public synchronized void doGet (HttpServletRequest request, HttpServletResponse response) throws
IOException, ServletException {
getServletContext().setAttribute("name","Albin");
}
C public void doGet (HttpServletRequest request, HttpServletResponse response) throws IOException,
ServletException {
synchronized (getServletContext()) {
getServletContext().setAttribute("name","Albin");
}
}
D All of the above.
22
66 Which method can be used to keep track of number of concurrent users?
A ServletContextListener
B ServletSessionListener
C HttpSessionBindingListener
D HttpSessionListener
67 Your application is distributed in different JVMs, you want to be notified when a session is migrated to
another JVM. How will you do this ?
A HttpSessionActivationListener
B HttpSessionPassivationListener
C HttpSessionListener
D HttpSessionAttributeListener
D
Q. No Question 71 Which of the following code will work fine? Assume all the variables are initialized
properly. Select two
A getServletContext().getRequestDispatcher("/test.jsp");
B getServletContext().getRequestDispatcher("test.jsp");
C request.getRequestDispatcher("/test.jsp");
D All of the above
24
72 Which method in conjunction with forward will cause an exception ?
A flush()
B setContentType()
C read()
D getOutputStream()
73 Which of the following code will work fine ? Assume all the variables are initialized properly. Select
two
public void doGet (HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{
PrintWriter out = response.getWriter();
A
ServletOutputStream stream = response.getOutputStream();
out.println ("Worked....");
}
public void doGet (HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{
PrintWriter out = response.getWriter();
B
response.setContentType("text/html");
out.println ("Worked....");
}
public void doGet (HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{
PrintWriter out = response.getWriter();
C out.flush();
response.setContentType("myname");
out.println ("Worked....");
}
D None of the above
74 Which method is used to specify the content of the response is a binary file?
A setContent();
B setBinaryOutput()
25
C setContentType();
D sendRedirect();
77 Your application is using a third party jar. Where will you keep this jar file ?
A WEB-INF
B WEB-INF\classes
C WEB-INF\lib
D WEB-INF\jar
26
78 We have a deployment descriptor with the following entry.
<servlet-mapping><servlet-name>MyServlet</servlet-name><url-pattern>*.do</url-pattern></servlet-
mapping>. Which of the following requests will not be handled by MyServlet?
A /MyServlet.do
B /scwcd/Myservlet
C /scwcd/Myservlet.do
D /*.do
80 Which method ensures that the session will never be expunged by the container ?
A session.setMaxInactiveInterval(0);
B session.setMaxInactiveInterval(1)
C session.setMaxInactiveInterval(-1);
D None of the above
27
82 encodeURL is a method of which class/interface?
A HttpServletRequest
B HttpServletResponse
C ServletConfig
D ServletContext
83 What is the symbol used to separate URL and Session id in URL rewriting?
A ;
B :
C ?
D Vendor specific
85 Which of the following description correctly define that the session will never expire ? Select two
<session-config>
A <session-timeout>0</session-timeout>
</session-config>
28
<session-config>
B <session-timeout>1</session-timeout>
</session-config>
<session-config>
C <session-timeout>NEVER</session-timeout>
</session-config>
<session-config>
D <session-timeout>-1</session-timeout>
</session-config>
86 What will be the output of the following code snippet inside doGet method ? Assume all variables are
declared an initialized properly?
29
88 Which method correctly specifies that the cookie must be alive for one hour ? Assume all variables are
declared and initialized properly.
A cookie.setMaxAge(1);
B cookie.setMaxAge(60);
C cookie.setTime(1);
D cookie,setMaxAge(3600);
89 Which method is used to add a cookie to the client ? Assume all variables are declared and initialized
properly
A request.setCookie(new Cookie("name","Albin"));
B response.setCookie(new Cookie("name","albin"));
C request.addCookie(new Cookie("name","Albin"));
D response.addCookie(new Cookie("name","Albin"));
C and D
Answer A is incorrect because the session will become invalid only if the user is
inactive for that specified amount of time. Other the session will never expire.
Answer B is incorrect because there is no way to notify the container that the cline
closed his window.
Q. No Question 91 State True or False. The session tracking cookie name is vendor specific.
30
A True
B False
96
Assume that all the imports are made correctly. Which statement is correct regarding the above class ?
32
97 In which directory we keep our servlets ?
A WEB-INF
B WEB-INF\classes
C WEB-INF\servlet
D WEB-INF\lib
33
100 <from method = "GET" action = "MyServlet">
<input type= "text" name="txtName">
<input type= "text" name = "txtName">
<input type = "submit">
</from>
Which statement can be used to get the value of second text box from MyServlet ?
A String value = request.getParameter("txtName");
B String value = request.getAttributeValues("txtName") [1];
C String value = request.getParameterValues("txtName") [0]
D String value = request.getParameterValues("txtName") [1];
Option A is incorrect because it will return the value of first text box only. The
same thing happens for C also. Option B is incorrect because there is no such
method exist.
Q. No Question 101 Which listener need not to configure in DD?
A HttpSessionActivationListener
B HttpSessionBindingListener
C HttpSessionAttributeListener
D HttpSessionListener
34
D public void sessionDidActivate(HttpSessionDidActivateEvent e) {}
106
Which statement correctly imports the java.util.* and java.io.* package in JSP ?
35
107 Which of the following is a valid JSP declaration ?
A <%= "Hello" %>
B <%! int x=10 %>
C <%! int x=10; %>
D <% int x=10; %>
108 <html><body>
<form action="test.jsp" method="GET">
<input type=text name="txtName">
<input type=Submit value = "Submit">
</form>
</body></html>
test.jsp
<% String name= request.getParameter("txtName"); %>
Name = <%= name %>
What will be the output if the user submits the form after inputting the name "Bill" ?
36
110 Which of the following JSP life cycle methods we should not override ?
A jspInit()
B _jspService
C jspDestroy
D All of the above.
We cannot override the _jspService method which is called from the generated
servlet's service method.
Q. No Question 111 How can we pre compile a JSP ?
A Invoke JSP by appending query string '?jsp_precompile'
B Invoke JSP by appending query string '?jsp-precompile=true'
C Invoke JSP after appending query string '?precompile=true'
D We cannot precompile a JSP page. We need to wait till the first request come, to compile JSP.
112 Which of the following will correctly configure init parameter for a JSP?
A <servlet>
<jsp-name>test.jsp</jsp-name>
<jsp-file>test.jsp</jsp-name>
<init-param>
<param-name>Abc</param-name>
<param-value>Xyz</param-value>
</init-param>
</servlet>
B <servlet>
<servlet-name>test.jsp</servlet-name>
<jsp-file>test.jsp</jsp-name>
<init-param>
<param-name>Abc</param-name>
<param-value>Xyz</param-value>
37
</init-param>
</servlet>
C <jsp>
<jsp-file>test.jsp</jsp-name>
<init-param>
<param-name>Abc</param-name>
<param-value>Xyz</param-value>
</init-param>
</jsp>
D We cannot configure init parameter for JSP.
114 The following code snippet retrieves values from which scope ?
<%= pageContext.getAttribute("name") %>
A session
B page
C application
D pageContext
115 How can we retrieve attributes from session scope using pageContext.
A <%= pageContext.getAttribute("name") %>
38
B <%= pageContext.getAttribute("name", PageContext.HttpSessionScope) %>
C <%= pageContext.getAttribute("name", PageContext.SESSION_SCOPE) %>
D <%= (Session) pageContext.getAttribute ("name") %>
116 Which of the following piece of code correctly set an attribute in application scope ?
A We cannot set attributes to application scope using pageContext.
B <% pageContext.setAttribute("name", "albin", PageContext_APPLICATION_SCOPE); %>
C <% pageContext.setAttribute("name","albin", PageContext.APPLICATION_SCOPE); %>
D <% pageContext.setAttribute("name","ablin",PageContext.CONTEXT_SCOPE); %>
117 <%
request.setAttribute("name","abc");
session.setAttribute("name","xyz");
application.setAttribute("name","pqr");
%>
What will be the return value if we are calling <%= pageContext.findAttribute("name") %> on the same
page?
A null
B abc
C xyz
D pqr
39
118 How can we create a thread safe JSP ?
A <%@ page isThreadSafe = "true" %>
B <%@ page implements="SingleThreadModel" %>
C <%@ page isThreadSafe="false" %>
D <%@ page extends="SingleThreadModel" %>
Q. No Question 121 Which directive is used to declare the tag library used by the application?
A page
B include
C taglib
D taglibrary
40
122 Which is a requirement of a distributable Web application?
A It must not call the sendRedirect method.
B It must rely on URL rewriting for session handling.
C It should not use any EL
D It must not rely on the propagation of events caused by the manipulation of session attributes.
123 What all methods we use to access static resources from a web application ?
A ServletContext. getResource()
B ServeltContext.getResourceAsStream()
C ServletConfig.getResourceAsStream()
D HttpServlet.getResourceAsStream()
124 Which code snippet correctly declares the current JSP page to be an error page?
A <%@ page errorPage="true" %>
B <%@ page isErrorPage="true" %>
C <%@ errorPage="true" %>
D All JSP pages are error pages only, we don't need to declare it.
41
125 Which HTTP method represents a request for information about the supported methods on an HTTP
server?
A GET
B POST
C HEAD
D OPTIONS
126 What all the things prevent a servlet from handling requests.?
A Init method throws a ServletException
B The servlet's init method does NOT return within a time period defined by the servlet container.
C The servlet's init method sets the Servlet Response's content type to null.
D All of the above.
127 What all Http methods are used to process data in a servlet ?
A doOptions
B doHead
C doGet
D doPost
128 Which are valid URL mappings to a servlet in a web deployment descriptor?
A */*
42
B /*.do
C /MyServlet
D scwcd/MyServlet
E /MyServlet/*
129 Given a servlet MyServlet mapped to /MyServlet. And a from declaration in HTML:
<from action = "/MyServlet">
<input type="text" name="first_name">
<input type="text" name = "last_name">
<input type= "submit" value = "Submit">
</from>
What MyServlet method is invoked as a result of this from submission?
A doGet
B doPost
C doOptions
D doDelete
Q. No Question 131 Which code correctly sets an error page for a JSP?
A <%@ page isErrorPage="true" %>
43
B <%@ page errorPage="mypage.jsp" %>
C <%@ page isErrorPage="myerrorpage.jsp" %>
D <%@ page isErrorPage="false" %>
132 Which code snippet correctly specifies a super class for a JSP ?
A <%@ page super="MySuperClass" %>
B <%@ page extends="MySuperClass" %>
C <%@ page implements="MySuperClass" %>
D We need to configure DD for specifying the super class for a JSP
45
137 Which statements are true regarding the code snippet given below ?
<jsp:useBean id="abc" class="test.Abc" scope="page">
<jsp:setProperty name="abc" property="name" value="albin" />
</jsp:useBean>
A This will create a new bean each tine it is called and se the property also.
B This code will fail to run if 'abc' bean is not already present.
C This code set the property only if the bean is newly created.
D This code set the property only if the bean is already existing.
138 What statements are true regarding the following code snippet?
<jsp:useBean id="abc" type="test.Xyz" scope="page" />
A It will work fine under all circumstances.
B It will work fine if 'abc' bean is already exists in scope.
C It will fail under all circumstances because the class attribute is not pre4sent.
D It will throws an InstantiationException if the 'abc' bean is not already exists in scope.
46
C The code will throw an exception because we cannot specify the and class together.
D The code will throw an exception because the scope attribute is not present.
47
142 Given
public abstract class MySuperBean { }
test.jsp
<jsp:useBean id="my" type="test.MyBean" class="test.MySuperBean" />
48
145
49
148 <jsp:useBean id="myBean" class="test.MyBean " type="test.MySuperBean" /> Which of the
following are true regarding this code snippet ?
A An object of type test.MyBean is instantiated and assigned to a variable myBean of type test.MySuperBean
B An object of type test.MySuperBean is instantiated and assigned to a variable myBean of type test.MyBean
C To avoid error, test.MyBean must be super class of test.MySuperBean
D To avoid error, test.MySuperBean must be super class of test.MyBean
50
150 Given myBean.getName() returns a java.lang.String. Which of the following is equivalent to <%=
myBean.getName() %>
A <% out.print(myBean.getName(); %>
B <% writer.print(myBean.getName(); %>
C <% response.out.print(myBean.getName(); %>
D <% response.writer.print(myBean.getName(); %>
152
A /META-INF/web.xml
B /META-INF/dependencies.xml file
C /META-INF/MANIFEST.MF
D /META-INF/MANIFEST.MF of a JAR inside the web application.
153 A developer wants to ensure that data is updated in a thread-safe manner. But he don't want to use
SingleThreadModel because somewhere he read that, using SingleThreadModel is bad. So how he can
achieve this goal ?
51
A Store the data in a local variable.
B Store data in instance variable.
C Store data in session
D Store data in request.
154 A JSP page needs to connect to the database before servicing the first request. Where can this be
done?
155
156 What operations are always performed when the getSession method is called with no arguments in a
servlet?
A All URLs will be encoded with the session id
52
B An HttpSession object is created if an object not existing
C The user name and password of the user are checked.
D The session ID is stored in the HTTP response as a cookie or appended to the URL (depends).
157 Which method in HttpSession is used to retrieve the time in which the session is created.
A getCreationTime
B getTime
C getSessionCreationTime
D getSessionTime
53
<input type="Submit" value="Submit" />
</form>
test.jsp
<jsp:useBean id="bean" type="beans.MyBean" >
<jsp:setProperty name="beans" property="name" />
</jsp:useBean>
Which of the following statements regarding the above code is correct ?
A The code will fail at run time, because no value is specified in <jsp:setProperty>
B The code will pick up the value from corresponding request parameter and set the value automatically.
C The code will fail to compile, because the value attribute is missing.
D The MyBean contains a method called setName.
160 How to set all the request parameter to a bean without setting each parameter explicitly ?
A <jsp:setProperty name="bean" property="*" />
B <jsp:setProperty name="bean" value="*" />
C <jsp:setProperty name="bean" param="*" />
D <jsp:setProperty name="bean" value="all" />
If all our request parameter names matches with the property names in beans, we don't need to set the
property explicitly. We can just tell the container to set the property using the syntax <jsp:setProperty
name="bean" property="*" />. The container will iterate through the request parameters and find any
parameter that matches the bean's property names and sets the value of the matching properties.
Q. No Question 161 Which of the following is an attribute for <%@ include >?
A page
B file
C filename
D All of the above
54
162 What will be the result of executing a JSP with the following code ?
<%@ include file="inc.jsp?name=Abc" %>
163 Which of the following can be successfully inserted at line marked as 1 in test.jsp. So that it will print
Hello 'Bill' ?
test.jsp
// 1.
include.jsp
Hello Bill
A <%@ include file="include.jsp">
B <%@ include page="include.jsp">
C <%@ include="include.jsp" >
D <%@ include filename="include.jsp" >
55
165
Which of the following code correctly iterates over an array 'names' and print the values? Assume that all
taglibs imported correctly and a String array names names is available in the scope.
A <c:forEach items="${names}">
<c:out value="${names[0]"/>
</c:forEach>
B <c:forEach item="name" items="${names}">
<c:out value="${name}"/>
</c:forEach>
C <c:forEach var="name" item="${names}">
<c:out value="${name}" />
</c:forEach>
D <c:forEach var="name" items="${names}">
<c:out value="${name}" />
</c:forEach>
166 What attribute is used to get a loop counter in <c:forEach > tag?
A counter
B count
C varStatus
D var
167 Which of the following code correctly prints the value of loop counter?
A <c:forEach var="name" items="${names}" varStatus="loopCounter">
<c:out value="${loopCounter}" />
</c:forEach>
B <c:forEach var="name" items="${names}" varStatus="loopCounter">
<c:out value="${loopCounter.count}" />
56
<c:forEach>
C <c:forEach var="name" items="${names}" varStatus="loopCounter">
<c:out value="${loopCounter.counter}" />
<c:forEach>
D <c:forEach var="name" items="${names}" varStatus="loopCounter">
<c:out value="${loopCounter.coun()}" />
<c:forEach>
169 Which attribute is used to specify the starting element of loop counter in <c:forEach>
A start
B loopStart
C begin
D init
170 What will be the output of the following code? Assume that all the taglibs are imported correctly.
<%
String[] names = {"Bill", "Peter","James","Sam","Deb"};
pageContext.setAttribute("names", names);
%>
<UL>
<c:forEach var="name" items="${names}" varStatus="loopCounter" begin="2">
<LI><B><c:out value="${name}"/> : <c:out value="${loopCounter.count}" /></B>
57
</c:forEach>
</UL>
A Bill : 2
Peter : 3
James : 4
B James : 1
Sam : 2
Deb : 3
C James : 2
Sam : 3
Deb : 4
D Sam : 1
Deb : 2
The optional begin attribute will specify the starting element for the array. In this case the begin is 2 so the
iteration will start at index 2 of names array. i.e. at 'James'. But again the value of the first loop counter will
be 1 only. It will not change to two.
Q. No Question 171 Which element is used to specify the iteration steps in <c:forEach> ?
A skip
B step
C change
D increment
172 What will be the result of executing a JSP with the following code ?
<%
String[] names = {"Bill", "Peter","James","Sam","Deb"};
pageContext.setAttribute("names", names);
%>
<c:forEach var="name" items="${names}" varStatus="loopCounter" begin="3" step="-1">
<c:out value="${name}"/> : <c:out value="${loopCounter.count}" />
</c:forEach>
A Sam : 4
James : 3
Peter : 2
Bill : 1
B James : 3
Peter : 2
Bill : 1
C Sam : 1
58
James : 2
Peter : 3
D Error 500 - Internal server error.
174 Which attribute is used for specifying the ending value of loop counter in <c:forEach> ?
A end
B stop
C loopStop
D loopEnd
The optional end element is used to specify the ending value for the loop counter.
175
59
What will be the output of the following JSP code?
<%
String[] names = {"Bill", "Peter","James","Sam","Deb"};
pageContext.setAttribute("names", names);
%>
A Bill : 0
Peter : 1
James :2
B Bill : 1
Peter: 2
James : 3
C Bill : 1
Peter : 2
D Internal server error
60
177 What will be the output of the following piece of code.
<%
String[] names = {"Bill", "Peter","James","Sam","Deb"};
pageContext.setAttribute("names", names);
%>
<c:forEach var="name" items="${names}" varStatus="loopCounter"/>
<c:out value="${loopCounter.count}"/>
</c:forEach>
A 01234
B 12345
C 135
D Compile time error
61
180 Which code correctly checks a condition in JSTL? Select two
A <c:if test="${ name eq 'Bill'}">
B <c:if check="${ name eq 'Bill'}">
C <c:if test='${ name eq "Bill"}'>
D <c:if check='${ name eq "Bill"}'>
A and C
The <c:if> tag is used to test a condition in JSTL. Choice B and D are incorrect because the attribute name
is wrong. Inside the condition we can have either single quotes or double quotes. So choice A and C are
correct.
Q. No Question 181 Which of the following statements regarding <c:choose> is correct? Select two
A and C
<c:choose> tag is used to test multiple conditions like an if.. else if.. construct. The
<c:when> tag inside <c:choose> is used to specify the condition inside <c:choose> . The
<c:otherwise> is not a mandatory tag inside <c:choose>. It will only execute if none of the
<c:when> matches the criteria. Only one <c:when> or <c:otherwise> tag will execute.
182 What will be the output of the following piece of code.
<%
String name="Bill";
pageContext.setAttribute("name",name);
%>
<c:choose>
<c:when test="${ name == 'Bill'}"> Name is Bill</c:when>
<c:when test="${name == 'Jack'}">Name is jack</c:when>
<c:otherwise>Name is not Bill.</c:otherwise>
</c:choose>
62
B
In <c:choose> not more than one <c:when> will execute. It will look for the first matching
condition , if found it will execute it and exit from the <c:choose> , if not found a matching
condition , it will execute the <c:otherwise> if one present.
183 What will be the output of the following pecie of code.
<%
String name="Bill";
pageContext.setAttribute("name",name);
%>
<c:choose>
<c:when test="${ name == 'Bill'}">Name is Bill 1 </c:when>
<c:when test="${name == 'Bill'}">Name is Bill 2 </c:when>
<c:otherwise>Name is not Bill.</c:otherwise>
</c:choose>
The <c:choose> will look for the first matching condition , if found it will execute it and
exit from the <c:choose>. Here on execution it will find the matching condition on the first
<c:when> itself, so it will execute that block and exit <c:choose>
184 What will be the output of the following piece of code?
<c:set var="name" />
Jack
</c:set>
Since we have closed the <c:set> tag before setting the value , it will give a compile time
error . Because the container will not be able to find out the corresponding opening tag for
</c:set>.
185 What will be the output of the following code?
<%
String name="Bill";
pageContext.setAttribute("name",name);
%>
<c:set var="name">
Jack
63
</c:set>
Name = <c:out value="${name}"/>
The var version of <c:set> is used to set the attribute values. We can specify the values for
<c:set> in two ways, by using the attribute 'value' and by putting the value inside the tag
body. Here we have declared the value as Jack inside the tag body. So it will set the value of
name to 'Jack'
186 The var version of <c:set> sets the bean properties?
A True
B False
The var version of <c:Set> is used to set the attribute values. For setting the bean properteos
we need to use the target version of <c:set>
187 The 'target' version of <c:set> is used to set all collection values?
A True
B False
The target version of <c:set> is used to set bean properties and map values. But it will not
work with all collection types.
188 The value is a mandatory attribute in <c:set>?
A True
B False
Every <c:set> must have a value. But the attribute value is not mandatory. Because we can
set the value to <c:set> in two ways. By using the value attribute and by putting the value
inside the body of the tag. So if we are putting the value inside the body of the tag the value
attribute is not mandatory.
189 Which of the statements regarding <c:set> are true? Select two.
A <c:set> can be used to set the bean properties and map values.
64
B The var is a mandatory attribute in <c:set>
C If the value specified for 'value' attribute is null, the variable will be removed.
D The value of 'value' attribute must be evaluated to String
A and C
The <c:set> can be used to set bean properties , Map values and attribute values. So option
A is correct. Option B is incorrect because if we are using the target version of <c:set> the
var is not required. If the value evaluates to null, the variable will be removed from the
scope. So option C is correct. The value can be any type of object . So option D is incorrect.
190 Which of the following statements regarding <c:set> is false?
If the target expression evaluates to null, then the container will throw an exception. So
option C is incorrect.
JAVASCRIPT
4) How do you write a conditional statement for executing some statements only if "i" is equal to 5?
a) if i==5 then
b) if i=5 then
c) (your answer) if (i==5) - correct answer
d) if i=5
65
5) How do you write a conditional statement for executing some statements only if "i" is NOT equal to
5?
a) if (i <> 5)
b) (your answer) if (i != 5) - correct answer
c) if =! 5 then
d) if <> 5
9) How do you round the number 8.25, to the nearest whole number?
a) Math.rnd(8.25)
b) (your answer) Math.round(8.25) - correct answer
c) round(8.25)
d) rnd(8.25)
11) What is the correct JavaScript syntax for opening a new window called "window5" ?
a) new("http://www.ex-designz.net","window5")
b) (your answer) window.open("http://www.ex-designz.net","window5") - correct answer
c) open.newwindow("http://www.ex-designz.net","window5")
d) new.window("http://www.ex-designz.net","window5")
66
b) var myarray = array new;
c) var new Array() = myarray;
d) var new array = myarray;
17) Which property would you use to redirect visitor to another page?
a) window.location.href - correct answer
b) document.href
c) java.redirect.url
d) (your answer) link.redirect.href
b) k = a & i
c) k = a(i)
1) You are a junior web designer. Your company assigns you to work on a JavaScript project. Which of
the following are the advantages of using JavaScript for form validation? a) Conservation of client
CPU resources b) Increased validity of form submission c) Conservation of bandwidth d) Increase end-
user satisfaction e) Either BCD - correct answer
2) Your company assigns you to work on a JavaScript project. With the DATE object, which of the
following allows you to call a function based on an elapsed time? a) setElapsedTime() b) Timeout()
c) setTimeout() d) setTime() - correct answer
3) You are working on a JavaScript project. What is used to restart the inner most loop? a) Abort
b) Breakloop c) Stop d) Continue label - correct answer
4) You work on a JavaScript project. Which of the following correctly describe the relationships of
JavaScript and "objects"? a) JavaScript is Object-oriented b) JavaScript is Object-based - correct
answer c) JavaScript is Object-driven d) JavaScript has no relationship with objects
5) You work on a JavaScript project. How do you prompt users with messages and at the same time
requesting user inputs? a) Alert() b) Display() c) Prompt() - correct answer d) Confirm()
6) Which of the following is the correct syntax of FOR? a) for ( increment; initialize; test) b) for
( initialize; test), increment c) for ( initialize; test; increment) - correct answer d) for ( test; initalize;
increment)
67
7) In your JavaScript code, how do you find out which character occurs at the 5th position in a string
"How are you"? a) Substring() b) String() c) Stringlength() d) CharAt() - correct answer
8) Which of the following do you use for a multi-way branch? a) If b) Ifthen c) Ifelse d)
switch - correct answer e) for
9) You want to design a form validation mechanism. Using string methods, which of the following are
the steps involved ? a) Check for the presence of certain characters b) Check the position of substrings
c) Test the length of data d) Check the variable type of the strings e) Either ABC - correct answer
10) Which of the following is the minimum browser version that supports JavaScript a) Navigator
v2.0 - correct answer b) Mozilla V1.5 c) IE 2.0 d) Navigator V1.0
11) Under which of the following conditions will you need to include semi colons on a line of code?
a) When you have multiple statements on multiple lines b) When you have multiple statements on a line -
correct answer c) When you have single statement on multiple lines d) When you have single statement on
a line
12) Which of the following are the valid JavaScript versions? a) Version 1.2 b) Version 1.1 c)
Version 1.3 d) Version 1.4 e) All of the above - correct answer
13) Which of the following languages will you consider as being similar to JavaScript? a) C b)
C++ c) Pascal d) PHP e) Either A & C - correct answer
14) You plan the coding of your project. When must the object references be ready? a) at run time -
correct answer b) at compile time c) at debug time d) at code time
15) Which of the following correctly describe cookies ? a) Often referred to as "persistent cookies"
b) Often referred to as "persistent HTML" c) Small memory-resident pieces of information sent from a server to
the client d) Small memory-resident pieces of information sent from a client to the server e) Either AB&C -
correct answer
17) What are JavaScript relations with the underlying operating platform? a) Platform dependent
b) Platform linkage c) Platform independent - correct answer d) Platform binding
18) When you plan for the JavaScript variable names, the first character must be? a) Underscore
b) Comma c) Hyphen d) Letter e) Either A&D - correct answer
19) Which of the following correctly describe JavaScript as a language? a) It is based on object
creation b) It focuses on component building c) It focuses on logic flow d) It emphasis on
SCRIPTING - correct answer
20) When authoring web page with Javascript, why should you explicitly include the window object
into your codes? a) this is a good practice - correct answer b) this is REQUIRED c) this ensures
browser compatibility d) this ensures OS compatibility
JAVA
68
1) What is the size of a Char? a) 4 bits b) 7 bits c) 8 bits d) 16 bits - correct answer
3) Following code will result in: int a = 3.5; a) Compilation error - correct answer b) Runtime error
c) a being 3.5 d) a being 3.
4) Following code will result in: int a1 = 5; double a2 = (float)a1; a) Compilation error b)
Runtime error c) No errors - correct answer
5) Following code will result in: int a = 9/0; a) Compilation error: Divisions must be in a try block. b)
Compilation error: DivideByZeroException c) Runtime Exception - correct answer d) No Error: a is NaN
6) Following code will result in: float a = 9/0; a) Compilation error: Divisions must be in a try block
b) Compilation error: DivideByZeroException c) Runtime Exception - correct answer d) No Error: a is NaN
8) Following code will result in: class A { int b = 1; public static void main(String [] args)
{ System.out.println("b is " + b); }} a) Compilation error - correct answer b) Runtime Error c)
Runtime Exception d) Output of b is 1
9) Following code will result in: class A { public static void main(String [] args) {B b = new A(); }}
class B extends A {} a) Compile error - correct answer b) Runtime Exception c) No error
10) Following code will result in: class A { public static void main(String [] args) {A a = new B(); }}
class B extends A {} a) Compiler error b) Runtime Exception c) No errors - correct answer
11) Methods that are marked protected can be called in any subclass of that class. a) True - correct
answer b) False
12) An abstract class can have non-abstract methods. a) True - correct answer b) False
13) Java keywords are written in lowercase as well as uppercase. a) True b) False - correct answer
14) What is an instanceof a) A methods in object b) An operator and keyword - correct answer
15) Primitive datatypes are allocated on a stack. a) True - correct answer b) False
17) If class A implements an interface does it need to implement all methods of that interface? a)
Yes, always. b) No, not when A is abstract - correct answer
18) Integer a = new Integer(2); Integer b = new Integer(2); What happens when you do if (a==b)?
a) Compiler error b) Runtime Exception c) True d) False - correct answer
19) The methods wait(), notify() and notifyAll() in Object need to be called from synchronized pieces
of code. a) True - correct answer b) False
69
20) Inner classes can be defined within methods. a) True - correct answer b) False
21) Synchronized is a keyword to tell a Thread to grab an Object lock before continuing execution.
a) True - correct answer b) False
22) The default statement of a switch is always executed. a) True b) False - correct answer
23) How can you prevent a member variable from becoming serialized? a) By marking it private
b) By marking it volatile c) By marking it transient - correct answer d) You can not.
70