JDK, JRE, JVM
What is JDK?
-
The Java Development Kit (JDK) is a software development kit
used to develop applications in the Java programming language.
-
It includes
-
various tools which are essential for compiling, running, documenting, packaging, and debugging Java applications,
such as The Java Application Launcher (java), Java Compiler (javac), Documentation Generator (javadoc) etc and
-
a runtime environment (Java Runtime
Environment or JRE).
-
Below is the diagram showing JDK architecture in Java.
Components of JDK :-
There are 2 main components in JDK which are as below :-
JDK (Java Development Kit) = 1 - Development Tools + 2 - JRE (Java Runtime Environment)
-
Development Tools:
Tool |
Description |
java |
The Java Application Launcher: Executes Java
applications and applets. It replaces the older
jre tool, combining development and deployment
functionalities.
|
javac |
Java Compiler: Converts Java source code into Java
bytecode, producing .class files.
|
javadoc |
Documentation Generator: Automatically creates
HTML documentation from Java source code comments.
|
jar |
Archiver and Manager: Packages related class
libraries into a single JAR (Java ARchive) file
and manages JAR files.
|
jdb |
Java Debugger: Provides a command-line interface
for debugging Java programs.
|
Other Development Tools (you can skip)
Tool |
Description |
appletviewer |
Runs and debugs Java applets without a web
browser.
|
javah |
C Header and Stub Generator: Generates C header
files and JNI (Java Native Interface) stubs for
native methods.
|
javap |
Class File Disassembler: Displays information
about Java class files, including bytecode and
structure.
|
javaws |
Java Web Start Launcher: Launches and manages Java
applications distributed via JNLP (Java Network
Launch Protocol).
|
jps |
Java Virtual Machine Process Status Tool: Lists
HotSpot JVMs on the system and provides process
details.
|
jrunscript |
Command-Line Script Shell: Allows execution of
JavaScript and other scripting languages from the
command line.
|
jstack |
Prints Java stack traces of Java threads, useful
for diagnosing thread-related issues
(experimental).
|
jstat |
JVM Statistics Monitoring Tool: Monitors various
JVM statistics, such as garbage collection and
memory usage (experimental).
|
jstatd |
jstat Daemon: Provides a network interface to
monitor JVM statistics (experimental).
|
and many more.... |
-
Java Runtime Environment (JRE):
-
Function: Provides the libraries,
Java Virtual Machine (JVM), and other components to
run Java applications.
-
Included: The JRE is part of the JDK,
and it includes the JVM along with the necessary
runtime libraries.
Usage of JDK :-
-
Development : Used by developers to create and
compile Java applications.
-
Installation : Requires installation on the
developer’s machine and is not required for end-users who only
need to run Java applications.
What is JRE ?
-
The Java Runtime Environment (JRE) is a software platform that
enables the execution of Java applications. It works by
providing a runtime environment that includes a set of core libraries
and Java Virtual Machine (JVM).
-
The JRE allows Java
programs to run on any device or operating system without
modification, by translating Java bytecode into native machine
code that the JVM executes.
-
Below is the diagram showing JRE architecture in JDK.
Components of JRE :-
There are 4 main components in JDK which are as below :-
-
Java Libraries
-
Java libraries are collections of pre-written code that provide essential functionality for development. They include base libraries (e.g., java.lang, java.util), additional base libraries (e.g., java.beans, java.security), and integration libraries (e.g., JDBC, JNDI) for external system integration.
-
These are divided in 3 main categories :-
-
lang & util Base Libraries (e.g., java.lang, java.util): Provide core classes for Java, including fundamental utilities (e.g., collections, strings, math) and language features (e.g., threading, exceptions).
-
Other Base Libraries (e.g., java.beans, java.security): Provide additional functionality, such as object introspection (beans) and security features (cryptography, authentication).
-
Integration Libraries (e.g., JDBC, JNDI): Offer APIs for database connectivity (JDBC), directory services (JNDI), and integrating with external systems like databases and networks.
-
User interface toolkits :- User interface toolkits in JRE, like AWT, Swing, and Java 2D, provide tools for building graphical user interfaces (GUIs). They offer components for windows, buttons, and graphics rendering, enabling developers to create interactive, visually-rich applications with support for both basic and advanced UI elements and 2D graphics.
-
Deployment :- Deployment in JRE involves packaging and distributing Java applications for execution on client machines. This includes delivering Java programs in formats like JAR or WAR files, ensuring they run within the Java Runtime Environment, often using tools like Java Web Start or applet technology for deployment.
-
Java Virtual Machine :- The Java Virtual Machine (JVM) is an engine that executes Java bytecode. It provides platform independence by allowing Java programs to run on any device with a JVM, handling tasks like memory management, garbage collection, and code optimization.
JRE (Java Runtime Environment) = Java Libraries + Unser Interface Toolkits + Deployment + JVM (Java Virtual Machine)
Usage of JRE :-
Java Runtime Environment (JRE) is used to provide a runtime platform for executing Java applications. It includes the JVM, core libraries, and resources required to run Java programs, ensuring platform independence and handling tasks like memory management, security, and execution of compiled Java code.
What is JVM ?
-
The JVM is a part of the Java platform that executes Java bytecode, converting it into machine code for the host system. It provides an abstraction layer between compiled Java code and the operating system.
-
The main use of the JVM is to enable platform-independent execution of Java programs by interpreting or compiling bytecode to machine code, managing memory, ensuring security, and optimizing performance.
-
Below is the diagram showing JVM architecture in JRE.
Components of JVM :-
There are 3 main components in JVM :-
-
Class Loader: The class loader is responsible for dynamically loading Java classes into memory at runtime. It handles loading, linking, and initialization, organizing classes into namespaces and ensuring they are available for execution.
-
Memory Areas: The JVM's memory areas include the heap (for objects), stack (for method calls and local variables), method area (for class-level data), and native method stacks. These regions manage memory allocation, storage of program data, and execution context.
-
Execution Engine: The execution engine interprets or compiles bytecode into machine code for execution by the CPU. It includes the interpreter for line-by-line execution and the Just-In-Time (JIT) compiler for optimizing frequently executed code paths.
JVM (Java Virtual Machine) = Class Loader + Memory Areas + Execution Engine
Usage of JVM :-
The JVM interprets or compiles the
bytecode into native machine code that can be executed by the
host machine. This enables Java programs to run on any device
or operating system that has a compatible JVM implementation,
adhering to the principle of "Write Once, Run Anywhere."