Servlets are small program which execute on the web server. They run under web server environment exploiting the functionalities of the web server.
Servlet life cycle
Figure: – Servlet Life cycle
There are three methods which are very important in servlet life cycle i.e. “init”, “service” and “destroy”. Server invokes “init ()” method when servlet is first loaded in to the web server memory. Servlet reads HTTP data provided in HTTP request in the “service ()” method. Once initialized servlet remains in memory to process subsequent request. So for every HTTP request “service ()” method of the servlet is called. Finally when server unloads the “servlet ()” from the memory it calls the “destroy” method which can be used to clean up any resource the servlet is consuming.
See the following video on Java/J2EE Interview question which describes String Literal Pool: –
Click for more Java/Servlets interview questions
Visit for more author’s blog on Java/Servlets interview questions