Sunday, September 8, 2013

Steps involved during Execution of a Java Program

  1. JVM startup
  2. Loading – finding binary representation of class/interface then constructing the Class object
  3. Linking – combining class/interface into the run-time state of the JVM so that it can be executed
    1. Verification - semantic/structure validation
    2. Preparation - storage allocation, all static fields are created and initialized with default values
    3. Resolution – optionally resolve symbolic reference to other classes/interfaces
  4. Initialization – static initialization 
    1. superclass/superinterface static initialization
      • superclasses are initialized before subclasses
      • interface initialization does not initialize superinterfaces
      • only the class that declares static field is initialized, even though it might be referred to through the name of a subclass, a subinterface, or a class that implements an interface
    2. all static explicit field initializers and static initialization blocks are executed in textual order
  5. Instantiation - creation of object/class instance
    All the instance variables, including those declared in superclasses, are initialized to their default values first.
    1. start the constructor
    2. call explicit constructor this() if available
    3. call explicit/implicit super() unless class is Object – process recursively using same steps a. to e. 
    4. all non-static field initializers and non-static initialization blocks are executed in textual order
    5. execute the rest of the body of constructor
  6. Finalization – finalize() method is called before storage for object is reclaimed by GC
  7. Unloading – happens if its classloader is reclaimed by GC. Bootstrap loader may not be unloaded.
  8. Program Exit

No comments:

Post a Comment