• Post Reply Bookmark Topic Watch Topic
  • New Topic

static data initialization  RSS feed

 
shubham agarwal
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not getting this concept.



Static data initialization

When the data is static, the same thing happens; if it’s a primitive and you don’t initialize it, it gets the standard primitive initial values. If it’s a reference to an object, it’s null unless you create a new object and attach your reference to it..
.My question is when the static storage gets initialized. and how will get exact output.

this is link.
source: http://www-plan.cs.colorado.edu/diwan/3308-05/book/TIJ306.htm
topic: Static data initialization

 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In summary, static initialization occurs when:

  • an instance of the class is created
  • a static method of the class is invoked
  • a static field of the class is assigned
  • a non-constant static field is used

  • Programmatically, you can also use Class.forName(String)
     
    Winston Gutkowski
    Bartender
    Posts: 10575
    66
    Eclipse IDE Hibernate Ubuntu
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    shubham agarwal wrote:My question is when the static storage gets initialized.

    When the class is loaded.

    My question to you: How do you think knowing this is going to help you?

    The simple fact is that the only time you're NOT going to know what's in a field is when you haven't initialised it, so surely the simplest solution is to always initialise static fields?

    Personally, I'd also make them final - but that's another subject.

    Winston
     
    shubham agarwal
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    thankyou james and winston
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!