Java JDK, JVM, JRE, JIT




Before going into more details of Java, it is important to understand core of Java. Let’s dive into concepts like JVM, JIT, JDK, JRE.


JVM (Java Virtual Machine)


The name JVM explains itself. It is a virtual machine that executes Java code. As it’s a virtual machine it can be installed on any other physical machine.
JVM is responsible for allocating and deallocating memory space to program.
Do you know
JVM is written in C language. It is operating system dependent.

How JVM works


 


1.     Compiler converts java source code into bytecode. 
2.     Byte code is then loaded into JVM. 
3. In a JVM, each and every class is loaded by some instance of a java.lang.ClassLoader.
4.     Then bytecode verifier traverses the bytecode, constructs the type state information, and verifies the types of the parameters to all the bytecode instructions. The bytecode verifier acts as a sort of gatekeeper: it ensures that code passed to the Java interpreter is in a fit state to be executed and can run without fear of breaking the Java interpreter.
5.     JIT interprets parts of bytecode and try optimizing code performance by replacing original instructions by similar but efficient native instructions.
6.     Once JIT optimized code, interpreter reads bytecode and converts it into machine instructions and sends to operating system.
7.     OS kernel then executes instruction on underlined hardware.


Do you know: why Java called as platform independent language?
Before going into the detail, first you have to understand what is the mean of platform? Platform consists of the computer hardware (mainly architecture of the microprocessor) and OS. Platform=hardware +Operating System.

Anything that is platform independent can run on any operating system and hardware.

Java is platform independent so java can run on any operating system and hardware. Now question is how it is platform independent?

This is because of the magic of Byte Code which is OS independent. When java compiler compile any code then it generate the byte code not the machine native code (unlike C compiler).Now this byte code need a interpreter to execute on a machine. This interpreter is JVM. So JVM read that byte code (that is machine independent) and execute it. Different JVM is designed for different OS and byte code is able to run on different OS.
In case of C or C++(language that are not platform independent) compiler generate the .exe file that is OS dependent so when we run this .exe file on another OS it will not run because this file is OS dependent so is not compatible with the another OS.
Finally, an intermediate OS independent byte code makes the java platform independent.


Just In Time Compiler (JIT)

To learn JIT detail visit my blog Java code's lifecycle : Everything you should know (Click here to visit) and check Just In Time Compiler section.

JRE (Java Runtime Environment)

 

The name JRE self explains its role i.e. to provide runtime environment to executing Java code.

JRE provides minimum requirements to run java application.

As shown in diagram it consists of Java Virtual Machine (JVM), core classes and supporting files.

 



JDK (Java Development Kit)

It is a software development environment used for developing Java applications and applets.

As shown in diagram, JDK includes the Java Runtime Environment (JRE), a compiler (javac), an interpreter (Java), a documentation generator (Javadoc), an archiver (jar) and other tools required in development.

 

Difference between JDK, JRE and JVM :

JDK : JDK provides environment to develop and run java code. It consists of :

·        Development tools (for development)

·        JRE (for execution)

JRE : It provides environment to only run Java program. It is useful for end user of system who has no concern with development work.

JVM : It is important for both JVM and JRE and contained in both as shown in diagram. Java program executed using JDK or JRE goes to JVM, which acts as interpreter and executes code line by line.

 

How java code flows through these parts:

In my blog “Java code lifecycle : Everything you should know” (click here to visit), I have explained whole lifecycle of java code in detail with real world examples.

 


No comments:

Post a Comment

Operators in Java

Operator is a symbol which is used to perform operation on data. Eg. +,-,/,* etc. Do you know : Operator and operan...

Popular