<<< Servlets Interview Questions and Answers >>>

Servlets - Questions & Answers

Here is the list of Servlets Interview Questions. The answers are short and to the point.These questions are frequently asked by the recruiters. So we try our best to provide you the Servlets interview questions. A list of frequently asked Servlets interview questions and answers are given below.

«« | 1 2 3 4 5 | »»

Servlets : Java Interview Questions

1) What are Servlets?

Ans :Java Servlets are programs that run on a Web or Application server and act as a middle layer between a request coming from a Web browser or other HTTP client and databases or applications on the HTTP server.

2) What are the types of servlet?

Ans : The Types of a servlet are :

  1. Generic Servlet.
  2. HTTP Servlet.

3) How to create servlet?

Ans : Servlets can be created using :

  1. javax.servlet
  2. javax.servlet.http package

4) What is the life-cycle of a servlet?

Ans : The life-cycle of a servlet is :

  1. Servlet class is loaded.
  2. Servlet instance is created.
  3. Init method is invoked.
  4. Service method is invoked.
  5. Destroy method is invoked.

5) What are the life-cycle methods for a servlet?

Ans :The life-cycle methods of a servlet are :

  1. public void init().
  2. public void service().
  3. public void destroy().

6) When init() method of servlet gets called?

Ans :The init method is designed to be called only once. It is called when the servlet is first created, and It is used to initialize the servlet.

7) When service() method of servlet gets called?

Ans :It is invoked at each request.The service() method is used to service the request.

8) When destroy() method of servlet gets called?

Ans : It is invoked only once when servlet is unloaded. This method gives your servlet a chance to close database connections, halt background threads, write cookie lists or hit counts to disk, and perform other such cleanup activities.

9) What is the difference between GET and POST method?

Ans :The difference between GET and POST method are :

GET Method POST Method
1. Limited amount of data(2k) can be sent 1. Large amount of data can be sent
2. Data is sent in header 2. Data is sent in body
3. Can be bookmarked 3. Cannot be bookmarked
4. Parameters are not encrypted 4. Parameters are encrypted
5. Faster 5. slower

10) What are the advantages of servlets?

Ans :The advantages of servlets are :

  1. the web application developed with Servlet can be run on any standard web container such as Tomcat, JBoss, Glassfish servers and on operating systems such as Windows, Linux, Unix, Solaris, Mac etc.
  2. Servlets are robust because container takes care of life cycle of servlet and we don’t need ` to worry about memory leaks, security, garbage collection etc.
  3. Servlets are maintainable and learning curve is small because all we need to take care is business logic for our application.

«« | 1 2 3 4 5 | »»