Difference Between JDK JRE and JVM
Difference Between JDK JRE and JVM
scaler.com/topics/difference-between-jdk-jre-and-jvm
22 September 2023
Overview
Java is one of the most important programming languages in today's era. Java is also very
versatile as it serves as a programming language for Android development, web development,
desktop applications, and much more. But before delving into the world of Java, let us understand
the basic yet important concepts of Java- the difference between JDK, JRE, and JVM. This article
deals with the differences between these components.
Working
Compilation-
It consists of a Java compiler (javac) which is responsible for translating the Java code to
the bytecode. The bytecode is an intermediate code that is understood by the Java Virtual
Machine (JVM).
Execution-
Debugging-
There might be errors and bugs in our Java code which is debugged using the tools
provided by JDK.
Importance
It is important as it is used to maintain the compatibility between various versions of Java.
It is mainly used for development, compiling, and debugging.
JDK is mainly responsible for compiling as it contains the compiler javac. It makes JDK
essential for development.
The JDK version represents the Java version.
It ensures consistent behavior across all platforms by enforcing the standard Java syntax.
1/10
Also, multiple versions of JDK can exist on the same machine, allowing developers to work
with different Java versions simultaneously.
Use Cases
It provides different tools and libraries for building frameworks, Android applications,
desktop applications, etc.
Some of the popular JDK include- OpenJDK and Oracle JDK.
JDK architecture
The various components of JDK are- JVM, development and debugging tools, etc.
2/10
JRE Architecture
Working
To understand the workings of JRE, we need to know JVM. Here, we will understand it in
short and discuss it in depth later in this article.
3/10
From this we can understand that the important components are- ClassLoader, Bytecode
verifier, and Interpreter.
ClassLoader-
Classes are loaded into the memory as per their requirement. So, the Java ClassLoader is
used to load the required classes to run a Java program. When the JVM is initialized, the
following classes are loaded-
Before the code is passed to the interpreter, the bytecode verifier is used to verify the
format of the Java code.
4/10
Interpreter-
When the byte code is loaded successfully, the Java interpreter creates an object of JVM
because of which the Java code can run on the underlying machine.
Importance
It is majorly responsible for running the Java applications
It also ensures the safe execution of the Java program by using features like sandboxing.
It consists of various integration libraries like- Java Database Connectivity(JDBC),
JNDI(Java Naming and Directory Interface), RMI (Remote Method Invocation) etc.
JVM Architecture
5/10
The components of JVM are as follows-
6/10
Class Loader Subsystem-
The class loader subsystem ensures that the class is loaded into memory. It is an on-
demand process that prevents unnecessary work and redundancy. It handles the process of
Loading, Linking, and Initialization.
It is the area where the memory is used during the execution. The sub-components of the
Runtime Data Area are as follows-
It is used to interpret and execute bytecode. The instructions are read and executed. The
sub-components of the execution engine are as follows-
It is a Java framework that allows the code running in the JVM to interact with the native
libraries. The performance is also optimized.
Working
The JVM is responsible for loading, linking and initialization.
Loading-
Loading involves bringing the bytecode of a class into memory. It is the first step of
execution in JVM.
7/10
Linking-
Here, the bytecode verification takes place. The class file is parsed by the JVM and divided
into basic elements like methods, fields, etc. It is important to verify the bytecode to prevent
unauthorized access and ensure memory safety.
Verification-
It verifies and ensures that the bytecode adheres to the structural rules for JVM's
security. The rules like proper data type handling and valid references to objects are
checked.
Preparation-
Memory is allocated to the static fields and they are initialized with the default values.
It ensures that the static data of the class can be used.
Resolution-
Initialization-
During initialization, the sequence of static initializers and static fields' execution follows the
order they are defined in the code. This is to make sure that the classes are properly
initialized before they are put into use.
Importance
The feature of Write Once Run Anywhere or WORA is possible because of JVM. Java
code can be developed on one platform but it can be run on different platforms also.
JVM is actually responsible for calling the main() method of Java.
It also provides abstraction by hiding the inner implementation from the developers utilizing
libraries from JVM.
JVM enhances security by enforcing bytecode verification and runtime access controls,
ensuring that Java applications operate in a secure sandboxed environment. It results in a
safe application execution.
JDK stands for Java JRE stands for JVM stands for Java Virtual Machine
Development Kit Java Runtime
Environment
8/10
JDK JRE JVM
JDK consists of many JRE consists of JVM does not consist of any software
development tools. class libraries and tools.
other files.
FAQs
Q. What is the Difference between JDK, JRE, and JVM in Java?
A. JDK is the Java Development Kit used for development, JRE is the Java Runtime Environment
used to run Java applications, and JVM is the Java Virtual Machine responsible for executing
Java bytecode.
A. JVM interprets bytecode and converts it into machine-specific instructions, enabling Java code
to run consistently across various platforms.
A. Yes, multiple versions of JDK can exist on the same machine, allowing developers to work with
different Java versions simultaneously.
Conclusion
Java Development kit is used for developing Java applications and applets. It consists of
Java Runtime Environment (JRE), interpreter, compiler, and other tools like archiver,
document generator, etc. It is responsible for compiling, debugging, and executing.
In JDK, compilation involves using the Java compiler (javac) to translate code into
bytecode, which is understood by the Java Virtual Machine (JVM). The execution is carried
out by the JVM within JDK, whereas the debugging tools are provided to identify and rectify
errors and bugs in Java code.
Java Runtime Environment is provided by Java to run the applications. It is an
implementation of JVM. It consists of run-time libraries. t consists of various integration
libraries like- Java Database Connectivity(JDBC), JNDI(Java Naming and Directory
Interface), RMI (Remote Method Invocation) etc.
9/10
The important JRE components are- ClassLoader, Bytecode verifier, and Interpreter. It is a
specification that provides a run-time environment for Java applications.
JVM is responsible for converting the byte code to machine-specific code. It is known as a
virtual machine as it is not present physically.
The feature of Write Once Run Anywhere or WORA is possible because of JVM. Java code
can be developed on one platform but it can be run on different platforms also. JVM is
responsible for calling the main() method of Java.
10/10