Difference Between JDK, JRE and JVM in Details

Difference Between JDK, JVM & JRE: After knowing about the Introduction to Java and various Java terminologies, we learned about various terminologies like JDK, JVM & JRE. So, let’s go into some depth to learn more about the JDK, JVM, and JRE and know the exact difference between them.

If you visit our SoftwareTestingO blog for the first time, we suggest you check our series of posts on the Core Java tutorial by following the link.

As we know, Java is a high-level programming language. So, the computer will not run that if you try to run a high-level programming language on any machine. So, if you try to run a high programming language, you must convert the high-level language to machine-understandable.

So when you compile the Java program using the Javac Compiler, the Java compiler can take the Java program as the input and then convert that program to machine-understandable code, which is byte code. After the conversion, the machine takes the bytecode and runs that code, and then only the machines can understand that bytecode and perform the operation.

What is JVM & Architecture?

Now, we can understand that the primary function of JVM is to execute the byte code generated by the compiler. Each operating system has a different JVM, but when the JVM executes the bytecode, they all produce the same output across all different operating systems.

That means the byte code can be run in any environment. Because of this feature, Java is called a platform-independent or robust language.

JVM Architecture

In the below diagram, you can see the JVM architecture. Let’s go step by step and try to learn how things are happening internally:

JVM Architecture

ClassLoader: First of all, when we compile the .java program, it will converted into a .class file, which is nothing but a byte code, and this can be possible because of the java compiler. Now, when the JVM gets the .class file, there is a module or program called the class loader system, which does the following functions:

  • First, it loads the .class file into memory
  • After loading it, verify that the byte code is proper or not. If JVM finds anything suspicious, then the execution is rejected immediately.
  • If the byte code is proper, it allocates memory to execute the program.

Java Memory Area

The memory area is categorized into five parts, called run-time data areas; it can contain the results and data while running the program. These five different data areas are:

  • Method area: This area stores the class code like variables and code of methods in the Java program.
  • Heap Area: This is the area where objects are created. So when JVM loads a class, a method and heap area are created immediately.
  • Java Stacks: Method code is stored in the method area, but when we are executing those methods, you need some more memory to store the data and results; at that time, memory is allocated in the Java stack. So, Java Stacks is the memory area where the Java methods are executed. JVM Create a separate thread to implement each method.
  • Program Counter (PC) registers: This memory area contains the memory address of the instructions of the methods. if there are four methods, then 4 PC registers will be used to track the instructions of the methods
  • Native Method Stacks: Java methods are executed on the Java stack; native methods are performed in native method stacks. To execute the native methods generally, we required native method libraries. These header files are located and connected to JVM by a program called Native method interface.

Java Execution engine contains an interpreter and JIT (Just in time) compiler, which is responsible for converting the byte code to machine code so that the processor will execute them. Most of the JVM implements both an interpreter and a JIT compiler to convert the byte code. This technique is called an adaptive optimizer.

What is JDK?

The full Form is JDK ( Java Development Kit) of Java, which provides all the tools required to compile, debug, and execute the Java program. It’s a platform-specific software, so different versions are available according to the platform, like Windows, Mac, and Linux. Mainly, JDK includes two things.

  • Development tools (it provides an environment to develop Java programs)
  • JRE (It Helps to Execute your Java program)

What is JVM (Java Virtual Machine)?

It is the most critical thing in Java, which converts byte code to machine-specific code. It also provides the core Java functions like memory management, garbage collection, and security.

What Is JRE (Java Runtime Environment)?

JRE is providing us with the platform to execute the Java program. JRE combines JVM, Java binaries, and other classes, which helps us execute our Java program successfully. If you want to run a Java program on your machine, then on your computer, JRE should be installed, and JDK is not required to run the Java program.

What difference between JDK VS JRE and JVM

We hope terms like JDK (Java Development Kit), JVM(Java Virtual Machine), and JRE(Java Runtime Environment) all look similar. Still, these are the core concepts of the Java programming language. These are different and are used for a specific purpose. you may face this in most interviews, so let me explain.

JDK (Java Development Kit):

  • Role: JDK is a software package used for developing Java applications.
  • Function: It includes tools and utilities for compiling, debugging, and building Java applications. The JDK contains the Java Compiler (javac), libraries, and development tools like JavaDoc and Java Debugger.
  • Key Point: JDK is essential for Java developers to write, compile, and test Java code.

JVM (Java Virtual Machine):

  • Role: JVM is like a virtual computer within your actual computer. It’s responsible for executing Java bytecode.
  • Function: It takes the compiled Java bytecode and translates it into machine-specific instructions that the underlying operating system can understand and execute.
  • Key Point: JVM ensures platform independence, allowing Java programs to run on different platforms without modification.

JRE (Java Runtime Environment):

  • Role: JRE is a runtime environment essential for running Java applications.
  • Function: It provides the necessary runtime environment for executing Java programs. This includes the Java Virtual Machine (JVM), which executes bytecode, and the Java Class Library, a collection of pre-built classes for common tasks.
  • Key Point: JRE is needed on end-user machines to run Java applications. It doesn’t include development tools like the JDK.

In summary, JDK is used for Java development, JVM executes Java bytecode, and the JRE is required to run Java applications on end-user machines. Each serves a distinct purpose in the Java ecosystem.

Conclusion:

  • To develop a Java program, we need JDK, but to successfully run the Java program, we require JRE.
  • JDK and JRE have the JVM so that we can run the Java program.
  • Because of the JVM, java is a platform-independent language, so we can write the Java program once and run it on any other platform.

If you like this post, don’t forget to share it with your friends and colleagues. also, if you want to add or update something in the post, please mention that in the comment section.

I love open-source technologies and am very passionate about software development. I like to share my knowledge with others, especially on technology that's why I have given all the examples as simple as possible to understand for beginners. All the code posted on my blog is developed, compiled, and tested in my development environment. If you find any mistakes or bugs, Please drop an email to softwaretestingo.com@gmail.com, or You can join me on Linkedin.

2 thoughts on “Difference Between JDK, JRE and JVM in Details”

  1. I could see many spelling mistakes on this website.
    Difference Between JDK, JVM and JVM in Details
    Instead of 2 times JVM it should be JVM and JRE

    Under
    What is Java Language?
    End of the 1st paragraph
    ……benefits of Javed in the list Will Go On.”

    Reply

Leave a Comment