What is JDK JRE and JVM

The terms JDK JRE and JVM are used very frequently in java programming. Some programmers find it little difficult to understand what exactly they are, the differences in them and which one is needed for their requirement. Let's understand these things in this tutorial.

JDK JRE and JVM are basically the java software packages or part of the packages which contains tools and libraries that are needed to compile and execute java programs. Once you installed java, these tools and libraries get's installed in your system which enables you to compile and execute java programs.

What is tools in java ?

A tool is an utility or program which helps programmer to accomplish a task. For example javac, java, javap etc are tools. javac is used to compile a program while java is used to run a program. If you have installed java, you can see these tools(available as .exe files in windows) inside bin folder of java installation directory.

What is libraries in java ?

Libraries generally means a group of related classes and interfaces contained inside packages. In java, libraries mostly comes as .jar files. If you extract a jar file, you can see all the .class(compiled classes and interfaces) files included in that jar.

What is JDK in Java

JDK stands for java development kit. As the name itself suggest, JDK helps the programmer in development(compilation and execution) of java programs. It's a software package that contains tools and libraries needed for compilation and execution of java programs. If you are a programmer then you must need to install JDK first in your system in order to start programming in java. For windows os, this software generally comes in the form of .exe or .zip file.

jdk jre jvm

The JDK is a superset of JRE, which means it contains JRE in itself. Apart from JRE it includes tools for developing, debugging, and monitoring java applications. Some of the important tools are java(Java application launcher), javac(java compiler), javap(java disassembler), javadoc(java documentation tool) etc.

JDK = JRE + Development tools(eg. javac, javap, java, javadoc etc)

Does jdk exist physically in computer ?

Yes, JDK exists physically in computer. If java is installed in your computer, you can see the jdk in java installation directory. In windows os, by default it get's installed in C: directory as given in below image.

jdk location

Can we run java program without jdk ?

Yes, we can run a program without JDK if we have already compiled that program. If not compiled, then we can't run without JDK because java compiler(javac) is inside JDK, not in JRE. A compiled program(.class file) can be run with JRE only.

What is JRE in Java

JRE stands for java runtime environment. As the name itself suggests, it provides a runtime environment to your program for it's execution. As soon as you start running your program using java command, the job of JRE starts and it ends when either the program ran successfully or any error is thrown.

JRE is also a software package which contains JVM, runtime libraries and other supporting files needed to run a program. JRE does not contains tools like javac, javap etc but it contains tools like java, javaw etc since they are needed to run java programs. For windows os, the software generally comes in the form of .exe or .tar file.

JRE is a superset of JVM, as it contains JVM in itself. At runtime, JVM loads the required runtime libraries and files of JRE in memory in order to execute the program and generate the output.

JRE = JVM + runtime libraries(contains packages like util, math, lang etc.)+ runtime files

Does JRE physically exist ?

Yes, JRE also exists physically in computer. If java is installed in your computer, you can see the jre in java installation directory. It exists inside jdk directory. Current downloads of JDK provides a jre parallel to jdk as well.

What is JVM in Java

JVM stands for java virtual machine, a virtual machine which loads and executes java programs in memory. As soon as you run your program by using java command, a java virtual machine is created which has some default size of memory available for loading and executing classes, objects, variables etc of a program. The machine loads not only your class(program) but also other required classes and libraries as well which are needed to execute the program.

It's a virtual machine because you can not see this in your computer. Also it's java virtual machine, it can execute only java programs and applications. JVM is not a separate software package, instead it comes as part of JRE package. If you have installed JDK or JRE then you don't have to do anything else for JVM. it will be there. Let's see some of the tasks performed by JVM:

  • Loads code - Loads .class files in memory.
  • Verfies code - Verifies the bytecode.
  • Interprets code - Converts bytecode into machine specific code.
  • Provides runtime environment - Makes availability of dependent classes and libraries.
  • Executes code - Executes the code and generate the output.
  • Memory management - Manages memory for classes, objects etc. by using garbage collection.

Is JVM platform independent ?

No, JVM is platform dependent. There are different jvm implementations for different operating systems(windows, linux, MacOs etc) from different vendors. JVM along with bytecode makes java as WORA(write once, run anywhere) language.

Difference between JDK JRE and JVM

JDK JRE JVM
JDK stands for java development kit. JRE stands for java runtime environment. JVM stand for java virtual machine.
JDK is a software package. JRE is also a software package. JVM is not a separate software package, it's part of JRE.
Using JDK you can do both, compilation and execution of java programs. Using JRE you can do only execution of java programs. JVM is part of JRE, responsible for execution of your java programs.
JDK exists physically in your computer. JRE also exists physically in your computer. JVM does not exist physically in your computer.
You can download and install JDK in your computer. JRE can also be dowloaded and installed in your computer. JVM comes as part of JRE.
JDK is a superset of JRE. JRE is a subset of JDK but superset of JVM. JVM is a subset of JRE.
JDK contains tools like javac, javap, java, javadoc etc. JRE contains runtime tools like java, javaw etc. JVM doesn't contains any such tools.
★★★
  • JDK of one OS will not work on different OS, that is why Oracle provides options like 'JDK for Windows', 'JDK for Linux' etc. while downloading JDK.
  • An end user who wants to run java applications, JRE is sufficient for them as it contains everything needed to run java applications. While programmers need JDK as they require both, compilation and execution of java programs.
  • JDK JRE and JVM are platform dependent while java is platform independent.
  • If you download jdk, it contains jre and jvm as well.
  • JVM is an specification, JRE is an implementation of that given by Sun Micro Systems.