What is the Difference Between JRE, JDK and JVM?

shivam bhatele
CodeX
5 min readDec 13, 2022

--

Introduction

Of all the programming languages used today, Java is the most commonly used. Most developers use it for mobile and desktop computing, games, back-end development, etc. Java development relies heavily on JVM, JRE, and JDK. The differences between JDK, JRE, and JVM are essential for understanding this language in depth. This article will explain the differences between them

What is JVM

The Java Virtual Machine (JVM) is a type of abstract machine. Because it does not exist physically, it is called a virtual machine. An execution environment for Java bytecode is defined by this specification. In addition, it can run programs that have been compiled to Java bytecode in other languages.

There are many platforms on which JVMs are available. The configuration of each OS makes JVM, JRE, and JDK platform-dependent. In contrast, Java is platform-independent. JVMs have three notions: specifications, implementations, and instances.

JVMs perform the following tasks:

  • Loads the code
  • Checks code validity
  • Code execution
  • Provides an environment for running

Features of JVM

  • Using it, you can run applications on your device or in the cloud.
  • Byte code is converted into machine-specific code by the Java Virtual Machine.
  • There are many basic Java functions included, such as memory management, security, and garbage collection.
  • A Java virtual machine executes a program by using libraries and files that are supplied by the Java Runtime Environment.
  • Both JDK and JRE contain Java Virtual Machines.
  • Since it can execute Java programs line by line, it is also known as an interpreter.
  • A JVM can be customized in many ways, such as allocating minimum and maximum amounts of memory, for example.
  • It is not affected by the hardware or the operating system. Java programs can be written once and run anywhere.

Architecture of JVM

JVM consists of the following components:

Class Loader: The class loader is a subsystem of the Java Virtual Machine. It loads class files. When we run a Java program, the class loader loads it first.

Class method area: This is one of the data areas in JVM where class data is stored. A static variable, a static block, a static method, and an instance method are stored here.

Heap: When the JVM starts up, a heap is created. While the application is running, its size may increase or decrease.

Stack: JVM stacks are known as thread stacks. In the JVM memory, it’s a data area that’s created for each execution thread. In the JVM stack of a thread, various elements are stored, such as local variables, partial results, and data for method calls and returns.

Native stack: All native methods in your application are included in this class.

JIT compiler: A Just-In-Time (JIT) compiler is included in the runtime environment. During runtime, it compiles Java bytecodes into machine code to improve performance. By default, the JIT compiler is enabled.

Garbage Collector: Managing memory is done using the garbage collector, which is a Java program. The system consists of two steps, Mark and Sweep.

Native Interface: This interface enables Java method calls to connect to native library calls.

Native Libraries: Java Native Libraries contain programs or code written in languages other than Java, such as C, C++, etc.

What is JRE?

Java Runtime Environment (JRE) is software that is designed to run other types of software. A class library, a loader, and a JVM are contained in it. In simple terms, you need JRE in order to run Java programs. It is not necessary to install JDK if you are not a programmer, but you must install JRE in order to run Java programs. It is important to note, however, that all JDK versions come bundled with the Java Runtime Environment, so you do not have to download and install the JRE separately from the JDK.

Features of JRE

  • JRE is a set of tools that assist in running the JVM. Additionally, Java Web Start and Java Plug-in are included.
  • It is possible for a user to run Java code efficiently with only the JRE. JRE, however, does not allow you to write programs.
  • Several integration libraries are bundled with JRE, including JDBC, JNDI, and RMI (Remote Method Invocation).
  • Java HotSpot’s virtual machine client is included with the JVM.

Architecture of JRE:

JRE consists of the following components:

  • Class loaders: Various classes necessary for running Java programs are loaded through this. There are three main class loaders in the JVM: the system class loader, bootstrap class loader, and extensions class loader.
  • Byte code verifier: Verifies bytecode to prevent interpreters from being disturbed.
  • Interpreter: Once the classes have been loaded and the code has been verified, the interpreter reads the code line by line.
  • Run-time: Run-time is a system used in programs to determine how long the program will run for.
  • Hardware: Once the Java native code is complete, it is executed on a specific hardware platform. A Java Runtime Environment runs Java programs in this way.

What is JDK?

JDK stands for Java Development Kit. This software development environment allows you to develop applets and Java applications. JDK includes JRE and development tools, as well as a physical copy of JDK itself. The JDK can be installed on multiple computers at the same time. It can be used on macOS, Windows, Linux, and Solaris by Java developers. Java Development Kit assists them in coding and running Java programs. JDKs contain private JVMs along with a few other resources like java, javac, Javadoc, and jar for developing Java applications.

Features of JDK

  • Multiple extensions can be handled in a single catch block.
  • All the features of JRE are included in JDK.
  • Compilers, debuggers, and other development tools are included.
  • Java Development Kit provides an environment for developing and executing Java code.
  • Operating systems such as Windows, Unix, and Mac can be used to install it.
  • A generic type interface can be specified using the diamond operator instead of writing the exact one.

Architecture of JDK

JDK consists of the following components:

  • JDK and JRE: Developers use the JDK to create Java programs that run with the JRE, which includes a JVM and class libraries.
  • Class Libraries: These are dynamically loadable libraries that Java programs can access.
  • Compilers: It is a Java application that compiles text files given by developers into Java classes. It is a form of output produced by compilers, containing Java bytecode. Javac is the primary Java compiler.
  • Debuggers: Java debuggers allow developers to test and debug Java programs.
  • JavaDoc: The JavaDocs are Sun Microsystems’ documentation for Java. It is possible to generate API documentation from source code using JavaDoc

Conclusion:

Nowadays, Java plays a vital role in application development, which is why JDKs, JREs, and JVMs will always be used. To develop Java applications, Java Development Kit (JDK) is used.

An application written in Java is run by the Java Runtime Environment (JRE), which provides a Java Virtual Machine (JVM), class libraries, and other components. The Java Virtual Machine (JVM) on the other hand provides an environment for Java ByteCodes to be executed.

--

--

shivam bhatele
CodeX
Writer for

I am a Software Developer and I loved to share programming knowledge and interact with new people. Also I am big lover of dogs, reading, and dancing.