I am very confused. Why the HttpServlet class is an abstract? And what is the basic difference between bean and pojo?
-
Heading and body content are different!?!?! – Abimaran Kugathasan Feb 21 '14 at 17:32
-
1???... r u confused...or making us confusing ?` – Vinay Veluri Feb 21 '14 at 17:32
-
I've moved the title to your question body. In future, always include the question in the body. Else you might not get a good response. – Rohit Jain Feb 21 '14 at 17:33
-
So, why do you think the class shouldn't be `abstract`? – Rohit Jain Feb 21 '14 at 17:34
-
1Duplicate of http://stackoverflow.com/questions/18909206/why-httpservlet-is-an-abstract-class-any-functional-reason – Abimaran Kugathasan Feb 21 '14 at 17:34
-
Your bean/pojo question is an entirely different question, and should be asked in a different post (if at all). – Jon Skeet Feb 21 '14 at 17:35
-
Would you ever need instance of `HttpServlet`? How would you use it? – Pshemo Feb 21 '14 at 17:35
-
1Duplicate of http://stackoverflow.com/questions/6742533/why-httpservlet-class-is-declared-as-abstract for the first question – developerwjk Feb 21 '14 at 17:35
-
Duplicate of http://stackoverflow.com/questions/1612334/difference-between-dto-vo-pojo-javabeans for the pojo/bean question – developerwjk Feb 21 '14 at 17:37
3 Answers
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.

- 5,426
- 2
- 26
- 39
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.

- 1,421,763
- 867
- 9,128
- 9,194
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.

- 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