Understanding JVM, JRE and JDK

Advertisements

JVM (Java Virtual Machine), JDK (Java Development Kit) and JRE (Java Runtime Environment) are fundamental concepts in the Java programing language. They look very similar, and they are usually misused by programmers. It’s very important to know its differences because every one is a piece with an specific purposes.

Also, it’s a common questions in interviews for a Java developer position to explain those concepts. So, let´s try to understand better each one of these terms.

JVM

The Java Virtual Machine (JVM) is the core of the Java programming language. Have you heard the famous phrase about Java

Write once, runs everywhere

Well, the key behind that phrase is the JVM. It’s charge of converting the bytecode to machine specific code. It interface doesn’t depend on the underlying Operative System and hardware, but it implementation does. In addition to that, the JVM is responsible for: memory management, garbage collection, security, and more.

Different companies besides Oracle (owner of Java) released different implementation of the JVM. A list of JVM:

  • HotSpot, the official one, distributed by Oracle
  • GraalVM, based on HotSpot and OpenJDK but it’s polyglot and supports more than JVM language, like NodeJS, Ruby, Python. I wrote an article some weeks ago about it.
  • Azul Zulu, also based on OpenJDK.

JRE

This is what you need to install in order to run a java application in a machine. It provides the environment necessary for that purposes, and consists of:

  • JVM, as mentioned before, that handles memory and converts bytecode to machine instructions.
  • Core binaries and libraries like:
    • Lang and Util libraries,
    • Collections
    • Logging
    • Concurrency Utils
    • JMX libraries
    • JNI
    • Input and Output (I/O)
  • Some other configuration files.

JDK

The Java Development Kit, is what you need to create applications in Java, it consists of the JRE (which includes the JVM) and some development tools.

  • Java Compiler (javac)
  • Java Doc, the documentation generator
  • Debugger, Profilers, and more.
  • REPL tool, from Java 9, this tool allows to run java statements in a console.

Summary

Let’s look at some of the important difference between JDK, JRE, and JVM.

  1. JDK is for development purpose whereas JRE is for running the java programs.
  2. JDK and JRE both contains JVM so that we can run our java program.
  3. JVM is the heart of java programming language and provides platform independence.

References

Advertisements

Leave a Reply

Your email address will not be published. Required fields are marked *