HuntExams Academy logo
JavaBeginner#jvm#jdk#jre

Difference between JDK, JRE and JVM?

Answer

JDK (Java Development Kit) = JRE + development tools (compiler, debugger). JRE (Java Runtime Environment) = JVM + libraries needed to run Java apps. JVM is the engine that actually executes bytecode. Developers need JDK; end users only need JRE.

Example

To compile: javac (part of JDK only).
To run a compiled app: java (available in JRE).
Installing 'JDK 17' gives you javac, java, jar, jdb, and the JRE bundled in.

Detailed explanation

JDK, JRE and JVM describe three related parts of the Java platform: development tools, the runtime environment and the execution engine. The JDK (Java Development Kit) is used to develop, compile, test and run Java programs. The JRE (Java Runtime Environment) provides what a compiled Java application needs to run, including a JVM and standard Java libraries. The JVM (Java Virtual Machine) loads and executes Java bytecode. For interviews, “JDK = runtime + development tools” and “JRE = JVM + runtime libraries” are useful conceptual summaries, not exact descriptions of every modern installation layout.

Consider a file named Hello.java. The javac compiler, supplied with the JDK, converts its source code into bytecode stored in Hello.class. Running java Hello starts a JVM through the java launcher. The JVM loads classes, verifies bytecode and executes the program. In common implementations such as HotSpot, execution uses an interpreter and a just-in-time compiler, which compiles frequently executed code into native machine instructions. The JVM also manages runtime memory and garbage collection, although applications still need to close resources such as files and database connections.

The JRE supplies more than the JVM: it includes standard libraries used for collections, input/output, networking and other platform features, plus supporting runtime components. A traditional standalone JRE includes the java launcher but not development tools such as javac. The JDK adds tools including javac, jar for packaging archives, and jdb for debugging. Java bytecode can run across operating systems when a compatible JVM and required dependencies are available; the JVM implementation itself is platform-specific.

One important modern correction is that installing JDK 17 provides runtime capabilities, but generally does not create a separate bundled jre directory as older JDKs did. Standalone JRE availability depends on the vendor and release; applications may instead ship a custom runtime created with jlink. Therefore, developers normally install a JDK, while users need a suitable runtime—not necessarily a separately installed product called a JRE.

Key points to remember

  • JDK supports both Java development and execution; it includes javac, java, jar and jdb.
  • JRE means the runtime environment: JVM, standard libraries and supporting components.
  • JVM loads, verifies and executes bytecode, and manages memory through mechanisms including garbage collection.
  • javac Hello.java compiles source code; java Hello launches the compiled application.
  • Modern JDKs include runtime capabilities without necessarily containing a separate JRE installation.

Common mistakes candidates make

  • Saying the JVM compiles Java source files; javac normally compiles source into bytecode.
  • Claiming every modern JDK contains a separate jre folder, or that all vendors provide standalone JRE downloads.
  • Calling the JVM platform-independent rather than explaining that compatible platform-specific JVMs execute portable bytecode.

Likely follow-up questions

Can a Java program run without a JDK installed?

Yes, a compiled application can run with a compatible runtime that provides its required modules and dependencies. That runtime may be installed separately or bundled with the application.

What is the difference between javac and the JIT compiler?

javac normally converts Java source code into bytecode before execution. A JIT compiler operates inside the JVM during execution, converting selected bytecode into native machine code for better performance.

Can an older JVM run classes compiled by a newer JDK?

Not necessarily: an older JVM cannot load class files with an unsupported class-file version and typically throws UnsupportedClassVersionError. Using javac --release with a supported older release targets its language rules, class-file format and documented platform APIs, but dependencies must also be compatible.

Interview tip: Start with the three roles, demonstrate javac Hello.java and java Hello, then briefly clarify modern runtime packaging.

Related Interview Questions

1
JavaBeginner#operators#object

What is the difference between == and equals() in Java?

Open
2
JavaBeginner#oop

Explain OOP principles in Java.

Open
3
JavaIntermediate#oop#interface

What is the difference between abstract class and interface?

Open