Friday, April 29, 2011

SCWCD Mock Exam 1

This chapter is the first of our 2 practice Exams. It contains 60 Questions and you can take upto 90 minutes to answer all of them.

Remember that the exam contains the same number of Questions ‘60’ and you will be given the same 90 minutes only. So, make sure you time yourself and don't use more than the allotted time.

Questions:

Question 1:

Regarding a typical HTTP request/response cycle, which of the following places the described events in their proper order? (Choose two.)
A. The Web browser makes an HTTP request, the Web server receives the request, and the Web server hands off the request to the servlet container.
B. A client responds to a servlet validation ping, Web server receives the request, and the Web server hands off the request to the servlet container.
C. The servlet container receives a request. The container reads the configuration (web.xml), and then calls the appropriate servlet.
D. The servlet polls the request object to find out what to do, the servlet performs its logic, and then sends data back to the client via the response object.

Question 2:

Which of the following are true about JSP comments? (Choose two.)
A. The JSP syntax is < % - - comment - - % >
B. The JSP syntax is < ! - - comment - - >
C. The XML syntax is < jsp: comment >< /jsp: comment >
D. They document the JSP page but is not inserted into the response.

Question 3:

Servlets are a required API of which Java 2 platform?
A. J2ME
B. J2SE
C. J2EE
D. J2DE

Question 4:

Which of following methods represents the servlet life cycle described in the API? (Choose three.)
A. init
B. start
C. service
D. destroy
E. getServletInfo

Question 5:

Which two of the following are true regarding the container initializing a servlet before it can handle requests from clients? (choose two)
A. The container calls the init method.
B. The container calls the service method.
C. This is how you can keep track of request activities.
D. This is how you set up a catch/try block.

Question 6:

During initialization, the servlet instance can throw which exceptions? (Choose two.)
A. ServletUnavailableException
B. UnavailableException
C. ServletNotFoundException
D. ServletException

Question 7:

Which of the following statements regarding the forward method of the RequestDispatcher interface are true?
A. It must be called before the response buffer is full.
B. It can throw an IllegalStateException exception.
C. It requires an absolute path. A relative path won't work.
D. The client must have this feature turned on.

Question 8:

If during initialization, the servlet instance throws an exception, which of the following statements is true regarding the destroy() method?
A. The method is called finalize().
B. The container calls the destroy() method.
C. The container invokes the catch block.
D. The container doesn't call the destroy method after an exception.

Question 9:

Which exceptions can a servlet throw during the service of a request? (Choose two.)
A. RequestException
B. ServletException
C. HttpException
D. UnavailableException

Question 10:

Which two of the following are true about page directives in JSP?
A. They define attributes that apply to an entire JSP page.
B. If a variable is declared it must appear before it used in the JSP.
C. You can declare instance variables with them.
D. There can only be one.

Question 11:

Which two statements are true regarding how the servlet container will keep a servlet loaded? (choose two)
A. A servlet instance may be kept active in a servlet container for the lifetime of the servlet container.
B. When the session ends, the servlet is unloaded.
C. The specification defines a session to have a default timeout of 20 minutes.
D. There is no association between how long a servlet is loaded and the session.

Question 12:

Before the servlet container may destroy a servlet, what must be true?
A. Pending requests are flushed.
B. HttpSession calls finalize().
C. ServletContext calls finalize().
D. Threads that are currently running in the service method of the servlet must complete execution.

Question 13:

Regarding container paths and URL, which of the following equations is always true?
A. requestURI = contextPath + servletPath + pathInfo
B. requestURI = contextPath + pathInfo + servletPath
C. contextPath = requestURI + servletPath + pathInfo
D. servletPath = contextPath + pathInfo

Question 14:

How do you include an outside resource into a JSP page?
A. < jsp: include page="salesTax.jsp" >
this works
< /jsp: include >

B. < jsp: include uri="salesTax.jsp"/ >

