Servlets Basics QuizS2C Home « Servlets Basics Quiz

The questions in this Java Servlets quiz 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.

Lesson Summary

Click on a lesson in the table to go to that lesson for a refresher on the topics for that lesson.

Servlets Basics Lessons Description Question Range
Lesson 1 - Introduction to ServletsIn this lesson we download the tools necessary for setting up our environment to begin coding using servlets.
Lesson 2 - What is HTTP?This lesson is about the HTTP protocol, HTTP request/response mechanism, HTTP methods and HTTP response codes.1 - 8
Lesson 3 - Java EE 5 & ServletsIn this lesson we learn about the Java EE 5 Platform and how servlets fit into the architecture.9 - 19
Lesson 4 - Servlet OverviewIn this lesson we start our in depth investigation of servlets by looking at the java interfaces and classes we need to create our own servlets.20 - 24
Lesson 5 - The Servlet LifecycleIn this lesson we look at the servlet lifecycle, from the loading and instantiation of a servlet to its eventual destruction.25 - 31
Lesson 6 - Our First ServletIn this lesson we create our first servlet and look at the processes involved.32 - 37
Lesson 7 - ServletConfig & ServletContextIn this lesson we look at the conditional statements available in java.38 - 44
Lesson 8 - Request & ResponseIn this lesson we look in much more detail at requests and responses.45 - 51

Servlets Quiz

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 DELETE and POST?
- 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.
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 javax.servlet.Servlet interface?
- 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 service() methods?
- 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 Servlet interface?
- 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 <servlet-mapping> element?
- 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 <servlet-class> or <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 servlet element?
- The <code>context-param</code> is a top-level element and not part of the <code>servlet</code> element.
Question 45 : How are ServletRequest and ServletResponse objects created?
- <code>ServletRequest</code> and <code>ServletResponse</code> objects are created by the container.
Question 46 : Which class does HttpServlet extend?
- <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 HttpServletRequest and HttpServletResponse objects are part of the the javax.servlet package?
- 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 service() method?
- The <code>doGet()</code> method is the default for delegation from the <code>service()</code> method.
Question 51 : HttpServletRequest implements ServletRequest?
- <code>HttpServletRequest</code> extends <code>ServletRequest</code> as both are interfaces and you cannot implement another interface.
Quiz Progress Bar Please select an answer

What's Next?

The next quiz on Servlets is all about the lessons in the servlets intermediate section.

go to home page Homepage go to top of page Top