Java Platform Components Overview
===
- JDK, JRE, and JVM
Component Definitions
-
JDK (Java Development Kit)
- Definition: The JDK serves as the comprehensive toolkit for Java developers, providing all necessary tools to create, compile, debug, and execute Java applications.
- Contents: This kit bundles the Java compiler (javac), Java Runtime Environment, development utilities (debuggers, packaging tools), and the standard Java class libraries.
- Purpose: Designed for application development, offering a complete development environment and toolchain.
-
JRE (Java Runtime Environment)
- Definition: The JRE provides the runtime environment required to execute compiled Java applications.
- Contents: Includes the Java Virtual Machine (JVM) and Java API libraries, but excludes development tools.
- Purpose: Required for running pre-compiled Java programs; end users only need this component without development capabilities.
-
JVM (Java Virtual Machine)
- Definition: The JVM serves as the execution engine that runs Java bytecode on specific operating systems.
- Function: Translates Java bytecode into machine-specific instructions that the underlying operating system can execute.
- Key Feature: Enables Java's platform independence through a virtualized execution layer.
Relationships
- Containment Hierarchy: The JDK includes the JRE, which in turn includes the JVM. This hierarchy follows the pattern: JDK > JRE > JVM. Installing the JDK automatically includes both JRE and JVM components.
- Complementary Roles: The JDK supplies the complete development ecosystem with compilation, debugging, and execution capabilities. The JRE provides the necessary runtime environment. The JVM handles actual bytecode interpretation and execution.
- Unified Objective: These three components work together to deliver Java's cross-platform capability, allowing bytecode to execute across different operating systems without source code modifications.
- JDK Installation and Configuration
Installation Process
Obtaining and installing the JDK is straightforward. Visit the Oracle website or adopt distributions like Eclipse Temurin or Amazon Corretto. Download the installer matching your operating system and Java version, then execute the installer to complete setup.
Environment Configuration
1. Setting Environment Variables (Windows)
Note: Modern JDK versions may configure environment variables automatically. Test by running java -version in Command Prompt. If version information doesn't appear, manual configuration becomes necessary.
-
Configuring JAVA_HOME:
- Right-click "This PC" or "Computer" and select "Properties"
- Click "Advanced System Settings"
- In the System Properties dialog, click "Environment Variables"
- Under "System Variables," click "New" to create a new variable named
JAVA_HOME, setting its value to your JDK installation path (for example,C:\Program Files\Java\jdk-17)
-
Updating the Path Variable:
- Locate the
Pathvariable in System Variables and double-click to edit - Append
%JAVA_HOME%\binto the variable values, separated by semicolons (;) - Confirm changes by clicking "OK"
- Locate the
Note: macOS and Linux require different approaches. Users typically modify files like ~/.bash_profile, ~/.zshrc, or system files such as /etc/profile.
2. Verifying Installation
- Open Command Prompt (Windows) or Terminal (macOS/Linux)
- Execute
java -version— successful installation displays the version number - Optionally run
javac -versionto confirm the Java compiler is accessible
- Compilation and Execution Commands
Compilation uses the javac tool:
javac SourceFile.java
To specify character encoding during compilation:
javac -encoding UTF-8 MySource.java
Execution of compiled bytecode:
java ClassName
Note: Exclude the .class extension when running the program.
- Java Cross-Platform Mechanism
Java achieves platform independence through its distinctive two-stage compilation and execution model, supported by the JVM.
Compilation Phase
- Source Code Compilation: Java source files (
.javaextension) undergo compilation by the javac compiler, producing bytecode files (.classextension). This intermediate bytecode remains independent of any specific hardware architecture or operating system.
Execution Phase
-
Bytecode Interpretation: The compiled bytecode doesn't run directly on hardware. Instead, the JVM loads and executes these instructions. The JVM functions as a software layer installed atop various operating systems, delivering consistent runtime behavior regardless of the underlying platform.
-
JVM Functionality: The JVM translates bytecode into native machine instructions specific to the host operating system. While JVM implementations differ across platforms, they present a uniform interface to Java applications. This abstraction allows identical Java programs to execute on Windows, Linux, macOS, and other supported systems without code modifications.