Welcome to Codefind4you !

Follow Me


By  Kasun Thilina     5:50 AM    Labels:, 

Different between Interpreter, Compiler ,JIT  and How 

Java works.


Executing Programs

  • Computer can only execute the code in binary form.
  • A program written in a high –level language is called a source program or source code.
  • Because a computer cannot understand a source program, a source program must be translate into machine code for execution.
                 Source code – Written in high-level language
                 Machine code –Computer processor can understand
  • The translation can be done using another programming tool called an Interpreter or Compiler (So this interpreter and compiler are normally used to translate the code from one form to another form )


What is Compiler

A compiler is a program. It translates the entire source code into a machine code file or any intermediate code and that file is then executed.

What is Interpreter

An interpreter is a program. It reads one statement from the source code, translates it to the machine code or virtual machine code and the executes it right away.


How Java Works

In case of Java, compiler will convert the source code (.java file) to an intermediate code (byte-code / .class file) that the java virtual Machine can understand (JVM /Interpreter).The JVM convert intermediate code (byte-code / .class file) into machine code.
(In the java, javac is used to convert source code to intermediate code. javac-java compiler).

Let us see the below example



Just In Time Compiler (JIT)

Above you can see that we have 6 statements which 3 of them are redundant. Compiler (javac) compile the source code to byte-code. Now, when we run the program, the interpreter translate line by line.

The compile code, intermediate code, byte-code or .class file will go through the JIT compiler and optimize code. In this case, line 4, 5, 6 are redundant and JIT compiler will not this code as redundant. So when the file gets the interpreter, the interpreter will now know the code in line number 4 is going to come again.so, it’s store machine code of line number 4 somewhere in computer memory and when it comes the same piece of code again, it is simply tells the computer to run machine code directly without translating .This phenomenon is called JIT compilation and this significantly improve performers.  

JVM-This is platforms dependent. So, Windows, mac, Linux, etc… platforms specific JVM’s are capable of executing that same java byte-code in the same way.  





No comments:

Post a Comment


Contact Form

Name

Email *

Message *

Translate