Difference Between the JVM, JRE, and JDK in Java
Java Applications
Java doesn't compile to machine code but instead compiles to Java bytecode. This is what makes Java so powerful. This allows for a write-once, run-anywhere approach. The tradeoff is that it comes with a runtime overhead.
If you are new to Java applications, it can be confusing what you need to get started. It can really be broken down in two ways. Are you running or developing a Java program?
JVM (Java Virtual Machine)
The JVM is a specification for a program that executes Java bytecode on a specific platform. Multiple programming languages outside of Java can be compiled into Java bytecode and executed on the JVM. JVM implementations are platform-specific and are available on several different software and hardware platforms.
JRE (Java Runtime Environment)
The JRE is an implementation of the JVM and includes all the libraries and components that are needed to execute a Java application. This is what you use if you want to run Java applications.
JDK (Java Development Kit)
The JDK is what you use if you want to develop Java applications. The JDK is a set of tools to develop Java applications and also comes with a JRE, so you can run your code as well. Some of the tools it comes with are the following:
- javac: The compiler for Java. This converts Java source code files into Java bytecode.
- javadoc: Used for generating documentation from the Javadoc in the source code.
- jar: This is used to generate and manage JAR (Java Archive) files. This uses a ZIP format and allows you to package up and deploy your Java application with a single file.
- jshell: A REPL (Read Eval Print Loop) used to execute Java code.
This is only a small piece of everything a JDK comes with.
Conclusion
When working with Java, you really only need to consider running a Java application or developing a Java application. Use a JRE when you need to run a Java application. Use the JDK when you need to both develop and run a Java application.