aspose file tools
The moose likes Servlets and the fly likes init() vs. static {} Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply 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: 56160
    
  13

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


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: init() vs. static {}
 
Similar Threads
why static should be avoided with web app?
init missing in servlet
purpose of init method
Is init() really called once
Application Resources.properties