SCWCD Mock Exam 1

Question 1: 


Which of the following can call the init method?
A. doPut
B. session
C. service
D. request
E. the container


Question 2: 


Which corresponding method in the HttpServlet class do you use to retrieve the value of a text field on an HTML form?
A. doPost
B. getParameter(String fieldName)
C. doGet(String fieldName)
D. getHTTP(String fieldName)


Question 3: 


Please provide the interface name which you implement to create a context listener.
______________________________


Question 4: 


Which method is used to get a ServletContext object?
A. getContextServlet
B. getServlet
C. getContext
D. getServletContext


Question 5: 


Which two of the following are HttpServlet class methods (choose two)?
A. doPut
B. getRequest
C. doPost
D. post


Question 6: 


Which method does the container call at the end of the servlet lifecycle?
A. doDelete
B. end
C. finalize
D. destroy


Question 7: 


What type of HTTP request is normally used for simple HTML page requests?
A. POST
B. GET
C. DELETE
D. CALL


Question 8: 


The getInitParameterNames method returns what?
A. Enumeration of string objects with session-wide parameters.
B. String array with session-wide parameters.
C. Enumeration of string objects with application-wide parameters.
D. String array with application-wide parameters.


Question 9: 


What types of events trigger a POST type request?
A. When a user clicks a hyperlink.
B. When a user clicks a button on an HTML form whose method is set to POST, as in method=post.
C. This is determined by the browser based on the size of the request.
D. This is determined by the server based on the size of the request.


Question 10: 


Read the following code:
protected void service(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, IOException
{ response.setContentType("text/plain");
PrintWriter out = response.getWriter();
StringBuffer html = new StringBuffer();
html.append("< html >\n");
html.append("< head >< title >Servlet Example" + "< /title >< /head >\n");
html.append("< body >\n");
html.append("Servlet Example");
html.append("< /body >");
html.append("< /html >");
out.print( html.toString() );
}


Which two statements are true regarding this code (choose two)?
A. When a user sends a request to the container (assume servlet has not been loaded), this is the first method it calls.
B. When a user sends a request to the container (assume servlet has not been loaded), this is the second method it calls.
C. The doGet method will be called next.
D. The doGet method will not be called next.


Question 11: 


What causes a servlet to load?
A. A Web server start.
B. The container detects that a class file has changed.
C. It is configured to do so periodically.
D. It is loaded upon every request.


Question 12: 


Which two of the following are benefits of the POST method (choose two)?
A. It can send unlimited length data as part of its HTTP request body.
B. It allows bookmarks.
C. It uses simple query strings.
D. It hides data because it isn't passed as a query string, but is passed instead in the message body.


Question 13: 


Which of the following are application-wide actions?
A. Context.setAttribute("applicationName", "Certification by Que");


B. config.getServletContext .setAttribute("applicationName", "Certification by Que");


C. config.getServletContext .getAttribute("applicationName", "Certification by Que");


D. Context .setAttribute("applicationName", "Certification by Que"); 


Question 14: 


What is the benefit of using the HEAD HTTP method?
A. It hides the requester identity.
B. It masks the IP address.
C. It can handle any size request.
D. It is the smallest type request.


Question 15: 


Which interface defines the methods for retrieving form parameters?
A. ServletRequest
B. ServletResponse
C. HTTPRequest
D. HTTPResponse


Question 16: 


When does the container call init?
A. With each request for a given servlet.
B. Only on the first request for each user.
C. It is not called by the container.
D. Only at the beginning of the servlet lifecycle.


Question 17: 


Which method do you use to retrieve a single value if you know the particular parameter name?
A. getParameterName(String parameterName)
B. getParameterValues(String parameterName)
C. getParameters(String parameterName)
D. getParameter(String parameterName)


Question 18: 


Which method returns the URL to the resource that is mapped to a specified path?
A. getRealPath(String path)
B. getPath(String path)
C. getPathReal(String path)
D. getResource(String path)


Question 19: 


Read the following code:


protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
// Serve the requested resource,
// including the data content.
}


Which two statements are true regarding this code (choose two)?
A. The doGet() method is called when the container receives an HTTP GET request.
B. The container always services a request with a doGet request as the last method called.
C. The request object has session scope.
D. The HTTP GET method may include parameters that are retrievable from the request object.


Click for view the SCWCD Mock Exam 1 - Answers


Question 20: 


How do you perform programmatic server-side includes?
A. setForward(String url)
B. RequestDispatcher
C. Request
D. getResource(String url)


Question 21: 


Which of the following is true?
A. ServletContext.getRequestDispatcher()— This method uses absolute paths.
B. ServletRequest.getRequestDispatcher (String path)— The path may be relative, but cannot extend outside current servlet context.
C. ServletRequest.getNamedDispatcher(String path)— The path may be relative.
D. ServletContext.getRequestDispatcher()— This method uses relative paths.


