An interpreter performs the following function:
next → ← prev Show
Java is a platform-independent programming language. It means that we can run Java on the platforms that have a Java interpreter. It is the reason that makes the Java platform-independent. The Java interpreter converts the Java bytecode (.class file) into the code understand by the operating system. In this section, we will understand what is an interpreter in Java, the features of the interpreter, and how does the Java interpreter work. We will also see how it is different from a compiler. What is an interpreter in Java?Java interpreter is a computer program (system software) that implements the JVM. It is responsible for reading and executing the program. It is designed in such a way that it can read the source program and translate the source code instruction by instruction. It converts the high-level program into assembly language (machine language). How does the Java interpreter work?To convert the byte code into machine code, we deploy the .class file on the Java Virtual Machine (JVM). The JVM converts that code into machine code using the Java interpreter. The JVM uses the interpreter at runtime, after that it execute the code on the host machine. As the Java compiler compiles the source code into the Java bytecode. In the same way, the Java interpreter converts or translates the bytecode into the machine-understandable format i.e. machine code, after that the machine code interacts with the operating system. If the JVM is installed on any system it means that the platform is JVM enabled. The platform performs all the tasks of the Java run-time system. It loads the Java class file and interprets the compiled byte-code. The browsers, like Google Chrome, Netscape, etc. are the popular example that contains the Java interpreter. It means these are Java-enabled browsers. It is used to run the Applet in the browser. The interpreter also serves as a specialized compiler in an implementation that supports dynamic or just-in-time (JIT) compilation which turns the Java bytecode into native machine instructions. Let's see how an interpreter loads a Java program. First, we specify the class by using the java command followed by the class name and options available for the interpreter, and command-line arguments if required. We use the following command to load the class: In the above command, the class name should be a fully qualified name (the name of the class that includes the package name, if any). Remember that, we do not write the .class extension at the end of the class name. For example: In the first command, Product is the class name. In the second command, com.javatpint.product is the name of the package in which the Mobile class is stored. Once the class is loaded, Java follows a convention and searches for the class that contains the main() method. When the JVM founds the main() method, the interpreter starts the application by invoking the main() method. After executing the main() method, additional threads, and references other classes. Features of InterpreterIt converts the source code into machine language, line by line at run time, without changing the sequence.
Difference Between Interpreter and CompilerIn the following table, we have summarized the key differences between an interpreter and a compiler.
Next Topicjavac is not Recognized ← prev next → A compiler is a computer program that transforms code written in a high-level programming language into the machine code. It is a program which translates the human-readable code to a language a computer processor understands (binary 1 and 0 bits). The computer processes the machine code to perform the corresponding tasks. A compiler should comply with the syntax rule of that programming language in which
it is written. However, the compiler is only a program and can not fix errors found in that program. So, if you make a mistake, you need to make changes in the syntax of your program. Otherwise, it will not compile. An interpreter is a computer program, which converts each high-level program statement into the machine code. This includes source code, pre-compiled code, and scripts. Both compiler and interpreters do the same job which is converting higher level
programming language to machine code. However, a compiler will convert the code into machine code (create an exe) before program run. Interpreters convert code into machine code when the program is run. KEY DIFFERENCE
Difference Between Compiler and Interpreter
Role of Compiler
Also Check:- Compiler Design Tutorial for Beginners Role of Interpreter
HIGH-LEVEL LANGUAGESHigh-level languages, like C, C++, JAVA, etc., are very near to English. It makes programming process easy. However, it must be translated into machine language before execution. This translation process is either conducted by either a compiler or an interpreter. Also known as source code. MACHINE CODEMachine languages are very close to the hardware. Every computer has its machine language. A machine language programs are made up of series of binary pattern. (Eg. 110110) It represents the simple operations which should be performed by the computer. Machine language programs are executable so that they can be run directly. OBJECT CODEOn compilation of source code, the machine code generated for different processors like Intel, AMD, and ARM is different. To make code portable, the source code is first converted to Object Code. It is an intermediary code (similar to machine code) that no processor will understand. At run time, the object code is converted to the machine code of the underlying platform. Java is both Compiled and Interpreted.To exploit relative advantages of compilers are interpreters some programming language like Java are both compiled and interpreted. The Java code itself is compiled into Object Code. At run time, the JVM interprets the Object code into machine code of the target computer. Also Check:- Java Tutorial for Beginners: Learn Core Java Programming What functions does an interpreter perform?An interpreter is a speech professional who translates messages from one language to another so that various groups of people can understand the message and communicate with one another. Interpreters are usually fluent in both the spoken and translated languages they interpret.
What is the main function of the computer interpreter?In computer science, an interpreter is a computer program that directly executes instructions written in a programming or scripting language, without requiring them previously to have been compiled into a machine language program.
What are the three examples of interpreter?An Interpreter directly executes instructions written in a programming or scripting language without previously converting them to an object code or machine code. Examples of interpreted languages are Perl, Python and Matlab.
Which of the following functions does an interpreter perform with the instructions from a highIntroduction to Programming 01. |