keepcalculator

06 Numbers and Powers

JDK vs JRE vs JVM: What to Install

Card No. 06·33974 · Updated · Standard formula, shown below

To run Java programs you need the JRE; to develop them you need the JDK; and the JVM is the engine inside both that actually executes Java bytecode. If you are just running a Java application, install the JRE (or a JDK, which includes it). If you are writing or compiling Java code, install the JDK. The JVM is not something you install separately—it comes bundled with both.

What Each Component Does

The Java ecosystem is often confusing because three acronyms—JDK, JRE, and JVM—are used interchangeably, but they refer to distinct layers.

  • JVM (Java Virtual Machine) – The runtime engine that executes Java bytecode. It translates bytecode into machine-specific instructions and manages memory, garbage collection, and security. The JVM is platform-dependent; there are different builds for Windows, macOS, and Linux.
  • JRE (Java Runtime Environment) – A bundle that includes the JVM, core class libraries (like java.lang, java.util), and supporting files needed to run Java applications. It does not include development tools like a compiler or debugger.
  • JDK (Java Development Kit) – A superset of the JRE that adds development tools: the javac compiler, jar archiver, javadoc documentation generator, and debugger. If you want to write and compile Java code, you need the JDK.

Think of it as a restaurant: the JVM is the chef who cooks the food, the JRE is the kitchen with all necessary utensils, and the JDK is the full restaurant including the recipe books and training manuals.

How They Work Together

When you compile a Java source file (.java), the JDK’s javac tool converts it into bytecode (.class files). That bytecode is platform-independent—it can run on any device that has a JVM. At runtime, the JVM loads the bytecode, verifies it for security, and executes it using an interpreter and Just-In-Time (JIT) compiler. The JIT compiler translates frequently executed bytecode into native machine code for better performance.

The JRE provides the class libraries that your program calls (like System.out.println), and the JVM handles memory allocation and garbage collection. Without the JVM, the bytecode is just a file; without the JRE, the JVM lacks the standard libraries; without the JDK, you cannot create new bytecode from source.

Which One Should You Install?

Your choice depends entirely on your role:

  • End user running a Java application – Install the JRE (or a JDK, which is backward-compatible). Many applications bundle their own JRE, so you might not need anything. If you do, download the latest JRE from a trusted source like Oracle or Adoptium.
  • Developer writing Java code – Install the JDK. It includes the JRE, so you get everything. Most IDEs (like IntelliJ IDEA, Eclipse, or VS Code) require a JDK to compile and run your projects.
  • Student learning Java – Install the JDK. You will need the compiler to practice, and most tutorials assume you have it.
  • Server administrator running Java-based services – Often the JRE is sufficient, but some tools (like Tomcat) may need a JDK for JSP compilation. Check the specific software’s documentation.

In practice, many developers simply install the JDK and never worry about the JRE separately. Since JDK 11, Oracle and other vendors offer builds that include both, so there’s little reason to install a standalone JRE unless you have a very specific need.

Common Misconceptions and Pitfalls

One frequent error is confusing the JVM with the JRE. The JVM is a process, not a downloadable package. When you install the JRE, you get a JVM inside it. Another mistake is assuming that having a JRE means you can compile code—it does not. The javac command will not exist if only the JRE is installed.

A related issue is version mismatch. If you compile with JDK 17 but run with JRE 8, you will get an UnsupportedClassVersionError because the bytecode version is newer than what the JVM can read. Always ensure the runtime version is equal to or newer than the compiler version.

Another pitfall is having multiple Java installations. On Windows, the PATH environment variable might point to an old JDK, causing you to run a different version than expected. Use java -version and javac -version to verify which versions are active.

How to Install and Verify

Installation steps vary by operating system, but the general flow is:

  1. Download the installer from a trusted source (e.g., Oracle JDK, Adoptium Eclipse Temurin, or your package manager).
  2. Run the installer and follow the prompts. On Windows, note the installation directory.
  3. Set the JAVA_HOME environment variable to the installation path (e.g., C:\Program Files\Java\jdk-17).
  4. Add %JAVA_HOME%\bin to your PATH (Windows) or $JAVA_HOME/bin (Linux/macOS).
  5. Open a new terminal and run java -version to check the runtime, and javac -version to check the compiler.

If you see “command not found,” the PATH is not set correctly. If you see an older version than expected, check for other Java installations that might be taking precedence.

Cost and Licensing Considerations

Oracle’s JDK has a paid license for commercial use, but there are many free and open-source alternatives. The most popular is Eclipse Temurin (formerly AdoptOpenJDK), which is free and TCK-tested. Other options include Amazon Corretto, Azul Zulu, and Red Hat OpenJDK. These builds are functionally equivalent to Oracle’s for most purposes.

The JRE alone is rarely distributed separately anymore; most vendors provide a full JDK that includes the runtime. For production servers, using a free JDK build is common and cost-effective.

Alternatives and Future Directions

If you are new to Java, you might consider using a build tool like Maven or Gradle, which automatically manage the JDK version for your project. For containerized environments, you can use a Docker image that already has a JRE or JDK, such as eclipse-temurin:17-jre for a lightweight runtime.

There is also the GraalVM project, which can compile Java applications into native executables, removing the need for a JVM at runtime. This is useful for microservices and CLI tools, but it is not a drop-in replacement for the standard JDK.

Frequently Asked Questions

Do I need to install both JDK and JRE?

No. The JDK includes the JRE, so installing the JDK gives you both. Installing a separate JRE is only necessary if you want a minimal runtime without development tools, which is rare.

What is the difference between OpenJDK and Oracle JDK?

OpenJDK is the open-source reference implementation of Java. Oracle JDK is built from OpenJDK but includes additional commercial features and support. For most users, OpenJDK builds like Temurin are free and sufficient.

Why do I get “UnsupportedClassVersionError”?

This error occurs when the bytecode was compiled with a newer Java version than the JVM that is trying to run it. For example, compiling with JDK 17 and running with JRE 11. Upgrade your runtime or recompile with an older JDK.

Can I have multiple JDK versions installed?

Yes. You can install multiple versions and switch between them by changing the JAVA_HOME and PATH variables. Tools like SDKMAN (on Unix) or manual environment configuration make this easy.

Is the JVM the same as the Java interpreter?

No. The JVM includes an interpreter, but it also has a JIT compiler that converts bytecode to native code for performance. The interpreter alone would be too slow for complex applications.

What is the smallest Java installation I need for a simple program?

For a simple “Hello World” program, you need the JDK to compile it and the JRE (or just the JDK) to run it. If you are distributing the program, you can bundle a JRE with it, but the end user does not need a JDK.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →