Professional Documents
Culture Documents
Version 8.0
310 - 080
Section A
QUESTION NO: 1 Given: 1. public class ServletTest extends HttpServlet{ 2. public
void goGet( 3. HttpServletRequest request 4. HttpServletResponse response) 5.
throws ServletException, IOException 6. { 7. String message = *In doGet*; 8. 9. }
10. } Which two, inserted individually at line 8, will each place an entry in the
servlet log file? (Choose two) A. B. C. D. E. F. log(message);
request.log(message); getServletInfo().log(message);
getServletConfig().log(message); getServletContext().log(message);
request.getSession().log(message);
Answer: A. E
QUESTION NO: 3 In a JSP custom tag, which method would you use to access the JSP
implicit variable that references the application scope? A. B. C. D.
PageContext.getOut() JspFactory.getPagetContext() TagSupport.getValue(String)
PageContext.getServletContext()
Answer: D
QUESTION NO: 4 Which method is used to retrieve objects from an HTTP session? A.
getAttribute method of javax.servlet.Session B. getAttribute method of
javax.servlet.HttpSession C. getAttribute method of javax.servlet.http.Session D.
getAttribute method of javax.servlet.http.HttpSession Answer: D
QUESTION NO: 5 Which method is used by a servlet to place its session ID in a URL
that is written to the servlet’s response output stream? A. B. C. D. The encodeURL
method of the HttpServletRequest interface. The encodeURL method of the
HttpServletResponse interface. The rewriteURL method of the HttpServletRequest
interface. The rewriteURL method of the HttpServletResponse interface.
Answer: B
QUESTION NO: 7 Which statement is true? A. A try statement must have at least one
corresponding catch block. B. Multiple catch statements can catch the same class
of exception more than once. C. An Error that might be thrown in a method must be
declared as thrown by that method, or be handled within that method. D. Except in
case of VM shutdown, if a try block starts to execute, a corresponding finally
block will always start to execute. E. Except in case of VM shutdown, if a try
block starts to execute, a corresponding finally block must always run to
completion. Answer: D
Answer: D
QUESTION NO: 9 When a session becomes invalid, which method will be invoked on a
session attribute object that implements the corresponding interface? A. B. C. D.
sessionDestroyed of the HttpSessionListener interface valyeUnbound of the
HttpSessionBindingListener interface attributeRemoved of the
HtppSessionAttributeListener interface sessionWillPassivate of the
HttpSessionActivationListener interface Leading the way in IT testing and
certification tools, www.testking.com -5-
310 - 080
Answer: B
Answer: B, G
QUESTION NO: 11 Which statement is true about assertions in the Java programming
language? A. B. C. D. Assertion expressions should not contain side effects.
Assertion expression values can be any primitive type. Assertions should be used
for enforcing preconditions on public methods. An AssertionError throws as result
of a failed assertion should always be handled by the enclosing method.
Answer: A
QUESTION NO: 12 Which JSP directive declares a tag library used by the page?
Answer: taglib
QUESTION NO: 13 Given a tag library with the following tags: • A tag called
getTestKing that has one attribute called hierarchy that accepts a dynamic value.
Leading the way in IT testing and certification tools, www.testking.com -6-
310 - 080 • A tag called getChapter that has one attribute called num.
Which three options are valid of these custom tags in a JSP page? (Choose three)
A. B. C. D. <mT:getTestKing hierarchy=”vol1,chap1”/> <mT:getTestKing
hierarchy=”<mT:getChapter num=1/>”/> <mT:getTestKing hierarchy=’<mT:getChapter
num=”1”/>’/> <%String chapter = “chap1”;%> <mT:getTestKing
hierarchy=<%=chapter%>/> E. <%String chapter=”chap1”;%> <mT:getTestKing
hierarchy”<%=chapter%>”/>
Answer: A, C, E
Answer: B, C
QUESTION NO: 15 Which TagSupport method can access any outer tag handler object?
A. B. C. D. getParent findAncenstor getParentWithClass findAncenstorWithClass
Answer: D
QUESTION NO: 16 Within a Web application deployment descriptor, what is the name
of an element that can contain an <error-page> element?
Answer: B
QUESTION NO: 17 Which four constants describe the attributes of a JSP custom tag
in a tag library descriptor? (Choose four) A. B. C. D. E. F. G. Name Type Required
Name-given Short-name Rtexprvalue Display-name
Answer: A, B, C, F
Answer: B
Answer: A
QUESTION NO: 20 How many times can the doAfterBody method be called when
processing a custom tag handle in a JSP page? A. B. C. D. Only one Zero or one One
or more Zero or more
Answer: D
QUESTION NO: 21 Which is true of all servlets? A. If the service method is over-
ridden, its definition must include the synchronized modifier. B. Every instance
of the servlet has access to a thread-safe ServletContext Object. C. The servlet
container may maintain a pool of multiple servlet objects for a given servlet
instance. D. The developer has responsibility for synchronizing access to session
attributes across multiple concurrent requests. Answer: D
QUESTION NO: 22
QUESTION NO: 23 You are designing a Web application to guise users through a
problem-solving process. All the information about the problems, and their
solutions, will be stored in a database. The application will use a central
controller to: • Dispatch requests to the appropriate JSP page. • Manage the
workflow process across pages. • Load the behavior of the controller dynamically
for flexibility. Which design pattern is intended to achieve these goals? A. B. C.
D. Front Component Data Access Object Mode-View-Controller Session Entity Façade
Answer: A
Answer: B, F
QUESTION NO: 26 Given: 11. public class Acc extends HttpServlet{ 12. private
StringBuffer bar = new StringBuffer(“bar”); 13. private static StringBuffer xyz =
new StringBuffer(); 14. public void doPost(HttpServletRequest req,
HttpServletResponse resp){ 15 StringBuffer testking = new
StringBuffer(“testking”); 16. HttpSession session = req.getSession(); 17. } 18. }
Which two variables reference objects that are thread-safe? (Choose two) A. B. C.
D. E. req at line 14 testking at line 15 bar at line 12 xyz at line 13 session at
line 16
Answer: A, B
QUESTION NO: 27 Which two are benefits of the Value Object design patterns for
implementing Web applications? (Choose two) A. B. C. D. E. It improves response
time for accessing data. It separates business logic from presentation logic. It
can greatly reduce network traffic for accessing data. It separates resource
interface from resource implementation. It allows software developers and page
authors to work in parallel with few dependencies.
Answer: A, C
QUESTION NO: 28 You are designing a large, complex Web application that will be
structured in a multi-tier architecture. You must provide interfaces based on both
HTML and XML. The application must be maintainable over many development and
deployment iterations. Which design pattern is intended to achieve these goals? A.
Remote Proxy B. Business Delegate C. Bimodal Data Access Leading the way in IT
testing and certification tools, www.testking.com - 12 -
310 - 080 D. Model-View-Controller Answer: D
QUESTION NO: 29 Within a Web application deployment descriptor, what is the name
of the child element of <context-param> that describes a parameter? A. B. C. D. E.
F. desc usage param-desc description param-usage param-description
Answer: D
QUESTION NO: 30 Which two are true about the basic HTTP authentication mechanism?
(Choose two) A. B. C. D. An HTML form is used to collect username and passphrase.
The username and passphrase information is passed “in the clear”. The username and
passphrase information is passed in an encryption form. The Web browser uses a
browser-specific mechanism to collect username and passphrase.
Answer: B, D
Answer: D
QUESTION NO: 32 Which deployment description snippet would you use to declare the
use of a tag library? A. 7. 8. 9. 10. B. 7. 9. 10. 11. C. 7. 9. 10. 11. D. 7. 8.
9. 10. Answer: B <taglib> <uri>http://testking.com/taglib.tld</uri>
<location>/WEB-INF/taglib.tld</location> </taglib> <taglib> <taglib-
uri>http://testking.com/tablib.tld</taglib-uri> <taglib-location>/WEB-
INF/tablib.tld</taglib-location> </taglib> <tag-lib>
<uri>http://testking.com/taglib.tld</uri> <location>/WEB-INF/taglib.tld</location>
</tag-lib> <tag-lib> <taglib-uri>http://testking.com/taglib.tld</taglib-uri>
<taglib-location>/WEB-INF/taglib.tld</taglib-location> </tag-lib>
QUESTION NO: 34 Given that a custom tag is meant to be used without a body, which
value would you use in the body-content element? Answer: empty
Answer: A
Answer: D
Answer: A. C
Answer: B
QUESTION NO: 40 Many programmers write classes for use in your customer’s systems.
Programmers are granted authority to write classes for general use by the IT
department. Each programmer supplies a certificate along with their classes. The
certificate is intended to identify the author of the classes, and validate the
“authority to write” of that programmer. Which three items form a minimum criteria
set that will allow users (or their systems) to validate that the “authority to
write” has been granted to a given set of classes? (Choose three) A. The classes
should be loaded using HTTPS. B. The programmer’s certificate should be self-
signed. Leading the way in IT testing and certification tools, www.testking.com -
16 -
310 - 080 C. The classes should be deployed from a trusted host. D. The
programmer’s certificate should be signed by the IT department management. E.
Programmers should distribute their classes in jarfiles signed using the key
represented by their certificates. F. The certificate of the IT department
management should be installed as a trusted certificate in the keystore database
of each user. G. The certificate of the programmer should be installed as a
trusted certificate in the keystore database for each user. Answer: D, E, F
Answer: A
Answer: B
Answer: A
QUESTION NO: 46 Which XML tag may be used to specify the JSP page directive? A. B.
C. D. E. <jsp /> <page /> <jsp.page /> <jsp:page /> <jsp:directive.page />
Answer: E
Answer: C
QUESTION NO: 51 Which two are true about Web application archive files? (Choose
two) A. B. C. D. They must NOT be signed. They may contain JAR files. They must
have a “.web” extension. They may serve files from the META-INF directory. Leading
the way in IT testing and certification tools, www.testking.com - 21 -
310 - 080 E. They may contain JSP files in addition to HTML files. F. They CANNOT
define their dependencies in the manifest.mf file. Answer: B, D
QUESTION NO: 52 Given that the deployment descriptor for a Web application named
test contains: 12. <servlet-mapping> 13. <servlet-name>testking</servlet-name> 14.
<url-pattern>*.bop</url-pattern> 15. </servlet-mapping> Which will invoke the
servlet instance named testking? A. B. C. D. E. http://servername/test.bop
http://servername/testking/bar.bop http://servername/test/testking/bop
http://servername/baz/bat/boo.bop http://servername/test/testking/bar/baz.hop
Answer: A
QUESTION NO: 53 Where must the class file for TestKingServlet be located? A. B. C.
D. E. test/WEB-INF/TestKingServlet.class
test/classes/com/testcorp/TestKingServlet.class
test/classes/com.testcorp.TestKingServlet.class
test/webapp/classes/com.testcorp.TestKingServlet.class test/WEB-
INF/classes/com/testcorp/TestKingServlet.class
Answer: E
Answer: D
QUESTION NO: 55 Which two methods of HttpServletResponse will allow an HTTP header
to be set in the response? (Choose two) A. B. C. D. setHeader SetHeaders
SetDataHeader SetHeaderValue
Answer: A, C
QUESTION NO: 56 You are developing a servlet to generate a GIF image stream:
Given: 12. response.setContentType(“image/gif”); 13. 14. // Write image to out.
15. out.close(); Which, inserted at line 13, will initialize the out variable? A.
B. C. D. PrintWriter out = response.getWriter(); PrintWriter out =
response.GetOutputStream(); OutputStream out = response.getOutputStream();
ServeletOutputStream out = response.getServletOutput();
Answer: A
QUESTION NO: 57 Place the steps of a JSP life cycle in the correct order.
Answer: Page translation JSP compilation Load class create instance call jspInit
call _jspService call jspDestroy
QUESTION NO: 58 Which method in HttpServlet, apart from service, handles an HTTP
GET request? Note: Type only the same of the method, without parameters. The
answer is case sensitive. Answer: doGet
QUESTION NO: 59 The service method of a servlet instance is invoked under which
three conditions? (Choose three) A. The servlet instance receives an HTTP GET
request. B. An HTTP POST request is made of the servlet instance. Leading the way
in IT testing and certification tools, www.testking.com - 24 -
310 - 080 C. D. E. F. The servlet instance is activated by the servlet container.
An instance of the servlet is loaded by the servlet container. A browser sends an
HTTP HEAD request to the servlet instance. An instance of the servlet is placed
into service by the servlet container.
Answer: A, B, E
QUESTION NO: 60 Which two are valid arguments for the getRequestDispatcher method
of the ServletContext interface? A. B. C. D. E. /fred.txt error.html /error.html
www.sun.com/error.html http://www.sun.com/error.html
Answer: A, C
QUESTION NO: 61 Which two methods can be used to access static content within a
Web application? (Choose two) A. B. C. D. E. F. getResource of the Webapp
interface. getResource of the HttpServlet class. getResource of the ServletContext
interface. getResourceAsStream of the Webapp interface. getResourceAsStream of the
HttpServlet class. getResourceAsStream of the ServletContext interface.
Answer: C, F
QUESTION NO: 62 Which two are true about the HTTP POST method? (Choose two) A.
POST requests are faster. B. It supports multipart MIME requests. C. Request data
is sent in a separate content block.
QUESTION NO: 63 Which element name in the Web application deployment descriptor is
used to declare that a custom tag library can be used by the JSP pages in that Web
application? A. B. C. D. E. tag taglib tag-lib taglibrary tag-library
Answer: B
QUESTION NO: 64 Given that the http://testking.com/myTags library was declared for
use by this Web application and the JSP code: 1. <html> 2. 3. <h3><x:getTestKing
hierarchy=”vol1,chap2”/></h3> 4. <html> Which would you use in line 2 to permit
the custom tag use on line 3? A. B. C. D. <%@ <%@ <%@ <%@ taglib taglib taglib
taglib uri=”myTags” prefix=”x” %> uri=”myTags” prefix=”x” %>
uri=”http://testking.com/myTags” prefix=”x” %> uri=”http://testking.com/myTags”
prefix=”x” %>
Answer: C
QUESTION NO: 65 Given a tag library with the following tag: a tag called
getTestKing that has one attribute called hierarchy that is not mandatory Which
two options are a valid use of this tag in a JSP page? (Choose two) Leading the
way in IT testing and certification tools, www.testking.com - 26 -
310 - 080
A. B. C. D. E. F.
Answer: D, F
QUESTION NO: 66 Which three constants describe the body content of a JSP custom
tag in a tag library descriptor? (Choose three) A. B. C. D. E. JSP none empty tei-
class tagdependent
Answer: A, C, E
QUESTION NO: 67 What is the meaning of the SKIP_PAGE constant when it is returned
from the doEndTag method? A. B. C. D. SKIP_PAGE is not a valid return value for
the doEndTag method. SKIP_PAGE directs the JSP page to disregard the body of the
custom tag. SKIP_PAGE directs the JSP page to disregard the rest of the JSP page
content. SKIP_PAGE directs the JSP page to disregard any included JSP fragments
from the jsp:include standard action.
Answer: C
QUESTION NO: 68 Given: 1. <html> 2. <body> 3. <% Leading the way in IT testing and
certification tools, www.testking.com - 27 -
310 - 080 4. 5. 6. 7. 8. 9. for(int i = 0; 1 < 10; i++) { } %> </body> </html>
Which can appear at line 5 without causing an error? A. B. C. D. <%= i %> <b>i</b>
%><%= i %><% <h1>Hello</h1>
Answer: C
Answer: D
QUESTION NO: 70 Given a tag that iterates over a set of values, which static value
from the javax.servlet.jsp.tagext.Tag interface must be returned from the
doAfterBody method to end the iteration? Note: Do not specify the interface name
in your response. Answer: SKIP_BODY Leading the way in IT testing and
certification tools, www.testking.com - 28 -
310 - 080
QUESTION NO: 71 Which tag library descriptor element name identifies the type of
body content for a JSP custom tag? A. B. C. D. JSP Body content body-content
Answer: D
Answer: A
QUESTION NO: 73 What is the name of the tag library descriptor element that
declares the name of a tag? Answer: name
Answer: A
Answer: D
Assume xyz and servlet abc are in the webapp Web application. Further assume you
are using a browser with ALL cookies disabled and you submit an HTTP GET request
to abc. Which is true regarding the result of pressing the “Submit to XYZ” button
on the page generated by abc? A. B. C. D. “<h1></h1>” is returned in xyz’s
generated response. An exception is thrown at line 5 of xyz’s doPost method.
“<h1>ABC</h1>” is returned in xyz’s generated response. “<h1>null</h1>” is
returned in xyz’s generated response.
QUESTION NO: 77 Which interface must a class implement so that instances of that
class will be notifies when they are added as attributes of an HTTP session? A. B.
C. D. java.util.EventListener javax.servlet.http.HttpSessionListener
javax.servlet.http.HttpSessionValueListener
javax.servlet.http.HttpSessionBindingListener
Answer: D
QUESTION NO: 78 Given: 11. public class TestKing extends HttpServlet { 12. public
void doPost(HttpServletRequest req, HttpServletResponse resp) { 13. 14. } 15. }
Assume that no other servlets participating in the same session as servlet
TestKing explicitly invalidate the session. Which, inserted at line 13, will
ensure that the session remains valid for at least six minutes? A. B. C. D. E.
req.getSession().setTimeout(6); req.getSession().setTimeout(360); Nothing can be
inserted to ensure the given condition.
req.getSession().setMaxInactiveInterval(6);
req.getSession().setMaxInactiveInterval(360);
Answer: E
QUESTION NO: 79 Which declares the current JSP page to be an error page? A. B. C.
D. <%@ <%@ <%@ <%@ page page page page info=”error” %> errorPage=”true” %>
isErrorPage=”true” %> pageEndcoding=”error” %>
QUESTION NO: 80 Given: 11. public class Acc1 extends HttpServley implements
SingleThreadModel { 12. private StringBuffer bar = new StringBuffer(“bar”); 13.
private static StringBuffer xyz = new StringBuffer(); 14. public void
doPost(HttpServletRequest req, HttpServletResponse resp) { 15. StringBuffer
testking = new StringBuffer(“testking”); 16. HttpSession session =
req.getSession(): 17. } 18. } Which three variables reference objects that are
thread-safe? (Choose three) A. B. C. D. E. bar at line 12. xyz at line 13.
testking at line 15. req at line 14. session at line 16.
Answer: A, D, E
QUESTION NO: 84 Which J2EE design pattern unifies and simplifies workflow by
interpreting user request and dispatching screen from a single point? A. B. C. D.
E. Value Object Front Component Data Access Object Model-View-Controller Session
Entity Façade
Answer: D (or B)
Answer: E
QUESTION NO: 86 Which J2EE design pattern provides flexible, extensible access to
data and other resources? A. B. C. D. E. Value Object Front Component Data Access
Object Bimodal Data Access Session Entity Façade
Answer: C
Answer: E
Answer: A, E
QUESTION NO: 89 Which two represent valid JSP expressions? (Choose two) A. B. C.
D. E. F. <% x %> <%= Match.random() %> <%= “TESTKING” + “EXAMINATOR” %> <%=
Match.random(); %> <% int x = “4” + “2”; %> <% String x = “4” + “2” %>
Answer: B, C
Answer: A
QUESTION NO: 93 Given this fragment from a Web application deployment descriptor?
12. <context-param> 13. <param-name>user</param-name> 14. <param-
value>tessking</param-value> 15. </context-param> From within a servlet’s doPost
method, which retrieves the value of the user parameter? A. B. C. D.
getServletConfig().getAttribute(“user”); getServletContext().getAttribute(“user”);
getServletConfig().getInitParameter(“user”);
getServletContext().getInitParameter(“user”);
Answer: D
Which would you use in the abc.jsp fragment to produce the HTML response?
<h3>Registration Form</h3> A. B. C. D. <h3><jsp:getParam name=”subTitle”/></h3>
<h3><jsp:include param=”subTitle”/></h3> <h3><%= request.getParameter(“subTitle”)
%></h3> <h3><%= request.getAttribute(“subTitle”) %></h3>
Answer: C
Answer: A
QUESTION NO: 97 Which two API techniques can be used to get the name of an
authenticated user? (Choose two) A. Use the getUser on the HTTP servlet request
object. B. Use the getUserName on the HTTP servlet request object. Leading the way
in IT testing and certification tools, www.testking.com - 39 -
310 - 080 C. Use the getRemoteUser on the HTTP servlet request object. D. Retrieve
the principal object from the HTTP servlet request object using getUser and use
the getName on the principal object. E. Retrieve the principal object from the
HTTP servlet request object using getPricipal and use the getName on the principal
object. Answer: C, E
QUESTION NO: 98 Which deployment descriptor elements are used to configure Web
services for authorization? A. B. C. D. security-constraint, login-form, realm-
name security-constraint, login-config, security-role web-resource-constraint,
login-form, security-role web-resource-constraint, login-config, security-role
Answer: A
Answer: C
QUESTION NO: 100 Which will print the value of the Accept-Charset HTTP header in a
JSP page? A. B. C. D. <%= <%= <%= <%= headers.get(“Accept-Charset”) %>
page.getHeader(“Accept-Charset”) %> headers.getValue(“Accept-Charset”) %>
request.getHeader(“Accept-Charset”) %>
Answer: D
QUESTION NO: 101 Which includes a file in a JSP page at request time? A. B. C. D.
E. <%@ include file=”testking.html” %> <%@ include page=”testking.html” %> <%@
page include=”testking.html” %> <jsp:include file=”testking.html” /> <jsp:include
page=”testking.html” flush=”true” />
Answer: E
QUESTION NO: 102 Which two set the content type of a JSP page? (Choose two) A. B.
C. D. E. F. <%@ contentType “text/plain” %> <jsp:contentType “text/plain”> <%@
page contentType=”text/plain” %> <% session.setContentType(“text/plain”); %> <%
request.setContentType(“text/plain”); %> <% response.setContentType(“text/plain”);
%>
Answer: C, F
QUESTION NO: 103 Which attribute and value of the jsp:setProperty action causes a
JSP page to iterate over all ServletRequest parameters and assign values of the
corresponding properties in a JavaBean? Note: Type the attribute and value exactly
as they would appear within the jsp:setProperty element. Do not type any other
part of the jsp:setProperty element. Answer: property="*"
Section B
QUESTION NO: 1 Given: 11. public void testking(boolean a, boolean b){ 12. if(a){
13. System.out.println(“A”); 14. }else if(a&&b){ 15. System.out.println(“A&&B”);
16. }else{ 17. if( !b ){ 18. System.out.println(“notB”); 19. }else{ 20.
System.out.println(“ELSE”); 21. } 22. } 23. } What is correct? A. B. C. D. If a is
true and b is true then the output is “A&&B”. If a is true and be is false then
the output is “notB”. If a is false and be is true then the output is “ELSE”. If a
is false and b is false then the output is “ELSE”.
Answer: C
QUESTION NO: 2 Given: 11. public class Test{ 12. public void testking(){ 13.
assert false; 14. assert false; 15. } 16. public void bar(){ 17. while(true){ 18.
assert false; 19. } 20. assert false; 21. } 22. } What causes compilation to fail?
A. Line 13 Leading the way in IT testing and certification tools, www.testking.com
- 42 -
310 - 080 B. Line 14 C. Line 18 D. Line 20 Answer: D
Answer: E
Answer: C
QUESTION NO: 6 Given: 11. try{ 12. int x=0; 13. int y=5/x; 14. }catch(Exception
c){ 15. System.out.println(“Exception”); 16. }catch(ArithmeticException ac){ 17.
System.out.println(“Arithmetic Exception”); 18. } 19.
System.out.println(“finished”); What is the result? A. B. C. D. finished Exception
Compilation fails. Arithmetic Exception
Answer: C
QUESTION NO: 7 Given: 10. public Object m(){ Leading the way in IT testing and
certification tools, www.testking.com - 44 -
310 - 080 11. Object o=new Float(3.14F); 12. Object[]oa=new Object[1]; 13.
ao[0]=o; 14. o=null; 15. oa[0]=null; 16. return o; 17. } When is the Float object,
created in line 11, eligible for garbage collection? A. B. C. D. Just after line
13. Just after line 14. Just after line 15. Just after line 16(that is, as the
method returns).
Answer: C
QUESTION NO: 8 Given: 1. class Test{ 2. private Demo d; 3. void start(){ 4. d=new
Demo(); 5. this.takeDemo(d); 6. } 7. 8. void takeDemo(Demo demo){ 9. demo=null;
10. demo=new Demo(); 11. } 12. } When is the Demo object created on line 4,
eligible for garbage collection? A. B. C. D. E. After line 5. After line 9. After
the start() method completes. When the takeDemo() method completes. When the
instance running this code is made eligible for garbage collection.
Answer: E
QUESTION NO: 9 Given: 11. Float f=new Float(“12”); Leading the way in IT testing
and certification tools, www.testking.com - 45 -
310 - 080 12. switch(f){ 13. case 12:System.out.println(“Twelve”); 14. case
0:System.out.println(“Zero”); 15. default: System.out.println(“Default”); 16. }
What is the result? A. B. C. D. Zero Twelve Default Twelve Zero Default E.
Compilation fails. Answer: E
QUESTION NO: 10 Which four can be thrown using the show statement? (Choose four)
A. B. C. D. E. F. Error Event Object Throwable Exception RuntimeException
Answer: A, D, E, F
QUESTION NO: 11 Which statement is true? A. B. C. D. E. Programs will not run out
of memory. Objects that will never again be used are eligible for garbage
collection. Objects that are referred to by other objects will never be garbage
collected. Objects that can be reached from a live thread will never be garbage
collected. Objects are garbage collected immediately after the system recognizes
they are eligible.
Answer: D
Answer: B
QUESTION NO: 13 Given: 11. public void test(int x){ 12. int odd=x%2; 13. if(odd){
14. System.out.println(“odd”); 15. }else{ 16. System.out.println(“even”); 17. }
18. } What statement is true? A. B. C. D. E. Compilation fails. “odd” will always
be output. “even” will always be output. “odd” will be output for add values of x,
and “even” for even values. “even” will be output for add values of x, and “odd”
for even values.
Answer: A
Answer: B
QUESTION NO: 15 Which item provides tools to allow the formatting of currency and
date information according to local conventions? A. B. C. D. E. java.text package
java.util.Locale class java.lang.String class Pluggable look and feel in Swing.
Readers and Writers in the java.io package.
Answer: A
Answer: B
Answer: D
QUESTION NO: 19 Given: 20. public float getSalary(Employee c){ 21. assert
validEmployee(c); 22. float sal=lookupSalary(c); 23. assert (sal>0); 24. return
sal; 25. } 26. private int getAge(Employee c){ 27. assert validEmployee(c); 28.
int age=lookupAge(c); 29. assert (age>0); 30. return age; 31. } Which line is a
violation of appropriate use of the assertion mechanism? A. B. C. D. Line 21 Line
23 Line 27 Line 29
Answer: A
Answer: B
Answer: B
Answer: C
QUESTION NO: 24 Given: 11. int i=0,j=5; 12. tp:for(;;){ 13. i++; Leading the way
in IT testing and certification tools, www.testking.com - 52 -
310 - 080 14. for(;;){ 15. if(i>--j){ 16. break tp; 17. } 18. } 19. } 20.
System.out.println(“i=”+”,j=”+j); What is the result? A. B. C. D. E. i=1, j=0 i=1,
j=4 i=3, j=4 i=3, j=0 Compilation fails.
Answer: A
QUESTION NO: 26 Given: 1. class Bar{} 1. class Test{ Leading the way in IT testing
and certification tools, www.testking.com - 53 -
310 - 080 2. Bar doBar(){ 3. Bar b=new Bar(); 4. return b; 5. } 6. public static
void main(String args[]){ 7. Test t=new test(); 8. Bar newBar=t.doBar(); 9.
System.out.println(“newBar”); 10. newBar=new Bar(); 11.
System.out.println(“finishing”); 12. } 13. } At what point is the Bar object,
created on line 3, eligible for garbage collection? A. B. C. D. After line 8.
After line 10. After line4, when doBar() completes. After line 11, when main()
completes.
Answer: B
Answer: C
QUESTION NO: 28 Given: 11. int i=1,j=10; 12. do{ 13. if(i>j){ Leading the way in
IT testing and certification tools, www.testking.com - 54 -
310 - 080 14. continue; 15. } 16. j--; 17. }while(++i<6); 18.
System.out.println(“i=”+i+”and j=”+j); What is the result? A. B. C. D. E. i=6 and
j=5 i=5 and j=5 i=6 and j=4 i=5 and j=6 i=6 and j=6
Answer: A
QUESTION NO: 29 Given: 11. public static void main(String[]args){ 12. Object
obj=new Object(){ 13. public int hashCode(){ 14. return 42; 15. } 16. } 17.
System.out.println(obj.hashCode()); 18. } What is the result? A. B. C. D. E. 42 An
exception is thrown at runtime. Compilation fails because of an error on line 12.
Compilation fails because of an error on line 16. Compilation fails because of an
error on line 17.
Answer: D
QUESTION NO: 30 Given: 11. int i=0; 12. while(1){ 13. if(i==4){ 14. break; 15. }
16. ++i; Leading the way in IT testing and certification tools, www.testking.com -
55 -
310 - 080 17. } 18. System.out.println(“i=”+i); What is the result? A. B. C. D. E.
i=0 i=3 i=4 i=5 Compilation fails.
Answer: E
QUESTION NO: 31 Which two are valid declaration within an interface definition?
(Choose two) A. B. C. D. E. void methoda(); public double methoda(); public final
double methoda(); static void methoda(double d1); protected void methoda(double
d1);
Answer: A, B
Answer: C
QUESTION NO: 33 Given: 1. public class Delta{ 2. static boolean testking(char c){
3. System.out.print(c); 4. return true; 5. } 6. public static void
main(String[]argv){ 7. int i=0; 8.
for(testking(‘A’);testking(‘B’)&&(i<2);testking(‘C’)){ 9. i++; 10. testking(‘D’);
12. } 13. } 14. } What is the result? A. B. C. D. ABDCBDCB ABCDABCD Compilation
fails. An exception is thrown at runtime.
Answer: A
Answer: B, D
Answer: C
Answer: C
QUESTION NO: 37 Given: 11. int i=1,j=10; 12. do{ 13. if(i++>--j){ 14. continue;
15. } 16. }while(i<5); 17. System.out.println(“i=”+i+”and j=”+j); What is the
result? A. B. C. D. E. i=6 i=5 i=6 i=5 i=6 and and and and and j=5 j=5 j=4 j=6 j=6
Answer: D
QUESTION NO: 38 Given: 1. class Exc0 extends Exception{} 2. class Exc1 extends
Exc0{} 3. public class Test{ 4. public static void main(String args[]){ 5. try{ 6.
throw new Exc1(); 7. }catch(Exc0 c0){ 8. System.out.println(“Ex0 caught”); 9. }
catch(Exception c){ 10. System.out.println(“exception caught”); 11. } Leading the
way in IT testing and certification tools, www.testking.com - 59 -
310 - 080 12. } 13. } What is the result? A. B. C. D. Ex0 caught exception caught
Compilation fails because of an error at line 2. Compilation fails because of an
error at line 6.
Answer: A
Answer: A
QUESTION NO: 40 Given: 11. int x=1,y=6; 12. while(y--){ 13. x++; 14. } 15.
System.out.println(“x=”+x+”y=”+y); What is the result? A. B. C. D. E. x=6 y=0. x=7
y=0. x=6 y=-1. x=7 y=-1. Compilation fails.
Answer: E
Answer: D
QUESTION NO: 42 Given: 1. public class Test{ 2. public static void main(Strings
args[]){ 3. int i= 1,j=0; 4. switch(i){ 5. case2:j+=6; 6. case4:j+=1;
7.default:j+=2; 8. case 0;j+=4; 9. } 10. System.Out.Println(“j=”+j); 11. } 12. }
What is the result? A. B. C. D. E. F. 0 2 4 6 9 13
Answer: D
Answer: C
Answer: B
QUESTION NO: 45 Given: 1. public class Test{ 2. public static String output=””; 3.
4. public static void testking(int i){ 5. try{ 6. if(i==1){ 7. throw new
Exception(); 8. } 9. output +=”1”; 10. } 11. catch(Exception e){ 12. output+=”2”;
13. return; 14. } 15. finally{ 16. output+=”3”; 17. } 18. output+=”4”; 19. } 20.
21. public static void main(String args[]){ 22. testking(0); 23. testking(1); 24.
25.} 26.} What is the value of the variable output at line 23? Answer: 13423
Answer: A
QUESTION NO: 48 Given: Leading the way in IT testing and certification tools,
www.testking.com - 64 -
310 - 080 11. int i=1,j=10; 12. do{ 13. if(i>j){ 14. break; 15. } 16. j--; 17. }
while(++i<5); 18. System.Out.println(“i=”+i+”and j=”+j); What is the result? A. B.
C. D. E. i=6 i=5 i=6 i=5 i=6 and and and and and j=5 j=5 j=4 j=6 j=6
Answer: D
Answer: E
Answer: C
Answer: A
Answer: C, D
Answer: C
Answer: B
QUESTION NO: 55 Given: 1. public class Test{ 2. public static void aMethod()throws
Exception{ 3. try{ 4. throw new Exception(); 5. }finally{ 6.
System.out.println(“finally”); 7. } 8. } 9. public static void main(Strings
args[]){ 10.try{ 11. aMethod(); Leading the way in IT testing and certification
tools, www.testking.com - 68 -
310 - 080 12. }catch(Exception c){ 13. System.out.println(“exception”); 14. } 15.
System.out.println(“finished”); 16. } 17. } What is the result? A. finally B.
exception finished C. finally exception finished D. Compilation fails. Answer: C
QUESTION NO: 56 Given: 10. public Object m(){ 11. Object o=new Float(3.14.F); 12.
Object[]oa=new Object[1]; 13. oa[0]o; 14. 0=null; 15. return oa[0]; 16. } When is
the Float object, created in line 11, eligible for garbage collection? A. B. C. D.
Just after line 13 Just after line 14. Never in this method. Just after line
15(that is, as the method returns).
Answer: C
Answer: A
QUESTION NO: 58 Given: 11. int i=1,j=-1; 12. switch(i){ 13. case 0,1:j=1; 14. case
2;j=2; 15. default:j=0; 16. } 17. System.out.println(“j=”+j); What is the result?
A. B. C. D. E. j=-1 j=0 j=1 j=2 Compilation fails.
Answer: E
Answer: F
Note: Section A contains 103 questions. Section B contains 59 questions. The total
number of questions is 162.