In this article we are going to understand the Java Interpreter and learn the purpose of use of Interpreter in Java.
Java Interpreter - Java Interpreter is used for which purpose?
In this tutorial we are going to discuss the Java Interpreter which is part of Java Virtual machine. In Java the Interpreter is known as JIT (Just in time) compiler, which translates the .class file into machine code for execution on the host machine.
What is an Interpreter?
The Interpreter is a computer program that executes the program written in a high-level programming language such as Java, PHP, Python etc. For each programming language we have a different Interpreter.
Programs written in high-level programming language can be executed in two ways, first is the use of a compiler that compiles code into machine language and second is the use of Interpreter which interprets the code.
Interpreter versus Compiler
The interpreter program is used for translating the high-level code into an intermediate form. This intermediate code is executed on the host machine.
The compiler program covers the high-level programming language code to machine code. The machine code is then executed on the computer. The compiled programs usually run faster than the program executed using an Interpreter.
The machine code is compiled by compiler for a specific operating system and CPU architectures which can be executed on that is and CPU architectures. So, the compiled code is not platform independent.
The programs which are executed through Interpreter are platform independent and it can be executed on different platforms. Here the Interpreter is developed each target operating system, and the interpreter for that operating system executes the code written in high-level programming language.
What is a Java Interpreter?
In Java the Interpreter is known as Just in time compiler, which converts the Java Bytecodes into machine code. The machine code is then executed on the host machine as the computer can understand only machine code. The Java Interpreter comes with the JVM and it is an integral part of the JVM.
Since Java compiled code is converted to machine language in runtime, the Java program runs slower than the compiled machine code. Following screen shot shows the Java Compiler and Interpreter process:
Java Interpreter is used for which purpose?
The Just-In-Time (JIT) compiler is essentially an Interpreter component of the Java Runtime Environment that converts .class file into machine code.
The Java Interpreter is used by the JVM for converting the Java Bytecodes into machine code which is then executed on the host machine.
The only one work of Java Interpreter is to convert the compiled Java code from the Bytecodes (.class) file to in-memory native code (machine code) which can be run on the machine. This process is done in the runtime before the execution of a Java program.
Related Tutorials