Java/servlets interview questions: – 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

java

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

Regards,

Visit for more author’s blog on Java/Servlets interview questions

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s