wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes init() method usage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "init() method usage" Watch "init() method usage" New topic
Author

init() method usage

Harikrishna Gorrepati
Ranch Hand

Joined: Sep 23, 2010
Posts: 422
Hi, I am trying to understand the difference between these init() methods as given in the comments.


OCPJP 6.0-81% | Preparing for OCWCD
http://www.certpal.com/blogs/cert-articles | http://sites.google.com/site/mostlyjava/scwcd |
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1636
    
  23

Hi Harikrishna,

The javax.Servlet Interface consists of a method called init(ServletConfig sc), which is used to save the ServletConfig object in the Servlet so that you can access some init parameters and so on.

The GenericServlet implements the javax.Servlet which means that it has to implement the init(ServletConfig sc) method. As a convenience to the Servlet programmers (like us) they dicided to add a init() method.

When we write our own Servlet and we want to do some initialization we only have to override the init() method and all the default initialization (saving the ServletConfig object) is taken care of. GenericServlet.init(ServletConfig sc) is called by the servlet container and that method actually calls GenericServlet.init() method.

Regards,
Frits
 
Consider Paul's rocket mass heater.
 
subject: init() method usage
 
Similar Threads
Hibernate Problem
why super.init() is used??
Which one gets first executed ?????????
Code error
Hit management in j2ee