• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why generic servlet is an abstract class?

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to my knowledge, Generic Servlet class implements Servlet interface and it gives definition of all the methods present in Servlet interface except service() method. service() method is abstract in Generic Servlet class, that's why Generic Servlet is an abstract class.Please correct me if I am wrong or is there anything I can add in my explanation.
regards...
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, this is basic Java. If any method is abstract, then the class must be abstract.
 
rahul S Sharma
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about HttpServlet class? This class doesn't have any abstract method, still is an abstract class.
 
Ranch Hand
Posts: 290
Debian Fedora Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes you can make , even though the class doesn't have any abstract methods , for me the main reason i could say is doPost() or doGet() or other HTTP method than this , are just by-passing means it doesn't have any logical code in it . (This may be the main reason)
{Is it correct Bear Bibeault .}

 
Bartender
Posts: 543
4
Netbeans IDE Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HttpServlet is abstract because they don't want you instantiating it without subclassing it. Pretty much because there is no use at all. Java does a lot to protect developers from their own stupidity (checked exceptions, strong typing, ...), why shouldn't they do that here? :P
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
GenericServlet IS-A Servlet . and this GenericServlet has some common functionality/method to the Servlet class. As of Now, there is a HttpServlet which is specific to the Http protocal extends GenericServlet and uses some servlet methods. in future, pretend there is a FTPServlet which may be extends GenericServlet.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The think about HttpServlet is that while it's completely useless without overriding one of the service methods (hence making it abstract), it would be a pain to have to implement all the service methods if all you wanted was something to respond to GET requests. So that's why those methods aren't abstract.
 
This tiny ad is suggesting that maybe she should go play in traffic.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic