What is the difference between JDK and JRE?
What are their roles and when should I use one or the other?
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 .jar
s, 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..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
.