What is Java Compiler | How works it

Java Compiler and Interpreter are the most fundamental tools in Java language that programmers use during programming.

A compiler in Java is a computer program that is used for compiling Java programs. It is platform-independent. It converts (translates) source code (.java file) into bytecode (.class file).

In other words, the compiler (javac.exe) generates bytecode during the compilation process.

A bytecode is a binary code that is understood and interpreted by Java Virtual Machine (JVM) on the underlying operating system. It is not similar to machine code.

It is unreadable by humans because it is composed of numbers that are the only language that computers understand.

Java compiler can be activated by using “Javac.exe” command from the command prompt. Some of the compiler options are as follows:

  • -help: Display all the compiler option.
  • -version: Returns the compiler version.
  • -verbose: Output compiler messages.
  •  –deprecation: Identify retired APIs.
  • –nowarn: Generate no warnings.

The compiler options are case-sensitive. A screenshot of complete Java compiler options is as follows:

A complete Java compiler options

Responsible tasks for Compiler

Java compiler is responsible for the following tasks that are as follows:

a) Java compiler checks the syntaxial error (Syntax error).

b) It converts source code into byte code with the help of Java Virtual Machine (JVM).

c) It also adds the additional code to your program if required.

How does Java compiler work?

How Java compiler works

We can see in the above figure, where Java source code written by the programmer is compiled by javac and then generates java bytecode (.class file) that is automatically saved on the disk with file extension .class.

This .class file is then ​interpreted and executed by JVM at runtime on the underlying operating system.

Hope that this tutorial has covered all the important points related to Java compiler. I hope that you will have understood the basic points of compiler and its responsible tasks.
Thanks for reading!!!
Next ⇒ Interpreter in Java

⇐ Prev Next ⇒