File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes static block Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "static block" Watch "static block" New topic
Author

static block

Vallabhaneni Suresh Kumar
Ranch Hand

Joined: Mar 01, 2004
Posts: 68
What is the purpose of static block and what does it mean?

Thank you
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
You're probably familiar with how static variables are initialized the first time you reference a class (when the class is loaded). Static blocks are executed at the same time. That gives you a neat way to do a little more work than a single initial value. For example:

We could even move all those states into a static method and call it from the static block. Neat, huh?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: static block
 
Similar Threads
I hate NullPointerExceptions!
what is the difference between static variable and static block
What is the use of static block
static block
static block variable Vs static variable