0

I am very confused. Why the HttpServlet class is an abstract? And what is the basic difference between bean and pojo?

Rohit Jain
  • 209,639
  • 45
  • 409
  • 525
Aizen
  • 1
  • 1

3 Answers3

2

HttpServlet is abstract because it's completely useless without concrete implementations of the business methods. The javadoc says:

Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A subclass of HttpServlet must override at least one method, usually one of these:

  • doGet, if the servlet supports HTTP GET requests
  • doPost, for HTTP POST requests
  • doPut, for HTTP PUT requests
  • doDelete for HTTP DELETE requests
  • init and destroy, to manage resources that are held for the life of the servlet
  • getServletInfo, which the servlet uses to provide information about itself

Bean and Pojo are terms that usually refer to simple java classes that do not implement interfaces or extend classes from external libraries/frameworks.

Giovanni Caporaletti
  • 5,426
  • 2
  • 26
  • 39
1

Why would HttpServlet not be abstract? An instance of just HttpServlet would be useless - the whole point of a servlet is to be able to provide useful responses to requests, and HttpServlet can't do that. It's generally a good idea to prevent useless situations where possible.

As another example of something similar, consider MouseAdapter. That's abstract despite having no abstract methods, because it's useless until you override at least one method.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
1

Check the API

Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A subclass of HttpServlet must override at least one method, usually one of these:

  • doGet, if the servlet supports HTTP GET requests
  • doPost, for HTTP POST requests
  • doPut, for HTTP PUT requests
  • doDelete, for HTTP DELETE requests
  • init and destroy, to manage resources that are held for the life of the servlet
  • getServletInfo, which the servlet uses to provide information about itself

HttpServlet does not have useful functionality on its own.

Abimaran Kugathasan
  • 31,165
  • 11
  • 75
  • 105
  • thank you for your response.But my question is "if there is no any abstract method present in HTTP servlet class(means we have to override all methods) then why it is called ABSTRACT class?" – Aizen Feb 25 '14 at 10:10