The questions in this first quiz on Java Servlets are on the topics covered in the Servlet Basics section of the site. The table below lists the
lessons, a description of the lesson content and the quiz question number range.
Click on a lesson in the table to go to that lesson for a refresher on the topics for that lesson.
The quiz below tests your knowledge of the material learnt in the Servlets Basics section of the site.
Question 1 : What does HTTP stand for?
- HTTP stands for Hypertext Transfer Protocol
Question 2 : Which other protocols are responsible for getting HTTP requests and responses to and from the server?
- HTTP sits on top of TCP/IP, which are the protocols responsible for transferring data correctly and resolving internet connections.
Question 3 : HTTP requests and responses are always made up of three parts?
- This isn't always the case as in many HTTP methods the body is optional and so HTTP requests and responses can be made up of only two parts.
Question 4 : Which is the only HTTP method that is neither idempotent or safe?
- The <code>POST</code> HTTP method is neither idempotent or safe.
Question 5 : Which of the HTTP method is generally used by engineers rather than programmers?
- The <code>TRACE</code> HTTP method is generally used by engineers for debugging connection pathways.
Question 6 : What do HTTP response codes starting with a 3 generically indicate
- HTTP response codes starting with a 3 generically indicate some sort of redirection.
Question 7 : Which is the other inherently unsafe HTTP method apart from
- The <code>PUT</code> HTTP method is inherently unsafe as each time the operation is used it may have different effects.
Question 8 : We would use the
GET HTTP method to put sensitive data into the HTTP request body
- The <code>GET</code> HTTP method appends all data to the URI. For sensitive data we would use the <code>POST</code> HTTP method which hides all data in the request body.
Question 9 : What are Servlets and JSPs defined as in the Java EE5 specification?
- Servlets and JSPs defined are as web components in the Java EE5 specification
Question 10 : How are servlets invoked?
- Servlets are invoked from a web container.
Question 11 : A web container stores all our EJBs, JSPs and servlets?
- A web container stores web components which are JSPs and servlets. An EJB container stores EJBs.
Question 12 : Which method of a servlet does a container invoke?
- A container will invoke the <code>service()</code> method of a servlet.
Question 13 : What does the
doGet() method of a servlet generate?
- The <code>doGet()</code> method of a servlet generates dynamic page content to be passed back to the container via the HttpServletResponse object.
Question 14 : The container creates the HTTP response object
- The container creates the HttpServletResponse object not the HTTP response object.
Question 15 : What is the purpose of the MVC pattern?
- The MVC pattern reduces complexity by separating development into three distinct areas of concern.
Question 16 : In a three tier architecture which tier maps to the Controller area of the MVC pattern?
- In a three tier architecture the Application tier maps to the Controller area of the MVC pattern.
Question 17 : Which part of the MVC pattern maps to the Data tier in a three tier architecture?
- In a three tier architecture the Model maps to the Data tier.
Question 18 : What informs the View of changes in state?
- The Model informs the View of changes in state.
Question 19 : Where are user actions processed?
- User actions are processed by the Controller.
Question 20 : What type of requests can servlets respond to?
- Servlets can respond to any types of request, but are commonly used to extend applications hosted by web servers using a web container such as Tomcat 6.
Question 21 : We cannot implement the
javax.servlet.Servlet interface directly?
- We can implement the <code>javax.servlet.Servlet</code> interface directly, although it's unlikely we would do so.
Question 22 : The
javax.servlet.GenericServlet class is a concrete implementation of the
- The <code>javax.servlet.GenericServlet</code> class is abstract, so we need to extend this class to override the abstract <code>service()</code> method.
Question 23 : When using the
javax.servlet.http.HttpServlet class there is no need to override one of the
- This is true as there is no need to override either of the <code>service()</code> methods.
Question 24 : How are the
doXXX() methods of the
javax.servlet.http.HttpServlet class invoked?
- The <code>doXXX()</code> methods of the <code>javax.servlet.http.HttpServlet</code> class are invoked via the protected <code>service()</code> method.
Question 25 : What is the first stage in the servlet life cycle?
- The first stage in the servlet life cycle is when application class loader is used to load the servlet into the container
Question 26 : How many servlet lifecycle methods are there?
- there are three servlet lifecycle methods, these being <code>init()</code>, <code>service()</code> and <code>destroy()</code>.
Question 27 : Which of these lifecycle stage comes first, initialisation or instantiation?
- The container has to instantiate a servlet before we initialise it.
Question 28 : How many stages are there in the servlet lifecycle?
- There are five stages in the servlet lifecycle, these being class loading, instantiation, initialisation, servicing and destruction.
Question 29 : Servlets get loaded by the container on server statup?
- Servlets are lazily initialised and get loaded by the container when required unless instructed to within the DD using the <code>load-on-startup</code> sub-element of the <code>servlet</code> top-level element.
Question 30 : Each servlet gets one of which of the following objects?
- Each servlet gets a <code>ServletConfig</code> object.
Question 31 : The destroy() lifecycle method will always run for a servlet?
- If a servlet has failed during the initialisation stage of the lifecycle, then no servlet exists to be destroyed as the resources were not configuered correctly and hence the <code>destroy()</code> method doesn't get invoked.
Question 32 : What is the recommended method of deploying into Tomcat??
- The recommended method of deploying into Tomcat is by using a WAR file.
Question 33 : Where in Tomcat would we put static and dynamic view components we want a client to access directly?
- Files within <code>WEB-INF</code> folder are hidden and the <code>lib</code> folder is for JARS, so we would put viewable content within our project folder.
Question 34 : Which servlet object is accessible when directly implementing the
- Both the <code>ServletConfig</code> and <code>ServletContext</code> objects are available after the <code>init()</code> lifecycle method has run regardless of implementation.
Question 35 : Which top-level DD element is used in conjunction with the
- The <code>servlet</code> element is used in conjunction with the <code>servlet-mapping</code> element.
Question 36 : The
<servlet> top-level DD element is mandatory?
- All top-level DD elements are optional.
Question 37 : When coding the
<servlet> top-level DD element, the
<jsp-file> sub-level DD element is mandatory
- When coding the <code>servlet</code> top-level DD element, either the <code>servlet-class</code> or <code>jsp-file</code> sub-level DD element is mandatory.
Question 38 : Which of these methods of
GenericServlet should you override for initialisation within a servlet?
- You should override the <code>init()</code> method of the <code>GenericServlet</code> class, which is delegated to from the <code>init(ServletConfig servletConfig)</code> method for initialisation within a servlet.
Question 39 : Within which element within the DD do we place initialisation parameters for a servlet?
- Initialisation parameters for a servlet are placed within sub-elements of the <code>init-param</code> element.
Question 40 : You get one
ServletConfig object per web application?
- You get one <code><ServletConfig></code> object for each servlet (and there can be many) within a web application.
Question 41 : Within which element within the DD do we place initialisation parameters for a web application?
- Initialisation parameters for a web application are placed within sub-elements of the <code>context-param</code> element.
Question 42 : You get one
ServletContext object per web application?
- You get one <code><ServletContext></code> object for the entire web application.
Question 43 : You can have mulitple
context-param elements within the DD?
- Yes you can have mulitple <code><context-param></code> elements within the DD.
Question 44 : The
context-param element is a sub-element of the
- The <code>context-param</code> is a top-level element and not part of the <code>servlet</code> element.
Question 45 : How are
ServletResponse objects created?
- <code>ServletRequest</code> and <code>ServletResponse</code> objects are created by the container.
Question 46 : Which class does
- <code>HttpServlet</code> extends <code>GenericServlet</code>, the other answers are all interfaces.
Question 47 : Which HTTP protocol specific
service() method delegates servicing to one of the HTTP doXXX() methods?
- The protected <code>service()</code> method delegates servicing to one of the HTTP doXXX() methods.
Question 48 : What does the container guarantee with regards to multithreading?
- With regards to multithreading the container guarantees that every request is started in a new thread.
Question 49 : The
HttpServletResponse objects are part of the the
- The <code>HttpServletRequest</code> and <code>HttpServletResponse</code> objects are protocol specific and so have their own package called <code>javax.servlet.http</code>.
Question 50 : Which HTTP doXXX() method is the default for delegation from the
- The <code>doGet()</code> method is the default for delegation from the <code>service()</code> method.
Question 51 :
- <code>HttpServletRequest</code> extends <code>ServletRequest</code> as both are interfaces and you cannot implement another interface.
Quiz Progress Bar Please select an answer
The next quiz on Servlets is all about the lessons in the servlets intermediate section.