refresh java logo

JDK JRE And JVM

JDK JRE and JVM are basically tools and libraries that are needed to compile and execute java programs or applications. Once you installed java, all these tools and libraries get's installed in your system which you can use for development and execution of your programs.

What is tools ?

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. These tools are available in bin folder of java installation directory.

What is libraries in java ?

Libraries generally means group of packages that contains related classes and interfaces. In java, libraries mostly comes as .jar files.

The terms JDK JRE and JVM are used very frequently in java programming language. Let's understand what these terms means and what these contains inside.

JDK

JDK stands for java development kit. As the name itself suggest, JDK helps the programmer in development(from compilation to execution) of programs or applications. It's a group of libraries and tools needed for compilation and execution of java programs.

jdk jre jvm

The JDK is a superset of the 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 exists physically in computer. If java is installed in your computer, you can see the jdk in java installation directory.

JDK = JRE + JVM

JRE

JRE stands for java runtime environment. JRE comes into picture as soon as you started running your program using java command. JRE contains JVM, class libraries and other supporting files. JRE does not contains tools and utilities such as compiler, debugger for developing applets and applications.

The JRE is a superset of the JVM, which means it contains JVM in itself. Apart from JVM it also contains runtime libraries that are needed to run the program. JVM that runs the program, uses these runtime libraries to execute the program and generate the output.

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.

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

Do I need JDK if I need to run a .class file of a java program ?

No, JRE is sufficient for you to run that program.

JVM

JVM stands for java virtual machine. A virtual machine that is responsible for loading and executing the java programs in memory. It also loads all the dependent classes of running class in memory. JVM provides memory to objects and variables of a class.

As soon as you run a program by using java command, a seperate jvm is created which has some default size of memory available for classes, objects, variables etc. 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 specific machine 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.

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.

★★★
  • 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. It contains everything needed to run java applications while a programmer must need JDK to compile and execute 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.