DEV Community

thatanonymousgirl
thatanonymousgirl

Posted on

How Java program actually runs? What is Just in time compiler?

Java is a bit different from other types of compiled and interpreted languages.
First, a java program is compiled from source code to intermediate code called the byte code.
Java compiler does this job and javac command is used to invoke it.

This byte code is portable and can be run on any machine that has a machine specific JVM
installed on it. Now, JVM when triggered using the java command, will take line by line of this byte code and interpret it to machine code.
Here JIT comes into the picture. Even though it can optionally be disabled, it is a very useful part of JRE.

When JVM is invoked by the java command, the first thing it does is load the .class files at runtime
and then convert them into machine understandable code using an interpreter.
JIT Compiler when enabled, makes JVM analyze method calls in byte code, and if it sees any repeated code,
JIT compiles it to machine code the first time and replaces all the other occurrences directly with the machine code, hence saving a good amount of time.

Top comments (0)