This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes static block variable   Vs  static variable 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 » Beginning Java
Bookmark "static block variable   Vs  static variable" Watch "static block variable   Vs  static variable" New topic
Author

static block variable Vs static variable

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1371
static block loads before constructor gets executed. What about static variables outside static block(within the class) ?
Miklos Szeles
Ranch Hand

Joined: Oct 21, 2008
Posts: 142
Hi Kri,

Have you tried it? I found this:

According to one of my favorite authors, David Flanagan, author of Java in a Nutshell,

"What the compiler actually does is to internally produce a single class initialization routine that combines all the static variable initializers and all of the static initializer blocks of code, in the order that they appear in the class declaration. This single initialization procedure is run automatically, one time only, when the class is first loaded."


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38039
    
  22
The official version is in the Java™ Language Specification, but it is by no means easy to read.
 
jQuery in Action, 2nd edition
 
subject: static block variable Vs static variable
 
Similar Threads
Question on static block and static variable
How do you classify a method-local inner class defined inside a static method?
what is the difference between static variable and static block
Doubt on order of execution
final variable