Difference between JRE JDK JVM

In this post we will see about one of most common Java interview question for all level of Java developers, which is Tell me the “Difference between JRE JDK JVM”.

JRE – Java Runtime Environment:

To execute the program, JRE is enough. JRE contains JVM and other libraries. JRE will not have any development tools like compiler or debugger. JRE must be installed to execute any Java program.

Difference between JRE JDK JVM -  JRE Architecture

Difference between JRE JDK JVM – JRE Architecture

 

JDK – Java Development Kit:

JDK is a combination of development tools (like compiler, launcher and debugger) and JRE. With the help of development tools, we can develop a java program and compile it (using compiler). With the help of JRE we can execute it.

Difference between JRE JDK JVM - JDK Architecture

Difference Between JRE, JDK and JVM – JDK Architecture

Compiler in the JDK converts java code (.java) into byte code (.class) and in JRE with the help of JVM byte will be converted into machine code and executes it.

JDK must be installed if we want to write code, compile it and execute it.

JRE is enough if we only want to execute the code and not going to write any code.

JVM – Java Virtual Machine:

Java code (.java) will be converted into byte code (.class) using Java Compiler. Those machine code can’t be executed directly in a machine. It needs to be converted into machine code to execute it. JVM understands the byte code and convert into machine code to execute it.

JVM executes by converting the bytecode to machine code. JVM has built in interpreter and JIT Compiler both helps in converting the bytecode to machine code.

Interpreter converts each bytecode to native code/instruction. Here conversion means it maps the bytecode to corresponding native code.

JIT (Just In Time Compiler) analyze/understand the similar functionality byte code, optimize it and convert into machine code. Here similar functionality code converted by which it improves the time of compilation.

Additional Details of JVM

JVM is platform independent. JVM is a specification that provides runtime environment in which byte code will be executed. Many companies provide implementation of JVM, but Oracle HotSpot is most popular one.

 

Difference between JRE JDK JVM

To summarize, JRE is used to only to execute the program, JDK is used to code and execute the program and JVM is used to convert the convert bytecode to machine code and executes it. JVM is the subsystem of JRE. JRE is the subsystem of JDK.

 

References

JDK Architecture

 

Leave a comment

Your email address will not be published. Required fields are marked *