What happens when you run a Java Program?

Let suppose you run a Hello World program!
HelloWorld.java

public class HelloWorld(){
    public static void main(String[] args){
       System.out.println("Hello World!");
    }
}
 Compile Time :

Java Code(.java files) -------Compiler-------> Byte Code(.class files)


Before JVM(Java Virtual Machine) runs the program,the program needed to be converted to Byte-Code, which is platform independent.Compiler compiles and generates .class files if the program is error free.These class files are saved in Workspace/classpath specified

 Run Time :

Byte Code(.class files) -----Interpreter----->Executes the instructions


Now, JVM is invoked to run the byte-code.It searches for the .class file in the path/workspace and executes it.
In detail, JVM
>Classloader loads the compiled (.class files)  code,
>ByteCode Verifier verifies the bytecode ,
>Then interpreter comes into picture where it takes over the control of bytecode and converts it to machine readable instructions and executes them.




Comments

Popular posts from this blog

Sorting Algotithms

Bitwise right shift operators in Java

Program to to Merge Two sorted Linked lists in Java