Advanced Java Quiz

25 Questions | Total Attempts: 4615

SettingsSettingsSettings
Advanced Java Quiz - Quiz

This will exmine your understanding in JSP,Servlet and Design patterns


Questions and Answers
  • 1. 
    Which method in the HttpServlet class services the HTTP POST request? (Select one)
    • A. 

      DoPost(ServletRequest, ServletResponse)

    • B. 

      DoPOST(ServletRequest, ServletResponse)

    • C. 

      ServicePost(HttpServletRequest, HttpServletResponse)

    • D. 

      DoPost(HttpServletRequest, HttpServletResponse)

  • 2. 
    Which of the following lines would initialize the out variable for sending a Microsoft Word file to the browser?
    • A. 

      PrintWriter out = response.getServletOutput();

    • B. 

      PrintWriter out = response.getPrintWriter();

    • C. 

      PrintWriter out = response.getOuputStream();

    • D. 

      OutputStream out = response.getOuputStream();

    • E. 

      ServletOutputStream out = response.getServletOutputStream();

  • 3. 
    Which of the following methods would you use to retrieve header values from a request? (Select two)
    • A. 

      GetHeader() of ServletRequest

    • B. 

      GetHeaders() of HttpServletRequest

    • C. 

      GetHeaderValue() of ServletRequest

    • D. 

      GetHeader() of HttpServletRequest

    • E. 

      GetHeaders() of ServletRequest

    • F. 

      GetHeaders() of HttpServletRequest

  • 4. 
    Which element is used to specify useful information about an initialization parameter of a servlet in the deployment descriptor?
    • A. 

      Param-description

    • B. 

      Description

    • C. 

      Info

    • D. 

      Param-info

    • E. 

      Init-param-info

  • 5. 
    What file is the deployment descriptor of a web application named BankApp stored in?
    • A. 

      BankApp.xml

    • B. 

      Bankapp.xml

    • C. 

      Server.xml

    • D. 

      WebApp.xml

    • E. 

      Web.xml

  • 6. 
    Your web application, named simpletax, depends on a third-party JAR file named taxpackage.jar. Where would you keep this file?
    • A. 

      Simpletax/WEB-INF/thirdparty

    • B. 

      Simpletax/WEB-INF/jars

    • C. 

      Simpletax/WEB-INF/lib

    • D. 

      Simpletax/WEB-INF/classes

    • E. 

      Simpletax/WEB-INF

  • 7. 
    Consider the following class: import javax.servlet.*; public class MyListener implements ServletContextAttributeListener { public void attributeAdded(ServletContextAttributeEvent scab) { System.out.println("attribute added"); } public void attributeRemoved(ServletContextAttributeEvent scab) { System.out.println("attribute removed"); } } Which of the following statements about the above class is correct?
    • A. 

      This class will compile as is.

    • B. 

      This class will compile only if the attributeReplaced() method is added to it.

    • C. 

      This class will compile only if the attributeUpdated() method is added to it.

    • D. 

      This class will compile only if the attributeChanged() method is added to it.

  • 8. 
    Which deployment descriptor element is used to specify a ServletContext- Listener?
    • A. 

    • B. 

    • C. 

    • D. 

  • 9. 
    Consider the following doPost() method of a servlet: public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("Inside doPost"); PrintWriter out = response.getWriter(); out.println("Hello, "); String name = getNameFromDBSomeHow(); if(name == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Unable to get name."); } out.println(name); } Assuming that getNameFromDBSomeHow() returns null, which of the following statements regarding this code are correct?
    • A. 

      It will throw an InvalidStateException while serving a request.

    • B. 

      It will throw a ServletException while serving a request.

    • C. 

      It will throw a NullPointerException while serving a request.

    • D. 

      It will throw an IllegalStateException while serving a request.

    • E. 

      It will not throw an exception.

  • 10. 
    Which deployment descriptor element contains the element?
    • A. 

    • B. 

    • C. 

      <error-page>

    • D. 

  • 11. 
    Which of the following tags can you use to print the value of an expression to the output stream?
    • A. 

    • B. 

    • C. 

    • D. 

    • E. 

  • 12. 
    Which of the following correctly declares that the current page is an error page and also enables it to take part in a session?
    • A. 

    • B. 

    • C. 

    • D. 

      None of the above.

  • 13. 
    What will be the output of the following code? (Select one) x = ,
    • A. 

      X = 3, 5

    • B. 

      X = 3, 7

    • C. 

      X = 5, 3

    • D. 

      Compilation error

  • 14. 
    Which of the following implicit objects is not available to a JSP page by default?
    • A. 

      Application

    • B. 

      Session

    • C. 

      Exception

    • D. 

      config

  • 15. 
    Which of the following is a valid use of the action?
    • A. 

    • B. 

    • C. 

    • D. 

  • 16. 
    Consider the following code: state = Which of the following are equivalent to the third line above? (Select three)
    • A. 

    • B. 

    • C. 

    • D. 

    • E. 

      State =

    • F. 

      State =

  • 17. 
    Which of the options locate the bean equivalent to the following action? (Select three)
    • A. 

      Request.getAttribute("address");

    • B. 

      Request.getParameter("address");

    • C. 

      GetServletContext().getRequestAttribute("address");

    • D. 

      PageContext.getAttribute("address",PageContext.REQUEST_SCOPE);

    • E. 

      PageContext.getRequest().getAttribute("address");

    • F. 

      PageContext.getRequestAttribute("address");

    • G. 

      PageContext.getRequestParameter("address");

  • 18. 
    Consider the following code, contained in a file called this.jsp: <jsp:include page="that.jsp" /> Which of the following is true about the AddressBean instance declared in this code?
    • A. 

      The bean instance will not be available in that.jsp

    • B. 

      The bean instance may or may not be available in that.jsp, depending on the threading model implemented by that.jsp.

    • C. 

      The bean instance will be available in that.jsp, and the that.jsp page can print the values of the beans properties using .

    • D. 

      The bean instance will be available in that.jsp and the that.jsp page can print the values of the bean’s properties using only if that.jsp also contains a declaration identical to the one in this.jsp and before using .

  • 19. 
    Which of the following is a valid taglib directive?
    • A. 

    • B. 

    • C. 

    • D. 

    • E. 

  • 20. 
    You are automating a computer parts ordering business. For this purpose, your web application requires a controller component that would receive the requests and dispatch them to appropriate JSP pages. It would also coordinate the request processing among the JSP pages, thereby managing the workflow. Finally, the behavior of the controller component is to be loaded at runtime as needed. Which design pattern would be appropriate in this situation?
    • A. 

      Front Controller

    • B. 

      Session Facade

    • C. 

      Value Object

    • D. 

      Model-View-Controller

    • E. 

      Data Access Object

  • 21. 
    What are the benefits of using the Data Access Object pattern? (Select two)
    • A. 

      The type of the actual data source can be specified at deployment time.

    • B. 

      The data clients are independent of the data source vendor API.

    • C. 

      It increases the performance of data-accessing routines.

    • D. 

      It allows the clients to access the data source through EJBs.

    • E. 

      It allows resource locking in an efficient way.

  • 22. 
    Which design pattern allows you to decouple the business logic, data representation, and data presentation? (Select one)
    • A. 

      Model-View-Controller

    • B. 

      Value Object

    • C. 

      Bimodal Data Access

    • D. 

      Business Delegate

  • 23. 
    Which of the following are the benefits of using the Value Object design pattern? (Select two)
    • A. 

      It improves the response time for data access.

    • B. 

      It improves the efficiency of object operations.

    • C. 

      It reduces the network traffic.

    • D. 

      It reduces the coupling between the data access module and the database.

  • 24. 
    Which of the following statements are correct? (Select two)
    • A. 

      The Value Object pattern ensures that the data is not stale at the time of use.

    • B. 

      It is wise to make the Value Object immutable if the Value Object represents readonly data.

    • C. 

      Applying the Value Object pattern on EJBs helps to reduce the load on enterprise beans.

    • D. 

      A Value Object exists only on the server side.

  • 25. 
    What are the benefits of using the Business Delegate pattern? (Select three)
    • A. 

      It implements the business service functionality locally to improve performance.

    • B. 

      It shields the clients from the details of the access mechanism, such as CORBA or RMI, of the business services.

    • C. 

      It shields the clients from changes in the implementation of the business services.

    • D. 

      It provides the clients with a uniform interface to the business services.

    • E. 

      It reduces the number of remote calls and reduces network overhead.

Back to Top Back to top