What happens when you run a Java Program?
Let suppose you run a Hello World program!
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
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.
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
Post a Comment