Question 22: 


Which of the following is correct?
A. Enumeration names = request.getNames() ;
B. String[] names = request.getNames() ;
C. Enumeration parameterNames = request.getParameterNames() ;
D. String[] parameterNames = request.getParameterNames() ;


Question 23: 


Suppose the container received an HTTP POST request. How would you process this request in the servlet's doGet method?
A. This isn't possible. The doPost method will receive the request, not the doGet method.
B. 
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
//often just throw it at doGet()
doGet(request, response);
}






C. If there is no form parameters the container will automatically send the request to the doGet method.
D. 
protected void init(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
//often just throw it at doGet()
doGet(request, response);



Question 24: 


Which method corresponds to the HTTP GET method?
A. get
B. httpGet
C. doGet
D. getHTTP


Question 25: 


It happens often that pages move around and a URL becomes invalid. Throwing back a 404 error isn't nice. What could you do that is better?
A. Use the sendRedirect method to send viewers to a temporary page.
B. Use the sendTemporary method to send viewers to a temporary page.
C. Use the setTemporary method to specify a temporary page and set the context parameter to the new URL.
D. Use the redirect method to send viewers to a temporary page.


Question 26: 


Which of the following method lists are in the correct lifecycle order?
A. request start doPost end
B. service start response destroy
C. request init getPost
D. init service destroy


Question 27: 


Which two of the following are called only once during the lifetime of a servlet (choose two)?
A. destroy
B. doPut
C. service
D. init
E. config


Question 28: 


Which two of the following HttpServlet class methods receives the response object (choose two)?
A. get
B. doPut
C. getHTTP
D. doGet


Question 29: 


What happens if you redirect a request to another URL after some of the response has already been returned?
A. The container simply discards the partial response and jumps to the new URL.
B. The container gets confused.
C. The specification doesn't say what the container is supposed to do. It is up to the vendor to decide.
D. The container throws IllegalStateException.


Question 30: 


Read the following code:
public void service(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("< html >");
out.println("< head >< title >Servlet Error Handling " +
"Example< /title >< /head >");
out.println("< body >");
out.println("A skimpy, but complete servlet.");
out.println("< /body >");
out.println("< /html >");
}
}


Which two statements are true regarding this code (choose two)?
A. The doGet, doPost, or doPut method is called next depending on the type of request.
B. This code is invalid because it doesn't call one of the doGet, doPost, or doPut methods.
C. This code is valid and will handle all three types of HTTP requests including GET, POST, and PUT.
D. The next method invoked is destroy.


Question 31: 


How do you set, get, and change application-level (not session-level) attributes and talk to the servlet container?
A. ServletContext
B. Context
C. Response
D. Request


Question 32: 


Which three options are events that would trigger a GET type request (choose three)?
A. A form submission with the METHOD='GET'.
B. Uploading a file.
C. A user clicking a hyperlink.
D. Typing in the address text box on a browser.
E. Sending email.


Question 33: 


How do you get application-level initialization parameters?
A. You use the getParameterValues method.
B. You use the getInitValues method.
C. You call the init method, which returns an array of initialization parameters.
D. You use the getInitParameter and getInitParameterNames methods.


Question 34: 


You normally write a servlet by overriding the doPut, doGet, and doPost methods. Which class do they come from?
A. HttpServletRequest
B. HttpServletResponse
C. HttpServlet
D. HttpSession


Question 35: 


Which two of the following options are benefits of the POST method (choose two)?
A. It is used for getting information such as a simple HTML page or the results of a database query.
B. It is a method that supports query strings of unlimited length.
C. It hides data because it isn't passed as a query string, but is passed instead in the message body.
D. It normally saves resources because of the way the request is compressed.


Question 36: 


Which of the following methods belongs to the ServletContext class?
A. getInitParameterNames
B. getParameterValues
C. getParameterValues(String)
D. getInitParameter


Question 37: 


The session scope includes which two of the following (choose two)?
A. Requests from several machines.
B. All hits from a single machine.
C. Multiple browser windows if they share cookies.
D. Multiple hits from the same browser across some period of time.


Question 38: 


Which of the following methods corresponds to the HTTP PUT method?
A. getPUT
B. putHttp
C. httpPUT
D. doPut


Question 39: 


Which method returns an enumeration of String objects containing the names of the parameters contained in the request or an empty enumeration if the request has no parameters?
A. getParameterNames
B. getMap
C. getParameterMap
D. getParameterValues


Click for view the SCWCD Mock Exam 1 - Answers


Question 40: 


Read the following code:
< html >
< body >
Devyn likes < b >R/C Buggies< /b >. < br >
< %! int count = 100, factor=5; % >
< %=count * factor% >
< /body >
< /html >


