jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes loading, declare,initializing,ctor order Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "loading, declare,initializing,ctor order" Watch "loading, declare,initializing,ctor order" New topic
Author

loading, declare,initializing,ctor order

donald rieck
Ranch Hand

Joined: Mar 12, 2003
Posts: 75
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

Joined: Mar 12, 2003
Posts: 5
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

Joined: Mar 12, 2003
Posts: 75
what place in the sequience are static members handled? Before any objects are created and the JVM loads the class?
jantar mantar
Greenhorn

Joined: Mar 12, 2003
Posts: 5
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: loading, declare,initializing,ctor order