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
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: 61222
    
  66

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]
 
 
subject: init() vs. static {}