Skip to main content

Java Compilation Process



java compiler image

WORA


Before knowing how java compilation works,We have to know something called WORA - Write Once and Run Anywhere.

Java compilation works like a kind of WORA , we can write java code once and we can compile that in different platforms with JRE(java runtime environment)
java compiler image
JAVA COMPILATION PROCESS    FIG-1

As show in the FIG-1 only JRE can understand the ByteCode, N


Source Code

The code written by developer are said to be the source code.In this case code written in java is stored in a file name with the extension    .java  

 
class Simple{  
    public static void main(String args[]){  
     System.out.println("Hello Java");  
    }  
} 

Save this file as    mycode.java  

Javac

Javac is just a  compiler for compiling java programs,It cannot execute the source code ,Its purpose is only to check and return error if any syntax error is found ,Else it compiles and produce the bytecode with the extension    .class  

For instance if we compile mycode.java the output will be    mycode.class  

Byte Code

After successful compilation of a java program Byte code is generated.Byte code is just a intermediate code.   No platforms can understand ByteCode  Only JRE can understand this ByteCode. ByteCode is common for different platforms,But JRE is different for different platforms.




JRE- Java Runtime Environment

JRE is a tool or kind of Execution Engine which execute ByteCode,It cannot understand Java Programs rather it can only understand Byte Code. Only JRE cannot compile a java program(source program)  because it does not have a compiler.

Now you have a question arises in your mind "Then what is JDK" ?

JDK- Java Development Kit

JDK is a kind of kit which contains all the Tools and Essentials for the development of java application. JDK is an SDK (Software development Kit) which is specific for java applications. 
JDK internally contains JRE and also many essentials
learn java

Then what is JVM ?

Java Virtual Machine is kind of specification or procedure by which  JRE is developed. Sometimes JVM is also called as JVM. Oracle provides a open source platform by which anyone create their own JRE for their platform by use of JVM. It can be said that JRE is a physical implementation of JVM.

Dowload JDK8 :
 

Comments