C. < jsp: include page="salesTax.jsp" >
< jsp: param name="state" value="CA" / >
< jsp: param name="amount" value="359.92" / >
< /jsp: include >

D. < jsp: include uri="salesTax.jsp" >
< jsp: param name="state" value="CA" / >
< /jsp: include >.

Question 15:

What information does the client send back as part of a cookie?
A. date, location, name, and value
B. name and value
C. location, name, and value
D. server version, date, and SSL status

Question 16:

What is the lifetime of the request object?
A. Until all threads associated with the session are complete.
B. This is container vendor specific.
C. Like garbage collection, exact timing is not specified.
D. It depends on the scope of a servlet's service method.

Question 17:

Which of the following are true about includes in JSP? (Choose two.)
A. There is no such thing.
B. The XML syntax is < jsp: text > < /jsp: text >
C. The JSP syntax is < %@ include file="relativeURL" % >
D. The JSP syntax is < % include("string") % >
E. The included text is added to the JSP page at translation time, when the JSP page is compiled.

Question 18:

What does a servlet container do with buffering? (Choose two.)
A. It is allowed to buffer output going to the client.
B. It is not required to buffer output going to the client.
C. It is required to buffer output going to the client.
D. The container can be configured to buffer in the buffer.xml configuration file.

Question 19:

Which of the following are true about the declarations in JSP? (Choose two.)
A. The JSP syntax is < %@ declaration % >
B. The JSP syntax is: < %! declaration % >
C. The XML syntax is < jsp: declare >< /jsp: declare >
D. The JSP syntax is < % declaration % >.

Question 20:

How do you write a message to the WebApp log?
A. Response.log()
B. ServletContext.log(String)
C. Response.errorLog()
D. ServletContext.logger()

Question 21:

Headers may contain data that represents which data types? (Choose two.)
A. int
B. String
C. Date
D. Object

Question 22:

Using the sendError method has what side effect? (Choose two.)
A. There is no way to catch errors after calling sendError.
B. It automatically calls the destroy method.
C. It commits the response.
D. It terminates the response.

Question 23:

Which two of the following methods terminate the response so that afterward no more output may be added to the response buffer? (choose two)
A. The sendError method.
B. The sendRedirect method.
C. The sendTerminate method.
D. The sendComplete.

Question 24:

Which two of the following are true regarding the Hypertext Transfer Protocol (HTTP)? (choose two)
A. It is a stateful protocol.
B. It is a stateless protocol.
C. Servlets use sockets to make it stateful.
D. Servlets can only handle real connections so it is the container vendor's responsibility to manage this.

Question 25:

Which of the follow are features of URL rewriting?
A. It converts relative to absolute paths.
B. It redirects clients to another URL.
C. It is used for sessions.
D. It appends to a query string.

Question 26:

When is a session considered established?
A. When a client joins it.
B. When you create a cookie on the client.
C. When the client is notified about the session.
D. When the request object is created.

Question 27:

Which of the following methods may be used to send error information back to a client? (Choose two.)
A. HttpServletError.setError()
B. HttpServletResponse.sendError()
C. HttpServletError.sendStatus()
D. HttpServletResponse.setStatus()

Question 28:

What is the correct syntax for assigning a value to a bean's property?
A. < jsp: property name="houseLotBean" property="id" value="33245" / >
B. < jsp: useBean name="houseLotBean" property="id" value="33245" / >
C. < jsp: setProperty name="houseLotBean" property="id" value="33245" / >
D. < jsp: setProperty property="id" value="33245" / >

Question 29:

Any object bound into a session is available to which other servlets?
A. Those servlets that share the same response.
B. Those servlets that have access to HttpSession.
C. Those servlets in the same container.
D. Those servlets that belong to the same ServletContext.

Question 30:

Some objects may require notification when they are placed into, or removed from, a session. This information can be obtained by having the object implement which interface?
A. HttpSessionListener
B. ServletContextListener
C. HttpSessionBindingListener
D. HttpServletResponseListener

Question 31:

