Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

loading, declare,initializing,ctor order

 
donald rieck
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create a class.
Class is loaded by the JVM.
Class members are declared and initialized by the JVM.
Object is declared(instantained?) by the new.
Memory is allowcated by the new?(not the ctor)
Proper constructor is invoked by the new.
constructor then initializes object level variables?
is this how it goes?
I need help on this: info , books....
[ March 12, 2003: Message edited by: donald rieck ]
[ March 12, 2003: Message edited by: donald rieck ]
 
jantar mantar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Donald,
To some extent, you are right.
create a class. Ok
class is loaded by the JVM. Ok
class variables are declared and initialized-then. Ok
new is implemented - then. Unlike C++ or C, In Java, we never implement the new method. We only write the ctor (overloaded, if required.)
object is declared(instantained?) by the new.
memory is allowcated by the new.
After the memory allocation, the object level variables are automatically initialized to their defaults. ex : if we have private int iPrivateObjectLevelVariable, then this variable by default gets the value 0
constructor is called by the new.
object is initialized by the constructor. This does not happen. After the previous step, move directly to the next step.
instance variables are initialized by the c-tor.
Ok
is this how it goes?
I need help on this: info , books....
I dont know of any book that might contain all this information, however, using SOP's (System.out.println) you may get some answers.
Hope this helps.
'amit
 
donald rieck
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what place in the sequience are static members handled? Before any objects are created and the JVM loads the class?
 
jantar mantar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
static member as you know are class level variables. Thus they are initialized when the class is first loaded in the JVM.
However, you may use static initialization block , in case you need to initialize these variable differently.
Core Java Part - I, a book by Sun's Press, details this.
'amit
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic