aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes init() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "init() method" Watch "init() method" New topic
Author

init() method

Atul Sawant
Ranch Hand

Joined: Jul 06, 2006
Posts: 304
It is adviced to override init() method but if you are overriding init(ServletConfig) then we need to call super.init(ServletConfig). Why?

I learned that init() is called in init(ServletConfig) of super class so that it can give servletness to the servlet. If that is the case then we can override any init method and then call super.init() so that the servletness of the servlet is gained.

Please let me know if i am unclear.

Thanks for your answer(s)!


Mission SCWCD. Mission SCJP Complete: SCJP 1.4 - 91%
Clifton Eaton
Greenhorn

Joined: Mar 26, 2007
Posts: 16
Originally posted by Atul Sawant:
It is adviced to override init() method but if you are overriding init(ServletConfig) then we need to call super.init(ServletConfig). Why?


the important reason to call super.init(ServletConfig) is that it sets the ServletConfig object in the servlet. If you overide init(ServletConfig)without calling super.init(SC) You would not be setting the ServletConfig object.


-------------------------------------<br />SCJP<br />SCWCD
Atul Sawant
Ranch Hand

Joined: Jul 06, 2006
Posts: 304
Thanks Clifton. One more basic question on this. Which method does the container implicitly calls if you have not overrided any init() method from superclass? init() or init(ServletConfig)?
[ April 10, 2007: Message edited by: Atul Savant ]
Tridib Samanta
Ranch Hand

Joined: Apr 28, 2004
Posts: 128
Container calls both the method. It will call init(confi) followed by init(). If you don't override init(), the default implementation will be called and the default implementaion of init() does nothing.
The container calls init() from inside init(config) method.
[ April 10, 2007: Message edited by: Tridib Samanta ]

Thanks, Tridib
SCJP 1.4, SCWCD 1.4, SCBCD 5.0
 
Consider Paul's rocket mass heater.
 
subject: init() method