When will the life of the session expire? (Choose two.)
A. When you call the expunge() method.
B. When you set the setMaxInactiveInterval to -1.
C. When you call the invalidate() method.
D. When the service method completes.

Question 32:

What are the methods of the RequestDispatcher interface? (Choose two.)
A. include
B. getClient
C. forward
D. back

Question 33:

Using XML syntax, how do you add text to the JSP output stream?
A. < jsp: page text="your text here" / >
B. < jsp: text >
your text
< /jsp: text >

C. < jsp: include param="text" value="your text here"/ >
D. < jsp: text value="text here"/ >

Question 34:

A servlet being used from within an include has access to which of the following? (Choose two.)
A. javax.servlet.include.response_uri
B. javax.servlet.include.context_path
C. javax.servlet.include.servlet_path
D. javax.servlet.include.cookie_info

Question 35:

Which of the following statements is true about how a servlet binds an object attribute into an HttpSession implementation by name?
A. This is determined by the deployment descriptor.
B. It depends on how you extend a servlet.
C. It depends on the container.
D. It binds it to the HttpServletResponse object.

Question 36:

The HttpServlet abstract subclass has which of the following methods beyond the basic Servlet interface? (Choose two.)
A. doHead()
B. doGet()
C. doRemove()
D. doCookie()

Question 37:

Which of the following elements are legal in a JSP scriptlet? (Choose two.)
A. Statements
B. Variable declarations
C. jsp: useBean
D. XML action

Question 38:

Fill in the name of the method of HttpServletResponse used to notify the client of a servlet error (without parentheses and parameters).
______________

Question 39:

Which of the following is true about template data in JSP?
A. The XML syntax is < jsp: template > < /jsp: template >
B. The XML syntax is < jsp: text > < /jsp: text >
C. The JSP syntax is < % expression % >
D. It is processed by the JSP engine.

Question 40:

Regarding changing the status in the response header, which statement is true?
A. You use the addStatus method.
B. You use the setStatus method.
C. You use the page directive.
D. You use an XML action directive.

Question 41:

Provide the name of the method that the servlet container calls on every request.
______________

Question 42:

Regarding the taglib directive, which of the following two statements are true?
A. It names the tag library that defines the custom tags and specifies their tag prefix.
B. It is the tag-library directive, not the taglib directive.
C. It declares that the JSP page uses custom tags.
D. It declares that the JSP page can use beans as defined in the directive.

Question 43:

What happens when the session attribute of the page directive is false? (Choose two.)
A. The session attribute doesn't go in the page directive.
B. You cannot use the session object.
C. Referring to a session object in the code causes a translation-time error.
D. The session attribute can only be specified with XML, not JSP syntax.

Question 44:

How do you specify that a given JSP page can be used as an error page?
A. There is no tag for this. It must be done in the web.xml configuration file.
B. Set the isErrorPage attribute of the page directive to true.
C. Place it in the error directory.
D. Use the include element.

Question 45:

Regarding a JSP page that inherits a class, which two of the following are true?
A. Servlets can inherit a class so JSP pages can too.
B. It uses the extends="package.class" attribute of the page directive.
C. It can only inherit another JSP page, not a servlet.
D. It can only inherit a JSP page with the same superclass.

Question 46:

Which statement is true about JSP expressions?
A. You must convert them to strings to append them to the output stream.
B. The JSP syntax is < % expression % >
C. The JSP syntax is < %=expression % >
D. The JSP syntax is < % System.out.print(expression) % >

Question 47:

Regarding forwarding a request to a Web resource in JSP, what two of the following are true?
A. You use the page directive. Set the forward attribute to true.
B. You can't do this in JSP. Do it at the servlet level.
C. < jsp: forward page="< %= expression % >" / >
D. < jsp: forward page="relativeURL" >
< jsp: param name="parameterName" value="parameterValue" / > +
< /jsp: forward >

Question 48:

