Last Updated: 25 November, 2023
JDK, JRE, and JVM are the three basic core components of the Java programming language. A Java application cannot be developed and run without these components.
JDK, JRE, and JVM are basically the Java software packages, or parts of the packages, that contain tools and libraries that are needed to compile and execute Java programs.
JDK (Java Development Kit)
Used for developing Java applications and applets.
JRE (Java Runtime Environment)
Provides an environment to run Java applications.
JVM (Java Virtual Machine)
It is the core component of both JDK and JRE, responsible for executing Java bytecode.
The JDK is a superset of the JRE, which is a superset of the JVM. This means that the JDK includes the JRE and the JVM, and the JRE includes the JVM.
📝 JDK, JRE, and JVM are platform-dependent, while Java is platform-independent.
Now let's understand JDK, JRE, and JVM in detail, one by one.
The JDK is a Java Application Development Kit that provides the environment to develop and run Java programs. JDK includes JRE as well as development tools such as an interpreter and loader (java), a compiler (javac), an archiver (jar), a Java disassembler (javap), and a documentation generator (javadoc), among other things.
JDK = JRE + Development tools (eg. javac, javap, java, javadoc etc.)
The JRE provides a runtime environment for Java applications to execute. The JRE includes class libraries, a Java Virtual Machine (JVM), and other supporting files. It does not contain any tools for Java development, like a debugger, compiler, etc.
JRE = JVM + Runtime Libraries (contains packages like util, math, lang etc.) + Runtime Files
The JVM is part of the Java Runtime Environment (JRE). JVM is an abstract machine responsible for loading, verifying, and executing Java bytecode into machine code that can be executed by the underlying hardware.
Java bytecode is a low-level language that is generated by the Java compiler from Java source code.
The JVM also provides a number of other services to Java applications, including:
Loads .class files in memory.
Verifies the bytecode.
It converts bytecode into machine-specific code.
It provides a runtime environment and relies on the availability of dependent classes and libraries.
Executes the code and generates the output.
Uses garbage collection to manage memory for classes, objects, and so on.
Here is a table summarizing the key differences between JDK, JRE, and JVM:
Parameters | JDK | JRE | JVM |
Definition | The JDK (Java Development Kit) is a Java Application Development Kit that provides the environment to develop and run Java programs. JDK includes JRE as well as development tools. | The JRE (Java Runtime Environment) provides a runtime environment for Java applications to execute. The JRE includes class libraries, a Java Virtual Machine (JVM), and other supporting files. | The JVM (Java Virtual Machine) is part of the JRE. JVM is an abstract machine responsible for loading, verifying, and executing Java bytecode into machine code that can be executed by the underlying hardware. JVM also manages memory allocation, garbage collection, and other aspects of Java application execution. |
Functionality | Used for developing Java applications and applets. | Provides an environment to run Java applications. | Responsible for loading, verifying, and executing Java bytecode into machine code that can be executed by the underlying hardware. |
Platform Dependency | The JDK is platform-dependent. | The JRE is platform-dependent. |
The JVM is platform-dependent. |
Tools | JDK includes JRE as well as development tools such as an interpreter and loader (java), a compiler (javac), an archiver (jar), a Java disassembler (javap), and a documentation generator (javadoc), among other things. |
The JRE includes class libraries, a Java Virtual Machine (JVM), and various supporting files for JVM, and the class libraries that help JVM in running the program. | JVM does not consist of any tools for software development. |
Implementation | JDK = Development Tools + JRE (Java Runtime Environment) | JRE = Libraries for running the application + JVM (Java Virtual Machine) |
JVM = Only the runtime environment that helps in executing the Java bytecode. |
What is javac?
javac is a Java Compiler. It is an important tool of the JDK. Whenever we compile a Java source code file (.java), the Java compiler is responsible for compiling the Java source code, and once successful compilation is done, it generates a .class file. The .class file is the bytecode that is platform-independent. Then the JVM executes the bytecode to run the program.
To compile the Java source code file, we write the command given below.
javac Test.java
First, we write a Java compiler name that is javac followed by a Java file name with a .java extension.
When to use JDK, JRE, and JVM?
The JDK is used by Java developers to develop Java applications. The JRE is used by end-users to run Java applications. The JVM is the core component of both the JDK and the JRE, and it is responsible for executing Java bytecode.
That's all guys, hope this Java article is helpful for you.
Happy Learning.
feedback@javabytechie.com