Java JVM, JRE and JDK Explained with Diagrams


In this chapter, we will discuss an important definition of JVM, JRE, and JDK in the Java programming language. We also discuss the difference between JVM, JRE, and JDK.

Java technology is both a programming language and a platform. The Java programming language is a high-level object-oriented language that has a particular syntax and style. A Java platform is a particular environment in which Java programming language applications run.

Let's start with what is JDK?

1. JDK(Java Development Kit)

The JDK(Java Development Kit) is a superset of the JRE and contains everything that is in the JRE, plus tools such as the compiler, debugger, JavaDoc, keytool etc necessary for developing and running Java programs or applications.

The below diagram shows JDK (Java Development Kit) is a software development kit that contains everything that is in the JRE, plus tools such as the compiler, debugger, JavaDoc, keytool etc necessary for developing and running Java programs or applications.
JDK is a platform-specific software and that’s why we have separate installers for Windows, Mac, and Unix systems. For example, if you navigate to the Java download page at https://www.oracle.com/in/java/technologies/javase-downloads.html, you will see different installers for different operating systems (Windows, Linux, Mac etc):

2. JVM (Java Virtual Machine)

JVM is a very important component of Java programming language. When you run the Java program, the Java compiler first compiles your Java code to bytecode. Then, the JVM translates bytecode into native machine code (set of instructions that a computer's CPU executes directly).

JVM translates the byte-code into machine language, and since the machine language depends on the operating system being used, it is clear that the JVM is platform (operating system) dependent.

JVM is called virtual because it provides an interface that does not depend on the underlying operating system and machine hardware.


If you are interested in learning about JVM Architecture, visit The JVM Architecture Explained.

3. JRE(Java Runtime Environment)

The Java Runtime Environment (JRE) provides the libraries, the Java Virtual Machine, and other components to run applets and applications written in the Java programming language.

JRE doesn’t contain any development tools such as Java compiler, debugger, JShell, etc.

If you just want to execute a java program, you can install only JRE. You don’t need JDK because there is no development or compilation of java source code is required.

The below diagram shows the JRE (Java Runtime Environment) is a software package that provides Java class libraries, along with Java Virtual Machine (JVM), and other components to run applications written in Java programming.

JRE = JVM + Java Packages Classes (like util, math, lang, awt, swing etc) + runtime libraries.

4. JDK vs JRE vs JVM 

Let’s look at some of the important differences between JDK, JRE, and JVM.
  1. JDK is for development purposes whereas JRE is for running the java programs.
  2. JDK and JRE both contain JVM so that we can run our java program.
  3. JVM is the heart of Java programming language and provides platform independence.
The below diagram shows the relationship between JVM, JRE, and JDK:

Comments

Post a Comment