1074

Editors note: This question was asked in 2009 where the world was different. In 2022 the standard open sourced OpenJDK is JDK-only.


What is the difference between JDK and JRE?

What are their roles and when should I use one or the other?

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
i2ijeya
  • 15,952
  • 18
  • 63
  • 72
  • 13
    Nice and concise answer to this question can be found at: http://www.java.com/en/download/faq/techinfo.xml – Akshay Lokur Nov 14 '14 at 05:11
  • 7
    Possible duplicate of [What is the difference between JVM, JDK, JRE & OpenJDK?](http://stackoverflow.com/questions/11547458/what-is-the-difference-between-jvm-jdk-jre-openjdk) – kenorb Dec 10 '15 at 20:19
  • 9
    @kenorb based on timestamps, the linked question seems to be a duplicate of this one. – Ungeheuer Feb 13 '17 at 04:09

20 Answers20

1398

The JRE is the Java Runtime Environment. It is a package of everything necessary to run a compiled Java program, including the Java Virtual Machine (JVM), the Java Class Library, the java command, and other infrastructure. However, it cannot be used to create new programs.

The JDK is the Java Development Kit, the full-featured SDK for Java. It has everything the JRE has, but also the compiler (javac) and tools (like javadoc and jdb). It is capable of creating and compiling programs.

Usually, if you only care about running Java programs on computer you will only install the JRE. It's all you need. On the other hand, if you are planning to do some Java programming, you need to install the JDK instead.

Sometimes, even if you are not planning to do any Java development on a computer, you still need the JDK installed. For example, if you are deploying a web application with JSP, you are technically just running Java programs inside the application server. Why would you need the JDK then? Because the application server will convert JSP into Java servlets and needs to use the JDK to compile the servlets. I am sure that there are more examples.

vcovo
  • 336
  • 1
  • 3
  • 16
Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
  • 2
    There are a few jars specifically intended as extensions of Java; those can and should be placed in lib/ext. But putting any old application jars is not what this directory is intended for; it's an abuse of the extension mechanism and may cause problems later on. – Carl Smotricz Dec 15 '09 at 11:45
  • I have worked on JExcel API and I've set the classpath correctly and still there exists the problem. So i deployed it inside tlib/ext folder, which woks fine after that?? So what would be reason?? – i2ijeya Dec 15 '09 at 13:41
  • 3
    I don't have information to be completely sure, but my guess would be that either you didn't really set the classpath correctly, or you set the classpath for a different classloader than the one that ended up using your code. What makes lib/ext different from classpath extension is that lib/ext will affect *any* java app that uses that particular JRE - it's more foolproof than setting the classpath. – Carl Smotricz Dec 15 '09 at 18:55
  • A couple weeks ago I experienced a fairly massive failure that was corrected by changing my JAVA_HOME and Path environment variables to reference the JRE instead of the JDK. In what case would an app function using the JRE and fail with the JDK? I guess I should open a new question. An interesting note is that starting in version 1.6 the JRE is included with the JDK installation but unpacks at the same level as the JDK folder whereas in version 1.5 and prior the JRE folder is within the JDK. BTW: Good answer! – Jesse Ivy May 28 '15 at 17:56
  • OP, so then when java installer tells me there's an update and it is the latest JRE, I can just ignore the update and download a fresh version of the JDK and I'll have all the latest Java stuff? – Ungeheuer Oct 23 '16 at 21:50
  • so if JDK contains all of JRE, and the other programming necessities, then should/can I uninstall all the JRE stuff I have? I have JREs going back to 1.7.0 Update 45 – Ungeheuer Feb 13 '17 at 04:12
  • @Pablo Santa Cruz can you please tell me that is JRE or JDK physically exist? if yes then how? because i read it at this website which is saying that they physically exist can you please solve my confusion. https://www.javatpoint.com/difference-between-jdk-jre-and-jvm – Arsh Kaushal Jan 11 '18 at 04:48
  • @ArshKaushal By saying "they physically exist" they are referring to the fact that both of them (JDK and JRE) are installed and stored on the hard drive. On the contrary, JVM does not physically exist. It just runs on computer processor/memory. – Pablo Santa Cruz Jan 11 '18 at 12:54
  • Another example when JDK might be needed impliciltly is compiling an application from sources. User might not interact with JDK directly, but the underlying build system (cmake, msbuild, make, etc.) might need JDK to build the project. – dmytro.poliarush Dec 25 '19 at 06:30
165

The answer above (by Pablo) is very right. This is just additional information.

The JRE is, as the name implies, an environment. It's basically a bunch of directories with Java-related files, to wit:

  • bin/ contains Java's executable programs. The most important is java (and for Windows, javaw as well), which launches the JVM. There are some other utilities here as well, such as keytool and policytool.
  • conf/ holds user-editable configuration files for Java experts to play with.
  • lib/ has a large number of supporting files: some .jars, configuration files, property files, fonts, translations, certs, etc. – all the "trimmings" of Java. The most important is modules, a file that contains the .class files of the Java standard library.
  • At a certain level, the Java standard library needs to call into native code. For this purpose, the JRE contains some .dll (Windows) or .dylib (macOS) or .so (Linux) files under bin/ or lib/ with supporting, system-specific native binary code.

The JDK is also a set of directories. It is a superset of the JRE, with some additions:

  • bin/ has been enlarged with development tools. The most important of them is javac; others include jar, javadoc and jshell.
  • jmods/, which holds JMOD files for the standard library, has been added. These files allow the standard library to be used with jlink.
MultiplyByZer0
  • 6,302
  • 3
  • 32
  • 48
Carl Smotricz
  • 66,391
  • 18
  • 125
  • 167
  • 1
    Does this mean I can set my path variables to the JDK and that's it? – Brady Aug 28 '14 at 16:16
  • 4
    @Brady: Yes, I think so. That works fine for me, at least. As a developer, I essentially ignore the JRE. If there are special cases where you specifically want the JRE, I'm not aware of them. – Carl Smotricz Aug 29 '14 at 08:54
  • The JRE can work with only compiled Java code, right? – SexyBeast Oct 27 '14 at 21:00
  • 2
    @Cupidvogel, since there's no compiler in the JRE, I guess you could say that. The JRE is there for *running* (compiled) Java code, while the JDK also gives you the tools to develop it. – Carl Smotricz Oct 30 '14 at 01:32
  • 1
    So basically JDK includes a compiler (like Javac) to compile the code, a JRE (run-time system) to execute the compiled code, and other tools meant just to make programmer's life in developing easy, correct? So AFAIU, only the Javac and JRE are the really necessary tools here. Why then, many times, software installations , upgrades insist on a JDK to be present? – SexyBeast Oct 30 '14 at 20:11
  • I'm on a Mac. If I am running the 1.8 version of the JRE as my default and then I install the 1.6 version of the JDK, could I then instruct some applications to use the JRE inside the 1.6 JDK? (My Adobe CS4 only runs under 1.6). If so, how? – Darryl Nov 02 '14 at 21:18
  • @Darryl, sorry about the late response! I have some suggestions but they're untested. From easiest (if it works) to hardest, here are things to try: (1) write a bash script in which you set and export JAVA_HOME to the location of your 1.6 jdk, and call CS4 from that. (2) rather than setting JAVA_HOME, write a script to rearrange your PATH such that the jdk 1.6 /bin directory precedes the location of your 1.8, so "java" will call 1.6 rather than 1.8 . If either method works from a bash script you can then build an icon to call that script for you from your GUI shell. – Carl Smotricz Apr 16 '15 at 08:23
  • thanks for the inputs. I instead took the easiest route which was to upgrade my CS4 to the latest version. cheers. – Darryl Apr 16 '15 at 15:00
153

enter image description here

JDK is a superset of JRE, and contains everything that is in JRE, plus tools such as the compilers and debuggers necessary for developing applets and applications. JRE provides the libraries, the Java Virtual Machine (JVM), and other components to run applets and applications written in the Java programming language.

Chinbold Gansukh
  • 1,809
  • 1
  • 15
  • 6
  • 5
    Cool diagram! I'm a little confused that the java command is pictured outside the JRE which isn't correct. I don't understand why there are separate files for the java command when the JDK is installed which identical at least in size. In what case would an app function using the JRE and fail with the JDK? Experienced this recently and should probably back track to replicate and get to the bottom of it... – Jesse Ivy May 28 '15 at 19:11
133

In layman terms: JDK is grandfather JRE is father and JVM is their son. [i.e. JDK > JRE > JVM ]

JDK = JRE + Development/debugging tools

JRE = JVM + Java Packages Classes(like util, math, lang, awt,swing etc)+runtime libraries.

JVM = Class loader system + runtime data area + Execution Engine.

In other words if you are a Java programmer you will need JDK in your system and this package will include JRE and JVM as well but if you are normal user who like to play online games then you will only need JRE and this package will not have JDK in it.

JVM :

The Java Virtual Machine (JVM) is the virtual machine that run the Java bytecodes. The JVM doesn't understand Java source code, that's why you compile your *.java files to obtain *.class files that contain the bytecodes understandable by the JVM. It's also the entity that allows Java to be a "portable language" (write once, run anywhere). Indeed there are specific implementations of the JVM for different systems (Windows, Linux, MacOS, see the wikipedia list..), the aim is that with the same bytecodes they all give the same results.

JDK and JRE

To explain the difference between JDK and JRE, the best is to read the Oracle documentation and consult the diagram :

Java Runtime Environment (JRE)

The Java Runtime Environment (JRE) provides the libraries, the Java Virtual Machine, and other components to run applets and applications written in the Java programming language. In addition, two key deployment technologies are part of the JRE: Java Plug-in, which enables applets to run in popular browsers; and Java Web Start, which deploys standalone applications over a network. It is also the foundation for the technologies in the Java 2 Platform, Enterprise Edition (J2EE) for enterprise software development and deployment. The JRE does not contain tools and utilities such as compilers or debuggers for developing applets and applications.

Java Development Kit (JDK)

The JDK is a superset of the JRE, and contains everything that is in the JRE, plus tools such as the compilers and debuggers necessary for developing applets and applications.

Note that Oracle is not the only one to provide JDK.

JIT Compile Process (Courtesy: Oracle documentation)

JDK > JRE > JVM

enter image description here

Jaimin Patel
  • 4,559
  • 3
  • 32
  • 35
  • When you say "compile" or "compiler", it is extremely confusing in this context to which you are referring to: turning java source code into java byte code, or turning java byte code into machine code. – JoseOrtiz3 Jan 26 '19 at 21:30
  • 2
    Nice! I like the grandfather, father and son analogy. :D – Emzor Mar 26 '20 at 20:08
  • Yeah Thanks, it's very easy to understand who is not much familiar with these terms. – Jaimin Patel Apr 16 '20 at 13:48
  • 1
    @JoseOrtiz3: In Java using the term "compile" unqualified generally means "turning source code into byte code". "JIT (just-in-time) compile" generally means "turning byte code into machine code". It is called "just-in-time" because it is performed by the JVM as the program is running. – Lii Oct 22 '22 at 20:42
26

From Official java website...

JRE (Java Runtime environment):

  • It is an implementation of the Java Virtual Machine* which actually executes Java programs.
  • Java Runtime Environment is a plug-in needed for running java programs.
  • The JRE is smaller than the JDK so it needs less Disk space.
  • The JRE can be downloaded/supported freely from https://www.java.com
  • It includes the JVM , Core libraries and other additional components to run applications and applets written in Java.

JDK (Java Development Kit)

  • It is a bundle of software that you can use to develop Java based applications.
  • Java Development Kit is needed for developing java applications.
  • The JDK needs more Disk space as it contains the JRE along with various development tools.
  • The JDK can be downloaded/supported freely from https://www.oracle.com/technetwork/java/javase/downloads/
  • It includes the JRE, set of API classes, Java compiler, Webstart and additional files needed to write Java applets and applications.
Wanna Coffee
  • 2,742
  • 7
  • 40
  • 66
26

One difference from a debugging perspective:

To debug into Java system classes such as String and ArrayList, you need a special version of the JRE which is compiled with "debug information". The JRE included inside the JDK provides this info, but the regular JRE does not. Regular JRE does not include this info to ensure better performance.

What is debugging information? Here is a quick explanation taken from this blog post:

Modern compilers do a pretty good job converting your high-level code, with its nicely indented and nested control structures and arbitrarily typed variables into a big pile of bits called machine code (or bytecode in case of Java), the sole purpose of which is to run as fast as possible on the target CPU (virtual CPU of your JVM). Java code gets converted into several machine code instructions. Variables are shoved all over the place – into the stack, into registers, or completely optimized away. Structures and objects don’t even exist in the resulting code – they’re merely an abstraction that gets translated to hard-coded offsets into memory buffers.

So how does a debugger know where to stop when you ask it to break at the entry to some function? How does it manage to find what to show you when you ask it for the value of a variable? The answer is – debugging information.

Debugging information is generated by the compiler together with the machine code. It is a representation of the relationship between the executable program and the original source code. This information is encoded into a pre-defined format and stored alongside the machine code. Many such formats were invented over the years for different platforms and executable files.

David Robinson
  • 77,383
  • 16
  • 167
  • 187
Steve
  • 299
  • 3
  • 7
11

JVM, JRE, JDK - these are all the backbone of Java language. Each component work separately. JDK and JRE physically exist but JVM is an abstract machine that means it does not physically exist.

JVM is the subsystem of JDK and JRE which is used to check the intermediate code known as "bytecode". It first loads the "class file" (having .c extension) generated by the Java compiler (javac) through JVM subsystem classloader and classified memory location (class area, stack, heap and pc registers) according to their use. Then it checks all the bytecode to ensure that it is returned in Java and all memory accessibility access by the network. The interpreter's work starts after that where it checks the whole program line by line. The results are finally shown in the console/browser/application through JRE (Java Runtime Environment) which runtime facilities.

JRE is also a subsystem of JDK which provides runtime facilities like JVM, classes, executable files like .jar file, etc.

JDK stands for Java Development Kit. It contains all necessary components used in Java programming such as class, method, swing, AWT, package, Java (interpreter), javac (compiler), appletviewer (applet application viewer), etc. To conclude, it contains every file required for developing applications, whether standalone or web-based.

emphasent
  • 73
  • 2
  • 9
Kanan J
  • 121
  • 1
  • 5
9

Here's a simple response directly from Oracle http://docs.oracle.com/javase/7/docs/technotes/guides/

Java SE Runtime Environment (JRE)

The JRE provides the libraries, Java virtual machine, and other components necessary for you to run applets and applications written in the Java programming language. This runtime environment can be redistributed with applications to make them free-standing.

Java SE Development Kit (JDK)

The JDK includes the JRE plus command-line development tools such as compilers and debuggers that are necessary or useful for developing applets and applications.

Alex
  • 9,250
  • 11
  • 70
  • 81
8

JRE

JRE is an acronym for Java Runtime Environment.It is used to provide runtime environment.It is the implementation of JVM.It physically exists.It contains set of libraries + other files that JVM uses at runtime.

JDK

JDK is an acronym for Java Development Kit.It physically exists.It contains JRE + development tools.

Link :- http://www.javatpoint.com/difference-between-jdk-jre-and-jvm

Usually, when you only care about running Java programs on your browser or computer you will only install JRE. It's all you need. On the other hand, if you are planning to do some Java programming, you will also need JDK.

Nikhil Kumar
  • 2,618
  • 3
  • 21
  • 24
8

JVM, JRE and JDK are platform dependent because configuration of each OS differs. But, Java is platform independent.

Java Virtual Machine (JVM) is a run-time system that executes Java bytecode.

JRE is the environment (standard libraries and JVM) required to run Java applications.

The JDK includes the JRE plus command-line development tools such as compilers and debuggers that are necessary or useful for developing applets and applications.

Chintan Patni
  • 81
  • 1
  • 3
7

JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed.

JRE is an acronym for Java Runtime Environment.It is used to provide runtime environment.It is the implementation of JVM.It physically exists.It contains set of libraries + other files that JVM uses at runtime

JDK is an acronym for Java Development Kit.It physically exists.It contains JRE + development tools

Pruthvi
  • 375
  • 3
  • 7
7

If you want to run Java programs, but not develop them, download the Java Run-time Environment, or JRE. If you want to develop them, download the Java Development kit, or JDK

JDK

Let's called JDK is a kit, which include what are those things need to developed and run java applications.

JDK is given as development environment for building applications, component s and applets.

JRE

It contains everything you need to run Java applications in compiled form. You don't need any libraries and other stuffs. All things you need are compiled.

JRE is can not used for development, only used for run the applications.

nifCody
  • 2,394
  • 3
  • 34
  • 54
6

A clear understanding of these terms(JVM, JDK, JRE) are essential to grasp their usage and differences.

JVM Java Virtual Machine (JVM) is a run-time system that executes Java bytecode. The JVM is like a virtual computer that can execute a set of compiled instructions and manipulate memory locations. When a Java compiler compiles source code, it generates a highly optimized set of instructions called bytecode in a .class file. The JVM interprets these bytecode instructions and converts them to machine-specific code for execution.

JDK The Java Development Kit (JDK) is a software development environment that you can use to develop and execute Java applications. It includes the JRE and a set of programming tools, such as a Java compiler, interpreter, appletviewer, and document viewer. The JDK is implemented through the Java SE, Java EE, or Java ME platforms.

JRE The Java Runtime Environment (JRE) is a part of the JDK that includes a JVM, core classes, and several libraries that support application development. Though the JRE is available as part of the JDK, you can also download and use it separately.

For complete understanding you can see my Blog : Jdk Jre Jvm and differences

6

If you are a Java programmer you will need JDK in your system and this package will include JRE and JVM as well but if you are normal user who like to play online games then you will only need JRE and this package will not have JDK in it.

JVM

JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed.

JVMs are available for many hardware and software platforms. JVM, JRE and JDK are platform dependent because configuration of each OS differs. But, Java is platform independent.

JRE

It contains everything you need to run Java applications in compiled form. You don't need any libraries and other stuffs. All things you need are compiled.

JRE is can not used for development, only used for run the applications.

Java SE Development Kit (JDK)

The JDK includes the JRE plus command-line development tools such as compilers and debuggers that are necessary or useful for developing applets and applications.

(Sources: GeeksForGeeks Q&A, Java Platform Overview)

Jonathan Lam
  • 16,831
  • 17
  • 68
  • 94
Harita M
  • 119
  • 1
  • 4
  • There was plagiarism from multiple sites (for the JVM and JDK sections). Next time, please cite your sources -- it is not your original work. – Jonathan Lam Aug 11 '16 at 12:11
6

Simply :

JVM is the virtual machine Java code executes on

JRE is the environment (standard libraries and JVM) required to run Java applications

JDK is the JRE with developer tools and documentation

ABP
  • 69
  • 1
  • 2
5

jdk is necessary to compile to code and convert java code to byte codes while jre is necessary for executing the byte codes.

Mayank Jain
  • 95
  • 1
  • 9
5

JDK includes the JRE plus command-line development tools such as compilers and debuggers that are necessary or useful for developing applets and applications.

JRE is basically the Java Virtual Machine where your Java programs run on. It also includes browser plugins for Applet execution.

JDK is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed.

So, Basically JVM < JRE < JDK as per @Jaimin Patel said.

Dev
  • 59
  • 1
  • 4
4

The difference between JDK and JRE is that JDK is the software development kit for java while JRE is the place where you run your programs.

Samarth Shah
  • 941
  • 1
  • 8
  • 7
4

suppose, if you are a developer then your role is to develop program as well as to execute the program. so you must have environment for developing and executing, which is provided by JDK.

suppose, if you are a client then you don't have to worry about developing.Just you need is, an environment to run program and get result only, which is provided by JRE.

JRE executes the application but JVM reads the instructions line by line so it's interpreter.

JDK=JRE+Development Tools

JRE=JVM+Library Classes

3

JRE

JRE is an acronym for Java Runtime Environment.It is used to provide runtime environment.It is the implementation of JVM. It physically exists. It contains set of libraries + other files that JVM uses at runtime.

Implementation of JVMs are also actively released by other companies besides Sun Micro Systems.

enter image description here

JDK

JDK is an acronym for Java Development Kit.It physically exists.It contains JRE + development tools.

enter image description here

Akila
  • 1,258
  • 2
  • 16
  • 25