Java Interpreter And JITC

Java Interpreter And JITC(Just In Time Compiler) are the two important Translators which JVM(Java Virtual Machine) contains apart from garbage collector and other important tools

Interpreter V/s JITC

Originally java only had an interpreter which simply converted bytecode to machine language and sends it for execution to the computer.

As we know interpreters convert line by line, so the java interpreter converts one line of bytecode to machine language and sends it for execution to the computer.

Then it repeats the same process for line 2

Q-Is there a problem in this approach?

Yes, because if an instruction needs to be executed 100 times (for example inside a loop) then the interpreter needs to convert it 100 times.

First example:

Second example:

In the second example the interpreter will have to convert the statement print a; 100 times since it is running inside a loop

Solution is JITC !

To solve this problem the developers at SUN came up with a new idea.

They thought if a statement has to be executed multiple times then why not save the converted code in computer’s memory and then next time just execute it without converting it.

That is in the previous code , the statement print a; which is inside the loop would be converted only once and saved in computer’s memory and remaining 99 times it is just executed !.

This is called JITC(Just In Time Compiler) and the statements which have to be executed multiple times are called HotSpots and thus SUN’s JVM is also called HotSpot JVM

Are java compiler and JITC same?

No , not at all.

The java compiler converts source code to bytecode and is not a
part of JVM , rather it comes with JDK.

The JITC lives inside the JVM and converts bytecode to machine
understandable form

Java Interpreter And JITC