Which of the following are true about the include directive and the jsp: include element?
A. The include directive is processed when the JSP page is translated into a servlet class. The jsp: include element is processed when a JSP page is executed.
B. The include directive is processed when the JSP page is compiled into a servlet class. The jsp: include element is processed when a JSP page is translated.
C. The include directive is processed when the JSP page is translated into a servlet class. The jsp: include element is processed when a JSP page is translated.
D. The include directive is processed when the JSP page is executed into a servlet class. The jsp: include element is processed when a JSP page is executed.

Question 49:

How can a servlet set headers of an HTTP response? (Choose two.)
A. Using a query string.
B. Using POST.
C. Using addHeader.
D. Using setHeader.

Question 50:

What kind of scheme is the HTTP protocol?
A. request/response
B. store/forward
C. queuing
D. search/return

Question 51:

If you wanted to use a conditional piece of code, which of the following shows where would you place it?
A. < jsp: scriptlet > code goes here < /jsp: scriptlet >
B. < jsp: code > code goes here < /jsp: code >
C. < jsp: include > code goes here < /jsp: include >
D. < jsp: jsp > code goes here < /jsp: jsp >

Question 52:

How would you forward a request to another resource?
A. < jsp: forward url="page.htm" / >
B. < jsp: forward param="page.htm"/ >
C. < jsp: forward uri="page.htm" / >
D. < jsp: forward page="page.htm" / >

Question 53:

What does the sendError method do?
A. It sends an error message to the server.
B. It sends an error message to the client log.
C. It logs an error.
D. It sends an error response to the client using the specified status.

Question 54:

Requests are represented by which two of the following objects? (choose two)
A. Request
B. Servlet Request
C. HttpServletRequest
D. ContainerRequest

Question 55:

Regarding passing an exception object to the method that writes information to the log file, which statement is true?
A. You can pass a string but not an exception object to the method that logs a message.
B. You can pass an exception object to the ServletContext.errorLog method that logs a message.
C. The exception must be converted to a string first.
D. You can use the response.log method to write to the log.

Question 56:

Which of the following will include the text of a resource at translation time?
A. < %@ include file="relativeURLspec" % >
B. < %! include file="relativeURLspec" % >
C. < %jsp: include file="relativeURLspec" % >
D. < %@ page import="relativeURLspec" % >

Question 57:

Which two of the following are correct uses of the RequestDispatcher (assume req is a correctly instantiated object of HttpServletRequest)? (choose two)
A. req.getRequestDispatcher(forwardURL). forward(req, res);
B. req.getRequestDispatcher(includeURL). include(req, res);
C. req.getRequestDispatcher.include(req, res);
D. req.getRequestDispatcher.forward(req, res);

Question 58:

What happens if you send data to the client after sendError has been called?
A. The information is ignored by the server.
B. The information is ignored by the client.
C. The method will throw IllegalStateException.
D. The method will throw IllegalSendException.

Question 59:

Which design pattern acts as a proxy and reduces network traffic?
A. Value objects
B. Model-view-controller
C. Data access objects
D. Business delegate

Question 60:

Regarding the sendRedirect method, which two of the following statements are true? (Choose two.)
A. It is legal to call the sendRedirect method with a relative URL path.
B. It is legal to call the sendRedirect method with an absolute URL path.
C. You must redirect to a servlet that implements the same interface.
D. You must redirect to a resource that must be defined in the deployment descriptor.

Previous Chapter: Chapter 59 - Exam Preparation Tips

3 comments:

  1. Hi,

    Tx so much for all these questions, they were very useful.

    Regards

    Alvaro

    ReplyDelete
  2. Thanks for the useful questions. Where is the answer for question?

    ReplyDelete
    Replies
    1. Its here: http://inheritingjava.blogspot.com/2011/04/scwcd-mock-exam-1-answers.html

      Anand

      Delete

© 2013 by www.inheritingjava.blogspot.com. All rights reserved. No part of this blog or its contents may be reproduced or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without prior written permission of the Author.

ShareThis

Google+ Followers

Followers