Which two statements are true regarding this code (choose two)?
A. This is a JSP page, but it will not run because it is missing the JSP declaration.
B. The code will display: Devyn likes R/C Buggies. 500
C. This JSP page will be translated into servlet code, which will be compiled and invoked as a servlet going forward.
D. You can't declare two integers on the same line in JSP.


Question 41: 


How do you get the absolute path for a given virtual path?
A. getabsolute Path(String path)
B. getPath(String path)
C. getPathabsolute (String path)
D. getPathabsolute ()


Question 42: 


Which method do you use to retrieve multiple values for a given parameter?
A. getParameterValues
B. getParameterValues(String parameterName)
C. getParameters
D. getParameters(String parameterName)


Question 43: 


How would you “print” a text message to the browser?
A. PrintWriter out = response.getWriter();
out.println(message);


B. response.println(message);


C. ServletOutputStream out = response.getWriter();
out.println(message);


D. ServletOutputStream out = response.ServletOutputStream();
out.println(message);K. 


Question 44: 


Which method obtains a resource located at the named path as an InputStream object?
A. getResourceStream(String path)
B. getResourceAsStream(String path)
C. getResource(String path)
D. getStream(String path)


Question 45: 


A browser or application will sometimes send a request to a server just to check the status or get information (such as 'can you handle a file upload?') from the server. What method does it use to do this?
A. HEAD
B. PING
C. DELETE
D. POST


Question 46: 


What does the getParameter(String) method do?
A. It returns the value of a request parameter.
B. This method is not valid. It really is getFormParameter.
C. It should be getParameter without a string parameter of its own.
D. It can be used to return an integer from a form field.


Question 47: 


What happens if the container crashes?
A. The JVM calls finalize for all pending servlet requests.
B. Since it is crashing it doesn't do anything but disappear.
C. The destroy method is called if possible.
D. The log is noted and then pending requests get simple error returns.


Question 48: 


The PUT type request is for which type of situation?
A. Uploading files to the server.
B. Submitting form field values.
C. Testing for valid URLs.
D. Using XML for exchanges.


Question 49: 


Which of the following two options are ways to get a RequestDispatcher (choose two)?
A. getDispatcher
B. getDispatcherName
C. getNamedDispatcher
D. getRequestDispatcher


Question 50: 


Which of the following two options are ways to invoke the doGet method (choose two)?
A. The init method calls doGet.
B. The container calls doGet.
C. The request object calls doGet.
D. The service method calls doGet.


Question 51: 


Which method returns the values of a given request parameter as an array of strings, or returns null if the parameter does not exist?
A. getParameterMap
B. getParameterValues
C. getParameterValues
D. getParameters


Question 52: 


What happens if you set a Web application-wide parameter through ServletContext, but don't provide a value?
A. This cannot happen.
B. An exception will be thrown.
C. Retrieving this parameter will return a string containing a servlet container version number.
D. Retrieving this parameter will return a string containing a servlet container name.


Question 53: 


What is the most frequently used type of HTTP request?
A. POST
B. GET
C. DELETE
D. CALL


Question 54: 


How do you get the request header names?
A. Enumeration e = request.getHeaderNames ;
B. String[] names = request.getHeaderNames ;
C. Enumeration e = request.getHeaders ;
D. String[] names = request.getHeaders ;


Question 55: 


Suppose you want to open a binary file in a browser from a servlet. How would you declare and initialize the output stream?
A. ServletContext.getOutStream ;
B. ServletContext.getBinaryStream ;
C. ServletOutputStream out = response.getOutputStream ;
D. PrinterWriter out = response.getPrinterWriter ;


Question 56: 


Please provide the interface name that allows you to make your servlet thread-safe.
_____________________________


Question 57: 


How do you add the content-type header to the response?
A. response.setContentType ;
B. response.setType( contentType );
C. response.setContentType( String );
D. String type = request.getContentType ;


Question 58: 


Which of the following two options are features of the GET method (choose two)?
A. It can handle most request types including file uploading and form submissions.
B. It is for getting information such as a simple HTML page or the results of a database query.
C. This method supports query strings. Servers usually limit query strings to about 1,000 characters.
D. This disallows bookmarks.


Question 59: 


What happens if, when calling getParameterValues, the parameter has a single value?
A. It returns an error. You should use the getParameterValue method for single value parameters.
B. It returns an array with a length of one.
C. getParameterValues calls getValue for that single value.
D. It returns a string with that single value.


Question 60: 


The POST type request is most often used for which of the following situations?
A. When uploading a file.
B. With query strings.
C. The POST request is a combination of a GET and PUT.
D. When submitting an HTML form.




Click for view the SCWCD Mock Exam 1 - Answers



Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email