aspose file tools*
The moose likes Servlets and the fly likes init() vs. static {} Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "init() vs. static {}" Watch "init() vs. static {}" New topic
Author

init() vs. static {}

Herbert Wilson
Greenhorn

Joined: Nov 18, 2003
Posts: 3
What is the difference between using an init() method as opposed to a static block in a servlet? They both are called once when the servlet is loaded.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60048
    
  65

Big difference.
The static block is executed when the class is loaded. The init method is called by the container once important structures like the servlet context and the servlet config have been created and are available for the init() method to peruse.
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: init() vs. static {}
 
Similar Threads
init missing in servlet
Is init() really called once
purpose of init method
Application Resources.properties
why static should be avoided with web app?