JVM, runtime and development tools
These terms describe different layers. A JVM executes Java class-file code. A runtime supplies the JVM, Java libraries and supporting components needed by an application. A JDK also provides development tools, including javac, jar and javadoc.
“JRE” is useful as a conceptual name for the runtime, but it does not imply that every modern distribution ships a separate JRE installer or a jre/ directory. Modular JDKs can also be used to build application-specific runtime images with jlink.
From source code to execution
javaccompiles Java source into class-file bytecode.- The runtime loads, links and initializes the classes needed by the program.
- A JVM implementation may interpret bytecode, compile it to native machine code with a JIT compiler, or combine these approaches.
The interpreter executes bytecode, not Java source text. A JIT compiler commonly compiles frequently executed methods or regions, using runtime information to optimize them; it does not simply group instructions with “similar functionality.” The JVM specification defines observable behavior rather than requiring one execution strategy.
What is inside a JVM?
The specification describes logical runtime areas. Their physical implementation is not a hardware-virtual-machine diagram.
- Class loading and linking: locate class definitions, verify them and prepare their runtime representation. Applications can use custom class loaders; the platform does not require exactly one fixed loader arrangement.
- Heap: the logical area for objects and arrays. JIT optimizations can eliminate some allocations, so a source-level object does not necessarily become a separately allocated heap object.
- Method area and runtime constant pools: per-class structures and metadata. HotSpot’s storage choices, including Metaspace, are implementation details.
- Per-thread JVM stacks: hold method frames, including local variables, operand stacks and bookkeeping. Stack-held references can help keep heap objects reachable.
- Program counter: tracks a thread’s position in non-native JVM code; it is not a separate physical CPU assigned to Java.
- Native support: native methods use implementation-specific execution support. JNI is an interface between Java and native code, not a general protocol for communicating with another application.
Portability and version compatibility
Java’s portable class-file format helps the same program run on different systems with compatible runtimes. “Write once, run anywhere” still depends on the required Java version, libraries and any native or operating-system-specific dependencies. For example, a class file targeting a newer Java release may not run on an older JVM. When appropriate, javac --release can target a supported older platform.
Modern browsers such as Chrome do not run the legacy Java applet plug-in. Browser JavaScript and the Java language are separate technologies.
Interpreters and compilers
These are implementation techniques, not mutually exclusive categories of programming languages. A system can compile source to an intermediate form and then interpret or JIT-compile it. “Interpreted” does not universally mean slow, and “compiled” does not guarantee that every error is found before execution. Performance depends on the implementation and workload.
JDK versus IDE
The JDK supplies the tools and libraries for building and running programs. An IDE organizes editing, navigation, debugging and builds, usually by invoking an installed JDK or build tool. Examples include IntelliJ IDEA, Eclipse, NetBeans and Visual Studio Code with Java extensions.
Example: compile and run HelloWorld
Save the following as HelloWorld.java. This uses the traditional entry point so the example remains familiar across Java releases.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, Purrgramming!");
}
}
javac HelloWorld.java
java HelloWorld
The first command creates a class file; the second launches the program. You should see Hello, Purrgramming!. Single-file launch modes in newer JDKs are another option, but are not required for this example.