Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     

Java/servlets interview questions: - Can you explain Servlets and its lifecycle?

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

Share this article   |    Print    |    Article read by 3177 times
Shivprasad Koirala
We conduct training for Java/J2EE technologies like design patterns, J2EE, Struts, Hibernate, Spring, Rich Interface etc. and likes to write articles on the same in free time.
Related Articles: No related article
Related Interview Questions: No related interview question