编者注:这个问题是在2009年提出的,世界在哪里不同。到2022年,标准的开源OpenJDK将只支持jdk。


JDK和JRE有什么区别?

它们的角色是什么,什么时候应该使用其中一个或另一个?


当前回答

上面的答案(Pablo)是非常正确的。这只是额外的信息。

顾名思义,JRE是一个环境。它基本上是一堆包含java相关文件的目录,即:

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.

JDK也是一组目录。它是JRE的超集,增加了一些功能:

Bin /已经被开发工具放大了。其中最重要的是javac;其他包括jar、javadoc和jshell。 添加了jmods/,用于保存标准库的JMOD文件。这些文件允许标准库与jlink一起使用。

其他回答

JRE即Java运行时环境。它是运行已编译Java程序所需的所有东西的包,包括Java虚拟机(JVM)、Java类库、Java命令和其他基础设施。但是,它不能用于创建新程序。

JDK是Java Development Kit,是Java的全功能SDK。它拥有JRE所拥有的一切,还包括编译器(javac)和工具(如javadoc和jdb)。它能够创建和编译程序。

通常,如果你只关心在电脑上运行Java程序,你只会安装JRE。这就是你所需要的。另一方面,如果您计划进行一些Java编程,则需要安装JDK。

有时,即使您不打算在计算机上进行任何Java开发,仍然需要安装JDK。例如,如果您正在使用JSP部署web应用程序,那么从技术上讲,您只是在应用服务器中运行Java程序。那么为什么需要JDK呢?因为应用服务器将JSP转换为Java servlet,并且需要使用JDK来编译servlet。我相信还有更多的例子。

上面的答案(Pablo)是非常正确的。这只是额外的信息。

顾名思义,JRE是一个环境。它基本上是一堆包含java相关文件的目录,即:

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.

JDK也是一组目录。它是JRE的超集,增加了一些功能:

Bin /已经被开发工具放大了。其中最重要的是javac;其他包括jar、javadoc和jshell。 添加了jmods/,用于保存标准库的JMOD文件。这些文件允许标准库与jlink一起使用。

JVM, JRE, JDK——这些都是Java语言的主干。每个组件单独工作。JDK和JRE在物理上是存在的,但JVM是一个抽象机器,这意味着它在物理上不存在。

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也是JDK的一个子系统,它提供了运行时工具,如JVM、类、可执行文件(如.jar文件)等。

JDK是Java Development Kit的缩写。它包含Java编程中使用的所有必要组件,如类、方法、swing、AWT、包、Java(解释器)、javac(编译器)、appletviewer (applet应用程序查看器)等。总之,它包含了开发应用程序所需的所有文件,无论是独立的还是基于web的。

JDK和JRE之间的区别在于,JDK是java的软件开发工具包,而JRE是运行程序的地方。

从官方java网站…

JRE (Java运行环境):

它是实际执行Java程序的Java虚拟机*的实现。 Java运行时环境是运行Java程序所需的插件。 JRE比JDK小,所以它需要更少的磁盘空间。 JRE可从 https://www.java.com 它包括JVM、核心库和其他附加组件,用于运行用Java编写的应用程序和小程序。

JDK (Java Development Kit)

它是一组软件,可以用来开发基于Java的应用程序。 开发Java应用程序需要Java开发工具包。 JDK需要更多的磁盘空间,因为它包含JRE和各种开发工具。 JDK可以免费下载/支持 https://www.oracle.com/technetwork/java/javase/downloads/ 它包括JRE、一组API类、Java编译器、Webstart和编写Java小程序和应用程序所需的附加文件。