Difference between JDK, JRE and JVM

Filed Under: Java

Difference between JDK and JRE and JVM is one of the popular interview questions. You might also be asked to explain JDK vs JRE vs JVM.

Difference between JDK and JRE and JVM

difference between jdk and jre and jvm, jdk vs jre vs jvm, jdk jre jvm

JDK, JRE, and JVM are core concepts of Java programming language. Although they all look similar and as a programmer, we don’t care about these concepts a lot, but they are different and meant for specific purposes. It’s one of the common java interview questions and this article will explain each one of these and what is the difference between them.

JDK

Java Development Kit is the core component of Java Environment and provides all the tools, executables and binaries required to compile, debug and execute a Java Program. JDK is a platform-specific software and that’s why we have separate installers for Windows, Mac, and Unix systems. We can say that JDK is the superset of JRE since it contains JRE with Java compiler, debugger, and core classes. The current version of JDK is 11 also known as Java 11.

JVM

JVM is the heart of Java programming language. When we run a program, JVM is responsible for converting Byte code to the machine specific code. JVM is also platform dependent and provides core java functions like memory management, garbage collection, security etc. JVM is customizable and we can use java options to customize it, for example allocating minimum and maximum memory to JVM. JVM is called virtual because it provides an interface that does not depend on the underlying operating system and machine hardware. This independence from hardware and the operating system is what makes java program write-once-run-anywhere.

JRE

JRE is the implementation of JVM, it provides a platform to execute java programs. JRE consists of JVM and java binaries and other classes to execute any program successfully. JRE doesn’t contain any development tools like java compiler, debugger etc. If you want to execute any java program, you should have JRE installed but we don’t need JDK for running any java program.

JDK vs JRE vs JVM

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.

Just-in-time Compiler (JIT)

Sometimes we heard this term and being it a part of JVM it confuses us. JIT is part of JVM that optimizes byte code to machine specific language compilation by compiling similar byte codes at the same time, hence reducing overall time taken for the compilation of byte code to machine specific language.

Comments

  1. Love Gupta says:

    Below text from this article –
    JVM is called virtual because it provides an interface that does not depend on the underlying operating system and machine hardware. This independence from hardware and the operating system is what makes java program write-once-run-anywhere.

    Does JVM provided interface not depend on underlying platform. If that interface (i.e. loding, linking, JIT, interpreter etc) is same for all platforms then why JVMs are different for each platform.
    I feel this interface which takes byte code as input and gives you end result is platform dependent which makes Java platform independent.
    May be you can correct my understanding.

  2. Saangram says:

    Thanks a lot!

  3. srinivas narla says:

    Please update the version of Java.

  4. Vitthal Kasbe says:

    very well explained,

  5. Sailendra says:

    JVM is also platform dependent under JVM , i hope this is a TYPO.

  6. Bibhu Prasad Tripathy says:

    I wish to know step by step execution and impacts , functionalties for jdk, jvm (including memory areas )m jre ?
    I mean i wish to know end-to-end flow when a java program gets executed (specially through various section inside JVM – among those i also wish to know impacts on memory areas (heap,stack, native area ), class loaders e.t.c.

  7. debu says:

    Hi Pankaj,

    Thanks for such useful tutorials. You are doing great. Keep it up.

    I have some doubt about JIT. You said that it optimizes byte code to machine specific language compilation by compiling similar byte codes at same time.
    My question is that while converting byte code into machine specific code do all the byte code passes through JIT. Because i have heared that only interpretor also have its role in converting byte code into machine specific code. Or only similar byte codes are passes through JIT and rest all passes through interpreter.

    It would be very useful if you can elaborate it with some example.

    1. debu says:

      i have heared that interpreter also have its role in converting byte code into machine specific code. Or only similar byte codes are passes through JIT and rest all passes through interpreter.

  8. gansai says:

    This is to just let you know that you could update regarding ‘Current JDK Version’ information.

  9. Mike says:

    I’m confused when I go to Oracles site to download the JDK and they ask if you want JDK for Java EE or JDK for Java SE. What if I want to ability to develop both. Do I really have to install 2 separate JDKs?

    1. Pankaj says:

      You need JDK Standard Edition (JDK SE), that’s what is there on http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

      Where do you see JDK for Java EE option?

  10. sambasivarao says:

    Thanks .Good one.

  11. Rishi Raj says:

    Thanks again for such good posts.

    One change in the current post suggested:
    The second point “JDK and JRE both comes with JVM.” under JDK vs JRE vs JVM may be read in ambiguous manner. Please make it more specific and clearer. Suggested conversions: “JDK and JRE both contain JVM.”; “JVM is pre-included in JDK and JRE.” These conversion indicate one-way containment.

    1. Pankaj says:

      Point taken, updated the post to make it more clear.

      Thanks for the feedback.

Leave a Reply

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

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages