JDK vs JRE vs JVM

A program written in a high-level language cannot be run on any machine directly. First, it needs to be translated into that particular machine language. The javac compiler does this thing, it takes a java program (.java file containing source code) and translates it into machine code (referred to as byte code or .class file).

Java Virtual Machine (JVM) is a virtual machine that resides in the real machine (your computer) and the machine language for JVM is byte code. This makes it easier for the compiler as it has to generate byte code for JVM rather than different machine codes for each type of machine. JVM executes the byte code generated by the compiler and produces output. JVM is the one that makes the java platform independent.

What is JVM?

JVM is an engine that provides a runtime environment to drive the Java Code or applications. It converts Java bytecode into machine language. JVM is a part of the Java Run Environment (JRE). It cannot be separately downloaded and installed. To install JVM, you need to install JRE. The full form of JVM is Java Virtual Machine.

In many other programming languages, the compiler produces machine code for a specific system. However, Java compiler produces code for a virtual machine which is called as JVM.

JVM Architecture

jvm architecture
Image Courtesy: Beginnersbook.com


Let’s see how JVM works:

Class Loader: The class loader reads the .class file and save the byte code in the method area.

Method Area: There is only one method area in a JVM which is shared among all the classes. This holds the class level information of each .class file.

Heap: Heap is a part of JVM memory where objects are allocated. JVM creates a Class object for each .class file.

Stack: Stack is a also a part of JVM memory but unlike Heap, it is used for storing temporary variables.

PC Registers: This keeps the track of which instruction has been executed and which one is going to be executed. Since instructions are executed by threads, each thread has a separate PC register.

Native Method stack: A native method can access the runtime data areas of the virtual machine.

Native Method interface: It enables java code to call or be called by native applications. Native applications are programs that are specific to the hardware and OS of a system.

Garbage collection: A class instance is explicitly created by the java code and after use it is automatically destroyed by garbage collection for memory management.

JVM
Image Courtesy: Beginnersbook.com

What is JRE?

There’s no content to show here yet.

JRE is a piece of a software which is designed to run other software. It contains the class libraries, loader class, and JVM. In simple terms, if you want to run Java program you need JRE. If you are not a programmer, you don’t need to install JDK, but just JRE to run Java programs. Though, all JDK versions comes bundled with Java Runtime Environment, so you do not need to download and install the JRE separately in your PC. The full form of JRE is Java Runtime Environment.

JRE

What is JDK?

JDK is a software development environment used for making applets and Java applications. The full form of JDK is Java Development Kit. Java developers can use it on Windows, macOS, Solaris, and Linux. JDK helps them to code and run Java programs. It is possible to install more than one JDK version on the same computer.

JDK
Image Courtesy: Beginnersbook.com

References:

1. https://www.geeksforgeeks.org/differences-jdk-jre-jvm

2.https://www.ibm.com/cloud/blog/jvm-vs-jre-vs-jdk

3.https://beginnersbook.com/2022/06/jdk-vs-jre-vs-jvm-difference-between-them/

Image Courtesy: Beginnersbook.com

Design a site like this with WordPress.com
Get started