So why do we have two init methods? A good question.
Servlet interface defines only 1 init method. This init method takes ServletConfig object as a parameter.(void init(ServletConfig config)) When it loads a new servlet for the first time, the Container creates this Servlet and calls the init() method for initialization passing it the ServletConfig object which the servlet can store and use it later. (ServletConfig contains useful information for the servlet, like the initialization parameters of the servlet mentioned in the DD web.xml etc.....).
But our friendly Generic Servlet implements the Servlet interface and provides us with 2 methods:
1. init()
2. init(ServletConfig config) method.
The implementation/code also for both the above 2 methods has been provided by GenericServlet!
1. init() method is a blank method.
2. init(ServletConfig config) method stores the ServletConfig object in the Servlet so that we could retrieve it later when we call getServletConfig().
It then calls the other init() method which is the blank method.
Now in our Servlet class which extends HttpServlet, if we wish to do some initialization, we just override init()
void init() {
.....put our initialization code.....
}
The Container after loading the Servlet for the first time, always calls the init(ServletConfig) method. Since we wouldn't have implemented the init(ServletConfig) method, the GenericServlet's implementation of the method gets called which in turn calls our method init() method. So this is a just a covenience method!
If there was only one init(ServletConfig config) method provided in GenericServlet then, our code init method would like this:
void init(ServletConfig config) {
super.init(config);
.....put our initialization code.....
}
Does that make any sense or did I confuse you further?

[ May 19, 2005: Message edited by: Vishwa Kumba ]