There are mainly 3 steps involved in creation of java object
Those are
1.loading
2.Instantiating
3.Initializing
Assume that we have a class with name "Employee" and now that we want to create an object for it.
The statements that we will write is
statement 1: Employee emp;
statement 2: emp=new Employee();
In statement 1 it will create a reference with emp in the stack Area but its not the object of Employee class.
In statement 2 the actual process starts :
LOADING :
As the Employee class exists in the hard disk (secondary storage) it will be loaded into the main memory(RAM)
INSTANTIATING:
Once the loading is done it will allocate the memory for the non static members of the class in the
heap.
INITIALIZING:
Once the memory is allocated then the data members will be intialized with default values
provided by JVM.
Upon Completion of the above 3 steps the address of the object will be stored in a hash table
along with index and this index will be stored in the reference variable emp.
Those are
1.loading
2.Instantiating
3.Initializing
Assume that we have a class with name "Employee" and now that we want to create an object for it.
The statements that we will write is
statement 1: Employee emp;
statement 2: emp=new Employee();
In statement 1 it will create a reference with emp in the stack Area but its not the object of Employee class.
In statement 2 the actual process starts :
LOADING :
As the Employee class exists in the hard disk (secondary storage) it will be loaded into the main memory(RAM)
INSTANTIATING:
Once the loading is done it will allocate the memory for the non static members of the class in the
heap.
INITIALIZING:
Once the memory is allocated then the data members will be intialized with default values
provided by JVM.
Upon Completion of the above 3 steps the address of the object will be stored in a hash table
along with index and this index will be stored in the reference variable emp.