Sunday 18 May 2014

What happen while execute the java program ?


Virtual machine start-up

      A Java virtual machine starts execution by invoking the method main of some specified class, passing it a single argument, which is an array of strings. 
     
d:\app1\src\>java Test

   The steps the virtual machine may take to execute Test class are loading, linking, and initialization processes that are described further in this section.


Load the Class

    To execute the main method  of  Test class discovers that the class Test is loaded or not means that the virtual machine currently contain a binary representation for this class or not .If class not loaded then ,the virtual machine uses a class loader to attempt to find such a binary representation. If this process fails, then an error is thrown.
 
Link : Verify, Prepare

   Verification checks that the code that implements Test obeys the semantic requirements of the Java programming language and the Java virtual machine. If a problem is detected during verification, then an error is thrown.
  Preparation involves allocation of static storage and any data structures that are used internally by the virtual machine, such as methods.

Initializ : Execute Initializers

  Initialization consists of execution of any class variable initializers and static initializers of the class Test.But before Test can be initialized, its direct superclass must be initialized, as well as the direct superclass of its direct superclass, and so on.

Invoke : main method

   Finally, after completion of the initialization for class Test (during which other consequential loading, linking, and initializing may have occurred), the main method of Test is invoked. The method main must be declared publicstatic, and void. It must accept a single argument that is an array of strings. This method can be declared as


public static void main(String[] args)


0 comments :

Post a Comment