Open In App

What are the Roles of Java Compiler and Interpreter?

Last Updated : 18 Aug, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Compiler and Interpreter are two different ways to translate a program from programming or scripting language to machine language. In this article let’s discuss on what are the roles of the Compiler and Interpreter in Java.

Java Compiler

A compiler in Java translates the entire source code into a machine-code file or any intermediate code, and that file is then executed. It is platform-independent. A bytecode is basically an intermediate code generated by the compiler after the compilation of its source code. Java compiler can be operated by using the “Javac.exe” command from the command prompt. Some of the compiler options are given below:

  • -help: it prints a summary of standard options.
  • -version: returns the compiler information.
  • -verbose: verbose output i.e., it includes information about each source file compiled and each class loaded.
  • -nowarn: it is used to turn off warnings. 
Java-Compiler

 

Java Compiler Step By Step

Java-Compiler-Step-by-Step

 

Roles of Java Compiler

  • It scans the complete source code in one go and then highlights the error.
  • It requires more memory to produce the bytecode.
  • It checks the correctness of the program by checking the type errors, syntax, etc.
  • It also adds some additional code to our program if required.

Java Interpreter

Similarly, an Interpreter is a computer program that converts the high-level program statement into Assembly-level language. It converts the code into machine code when the program is run. Some of the interpreter options are given below:

  • -version: displays interpreter version.
  • -verbose: displays interpreter information.
  • -help: displays interpreter options.
Java-Interpreter

 

Java Interpreter Step By Step

Java-Interpreter-Step-by-Step

 

Roles of Java Interpreter

  • To convert the bytecode into the native code of the machine.
  • This process is done line by line.
  • If the error comes on any line, the process is stopped over there.

Interpreter vs Compiler: How is Interpreter Different Than a Compiler in Java?

Here are some key differences between an interpreter and a compiler. They are as follows:

  • The interpreter scans the program line by line and translates it into machine code whereas the compiler scans the entire program first and then translates it into machine code.
  • The interpreter shows one error at a time whereas the compiler shows all errors and warnings at the same time.
  • In the interpreter, the error occurs after scanning each line whereas, in the compiler, the error occurs after scanning the whole program.
  • In an interpreter, debugging is faster whereas, in the compiler, debugging is slow.
  • Execution time is more in the interpreter whereas execution time is less in the compiler.
  • An interpreter is used by languages such as Java, and Python, and the compiler is used by languages such as C, C++, etc.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads