JVM vs JRE vs JDK

Code Computer Skills Data Java

As developers, all of us have heard the terms JDK, JRE, and JVM. But only a few know what exactly is JVM vs JRE vs JDK and the difference between them.

Although these terms appear to be similar, there is a huge difference between them. It is a very basic question in Java. And it is also one of the favorite questions of interviewers.

Keeping all of these points in mind, I have written this article, explaining the basic difference between them. If you prefer studying using video, you can have a look at this. Continue reading the article for written content.

Java Virtual Environment (JVM):

  • It is an abstract machine and does not have a physical existence.
  • JVM is platform dependent i.e. for different hardware and software configurations, there is different JVM configuration
  • The aim of JVM is to run Java programs irrespective of the OS, making it platform independent.
  • Tasks of JVM:
    • Load and verify the code
    • Execute the code
    • Provides a run-time environment to execute Java bytecode.

First, the Java compiler compiles the source code into bytecode. Then the JVM executes the bytecode. Thus, JVM converts the Java bytecode into machine code.

JVM can also run programs written in other programming languages after they are compiled into Java bytecode.

It consists of registers, stack, method area, and garbage collection heap. The bytecode is present in the method area and is executed on the stack. The stack holds the results, parameters, state of variables and methods. The registers and program counter manage the stack during execution. The referenced objects created by the program live in the heap.

Refer to the below diagram for a clear cut understanding.

 

Java Run-time Environment (JRE):

  • JRE implements the JVM. The JRE can be called a superset of JVM.
  • It provides a platform to execute the java bytecode.
  • For executing programs, it contains many other supporting classes like binaries, core class files, libraries that help in the execution of the code.
  • It also provides user interface toolkits, JDBC integration (Java Database Connectivity), deployment tools, etc.
  • Primarily, JRE provides an environment to only run Java Programs. You cannot develop a Java application using JRE.

JDK: Java Development Kit

  • Java Development Kit provides an environment for developing Java applications.
  • JDK contains a JRE to execute Java codes.
  • It also consists of compiler (javac), Java interpreter, loader, debugger and a documentation generator (javadoc) to develop programs.
  • It manages the libraries in an efficient way through the archiver. The archiver combines and keeps the required library files into a single jar file.
  • JDK also contains various development tools like applet viewer, javaConsole, jrunscript, jshell, etc.

Thus, JDK is a package that consists of all the tools required to develop a Java application.

 

So this was all about JVM vs JRE vs JDK.