aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes regarding init() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "regarding init() method" Watch "regarding init() method" New topic

regarding init() method

Chaitanya Vivek
Ranch Hand

Joined: May 17, 2006
Posts: 36
Its on Page#102 of HFSJ.

why is there an init()method? Why is not a constructor enough for initializing a servlet?

Exprts, pls let me know the answer.
John Lincoln
Ranch Hand

Joined: Feb 11, 2003
Posts: 192
Because init does more than just instantiating the servlet. It does all the pre-work like setting up database connection any specific configurations required for the servlet.


Chaitanya Vivek
Ranch Hand

Joined: May 17, 2006
Posts: 36
Also init() method gives the servlet access to the ServletConfig and ServletContext objects, which the servlet needs to get info abt the servlet config and the web app.

thanks for the reply!
subject: regarding init() method
Similar Threads
difference b/w init() and init( config)
Why Init() method
Difference between init and servlet constructor
java.sql.SQLException: Closed Connection
Why Init Method, why can't we use constructor instead?