JDK vs JRE

Understand the difference between JDK and JRE, which distributions to use, and how to manage multiple Java versions in enterprise projects.

Last reviewed: January 2025

·Java 8Java 11Java 17Java 21
✅
Quick Understanding: JRE (Java Runtime Environment) is what you need to run Java programs. JDK (Java Development Kit) is what you need to develop Java programs — it includes the JRE plus the compiler (javac), debugger (jdb), and other development tools. As a developer, you always install the JDK.

🔍 What Is It?

JRE — Java Runtime Environment

Contains:

  • →JVM (the engine that runs bytecode)
  • →Java Class Library (java.lang, java.util, java.io, etc.)
  • →Supporting files and configuration

Used by: end users running Java applications, production servers (historically)

JDK — Java Development Kit

Contains everything in JRE plus:

  • →javac — Java compiler
  • →javadoc — documentation generator
  • →jar — archive tool
  • →jdb — Java debugger
  • →jshell — interactive REPL (Java 9+)
  • →jconsole, jvisualvm — monitoring tools
  • →jstack, jmap, jstat — diagnostic tools

Used by: developers, CI/CD pipelines, build servers

JDK Distributions (2025)

  • →OpenJDK — open-source reference implementation (free)
  • →Eclipse Temurin (Adoptium) — most popular free distribution for production
  • →Amazon Corretto — AWS-optimized, free, LTS patches
  • →Microsoft Build of OpenJDK — Azure-optimized
  • →Oracle JDK — commercial license required for production (Java 17+)
  • →GraalVM — includes native image compiler
  • →Azul Zulu — certified builds with extended support

🎯 Why Do We Need It?

Understanding JDK vs JRE matters for:

  • →Docker images — use JRE-based images for production (smaller), JDK for build stages
  • →CI/CD — build agents need JDK; runtime containers need JRE
  • →License compliance — Oracle JDK requires a commercial license; use Temurin/Corretto for free
  • →Version management — enterprise projects often have multiple Java versions; tools like SDKMAN manage this

🏗️ What Happens in Real Projects?

In a real enterprise Dockerfile (multi-stage build):

# Stage 1: Build with JDK
FROM eclipse-temurin:21-jdk AS builder
WORKDIR /app
COPY . .
RUN ./mvnw package -DskipTests

# Stage 2: Run with JRE (smaller image)
FROM eclipse-temurin:21-jre
WORKDIR /app
COPY --from=builder /app/target/app.jar .
CMD ["java", "-jar", "app.jar"]

The JRE image is typically 100–150MB smaller than the JDK image.

⚙️ How It Works

Since Java 11, Oracle stopped shipping a standalone JRE. The JDK is now used everywhere. However, you can create a custom minimal runtime using jlink:

# Create a minimal JRE containing only the modules your app needs
jlink --module-path $JAVA_HOME/jmods \
  --add-modules java.base,java.logging,java.sql \
  --output my-custom-jre

This produces a runtime as small as 30MB, much smaller than a full JDK.

Version Management with SDKMAN:

sdk install java 21.0.1-tem   # Eclipse Temurin 21
sdk install java 17.0.9-tem   # Eclipse Temurin 17
sdk use java 17.0.9-tem       # switch for current session
sdk default java 21.0.1-tem   # set default

💻 Example

JDK Tools in Practice — The JDK tools you will use daily as a backend developer.

bash
# Check installed Java version
java -version
javac -version

# jshell — interactive Java REPL (great for testing snippets)
jshell
jshell> var list = List.of(1, 2, 3);
jshell> list.stream().mapToInt(x -> x).sum()
$2 ==> 6

# jar — inspect a JAR file
jar tf myapp.jar           # list contents
jar xf myapp.jar           # extract

# javap — disassemble bytecode
javap -c MyClass.class
javap -verbose MyClass.class

# jdeps — analyze dependencies
jdeps --print-module-deps myapp.jar

# jlink — create minimal custom JRE
jlink --add-modules java.base,java.net.http \
  --output custom-jre --strip-debug --compress=2

🤔 Common Confusions

❓ Do I need to install both JDK and JRE?

No. JDK includes everything in JRE. Install only the JDK. Since Java 11, standalone JRE distributions from Oracle no longer exist anyway.

❓ Is Oracle JDK still free?

Oracle JDK is free for development and personal use, but requires a paid subscription for production use (since Java 17). For free production use, use Eclipse Temurin (Adoptium), Amazon Corretto, or Microsoft Build of OpenJDK — all are OpenJDK-based and fully compatible.

🚨 Common Production Issues

Wrong Java version in production — always pin exact versions in Dockerfiles and CI pipelines. Use .java-version or .sdkmanrc files in your repo.

Large Docker images — using JDK in production image adds ~300MB unnecessarily. Use multi-stage builds with JRE for runtime.

License violations — accidentally using Oracle JDK in production without a subscription. Audit your Docker base images.

✅ Best Practices

Use Eclipse Temurin (Adoptium) or Amazon Corretto for free, production-grade JDK distributions.

Pin exact Java versions in Dockerfiles: eclipse-temurin:21.0.1_12-jre, not eclipse-temurin:latest.

Use multi-stage Docker builds: JDK for build stage, JRE for runtime stage.

Use SDKMAN for local version management across multiple projects.

Use LTS versions (8, 11, 17, 21) in production for guaranteed long-term patches.

🏛️ Architect's Note

Senior Architect's Perspective

For new microservices in 2025, use Java 21 LTS with Eclipse Temurin. The virtual threads feature (Project Loom, GA in Java 21) is a game-changer for I/O-bound services — it allows millions of concurrent lightweight threads without the overhead of OS threads, eliminating the need for reactive programming in most cases.

💬 Frequently Asked Questions

What is the difference between OpenJDK and Oracle JDK?

OpenJDK is the open-source reference implementation. Oracle JDK was historically built from OpenJDK with some extra features and better support. Since Java 17, Oracle JDK and OpenJDK are functionally identical. The only difference is the license — Oracle JDK requires a commercial subscription for production.

What are virtual threads (Project Loom)?

Virtual threads (Java 21) are lightweight threads managed by the JVM, not the OS. You can create millions of them with minimal overhead. They make blocking I/O as efficient as async code without the complexity of reactive programming. Spring Boot 3.2+ supports virtual threads natively.

🎯 Key Takeaways

1JDK = JRE + compiler + tools; always install JDK as a developer
2Since Java 11, no standalone JRE — use JDK everywhere or create one with jlink
3Use Eclipse Temurin or Amazon Corretto for free production use
4Multi-stage Docker builds: JDK for build, JRE for runtime
5Use LTS versions (11, 17, 21) in production
6Java 21 virtual threads are a major reason to upgrade

🎯 Practice this topic in interviews

↗ Where this topic fits

Sources

Sources / References

Use these Core Java references to verify the concept in official docs and continue into the most relevant SplashRide pages.

Related SplashRide pages