Java Compilation Process Explained

Java Compilation Process Explained

So today in this post I will explain how the java compilation process works.

What is Compilation?

So before we get into the Java compilation process, we need to know what compilation exactly is. The process of converting source code written by the programmer into machine understandable or machine code is called compilation.

The machine code that is converted also depends on the platform, which means different platforms have different machine code but the source code remains unchanged and so does the output of the source code meaning the machine code may be different for different systems but the output generated by the source code is same for all systems for the same source code.

How It Works

Programs written in Java are compiled into machine language but it is a machine language for a virtual machine called JVM which stands for Java Virtual Machine.

The machine language used by JVM is called Java Bytecode.

The Bytecode still needs an interpreter to execute regardless the platform.

The interpreter called JIT compiler which stands for Just In Time compiler translates the native code on the host computer on which the code is to be executed.

NOTE: JIT is a part of JVM.

Diagram

Here is a diagram explaining the whole Java compilation process for better understanding.

Screenshot 2022-05-08 212631.png