Java JDK 和 JRE 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1906445/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between JDK and JRE?
提问by i2ijeya
What is the difference between JDK and JRE?
JDK 和 JRE 有什么区别?
What are their roles and when should I use one or the other?
它们的作用是什么,我什么时候应该使用其中一个?
采纳答案by Pablo Santa Cruz
The JREis 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.
该JRE是Java运行时环境。它是运行编译后的 Java 程序所需的一切的包,包括 Java 虚拟机 (JVM)、Java 类库、java
命令和其他基础设施。但是,它不能用于创建新程序。
The JDKis 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.
在JDK是Java开发工具包,Java的功能全面的SDK。它拥有 JRE 所拥有的一切,还有编译器 ( javac
) 和工具(如javadoc
和jdb
)。它能够创建和编译程序。
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.
通常,如果您只关心在计算机上运行 Java 程序,您只会安装 JRE。这就是你所需要的。另一方面,如果您打算进行一些 Java 编程,则需要安装 JDK。
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.
有时,即使您不打算在计算机上进行任何 Java 开发,您仍然需要安装 JDK。例如,如果您使用 JSP 部署 Web 应用程序,那么从技术上讲,您只是在应用程序服务器内运行 Java 程序。那你为什么需要JDK?因为应用服务器会将JSP 转换成Java servlet,需要使用JDK 来编译servlet。我相信还有更多的例子。
回答by Carl Smotricz
The answer above (by Pablo) is very right. This is just additional information.
上面的答案(由 Pablo 提供)非常正确。这只是附加信息。
The JREis, as the name implies, an environment. It's basically a bunch of directories with Java-related files, to wit:
该JRE是,顾名思义,一个环境。它基本上是一堆包含 Java 相关文件的目录,即:
bin/
contains Java's executable programs. The most important isjava
(and for Windows,javaw
as well), which launches the JVM. There are some other utilities here as well, such askeytool
andpolicytool
.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 ismodules
, 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 underbin/
orlib/
with supporting, system-specific native binary code.
bin/
包含 Java 的可执行程序。最重要的是java
(对于 Windowsjavaw
也是如此),它会启动 JVM。这里还有一些其他实用程序,例如keytool
和policytool
。conf/
保存用户可编辑的配置文件,供 Java 专家使用。lib/
有大量的支持文件:一些.jar
s、配置文件、属性文件、字体、翻译、证书等——所有Java的“修剪”。最重要的是modules
,一个包含.class
Java 标准库文件的文件。- 在一定程度上,Java 标准库需要调用本地代码。为此,JRE 包含一些
.dll
(Windows) 或.dylib
(macOS) 或.so
(Linux) 文件,这些文件位于bin/
或lib/
带有支持的特定于系统的本机二进制代码。
The JDKis also a set of directories. It is a superset of the JRE, with some additions:
在JDK也是一组目录。它是 JRE 的超集,并添加了一些内容:
bin/
has been enlarged with development tools. The most important of them isjavac
; others includejar
,javadoc
andjshell
.jmods/
, which holds JMOD files for the standard library, has been added. These files allow the standard library to be used withjlink
.
bin/
已通过开发工具扩大。其中最重要的是javac
; 其他包括jar
、javadoc
和jshell
。jmods/
已添加用于保存标准库的 JMOD 文件的 。这些文件允许标准库与jlink
.
回答by Wanna Coffee
From Official java website...
从官方java网站...
JRE (Java Runtime environment):
JRE(Java 运行时环境):
- 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.
- 它是 Java 虚拟机* 的一种实现,它实际执行 Java 程序。
- Java Runtime Environment 是运行java程序所需的插件。
- JRE 比 JDK 小,因此它需要的磁盘空间更少。
- JRE 可以从https://www.java.com免费下载/支持
- 它包括 JVM 、核心库和其他附加组件,用于运行用 Java 编写的应用程序和小程序。
JDK (Java Development Kit)
JDK(Java 开发工具包)
- 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.
- 它是一组软件,可用于开发基于 Java 的应用程序。
- 开发 Java 应用程序需要 Java Development Kit。
- JDK 需要更多磁盘空间,因为它包含 JRE 以及各种开发工具。
- JDK 可以从https://www.oracle.com/technetwork/java/javase/downloads/免费下载/支持
- 它包括 JRE、API 类集、Java 编译器、Webstart 以及编写 Java 小程序和应用程序所需的其他文件。
回答by Steve
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.
要调试到 Java 系统类(如 String 和 ArrayList)中,您需要使用“调试信息”编译的特殊版本的 JRE。JDK 中包含的 JRE 提供了此信息,但常规 JRE 不提供。常规 JRE 不包含此信息以确保更好的性能。
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.
现代编译器在转换高级代码方面做得非常好,它具有良好的缩进和嵌套控制结构以及任意类型的变量,将其转换为一大堆称为机器代码(或 Java 中的字节码)的位,其唯一目的是在目标 CPU(JVM 的虚拟 CPU)上尽可能快地运行。Java 代码被转换成几个机器代码指令。变量被推到各处——进入堆栈、进入寄存器或完全优化掉。结构和对象甚至不存在于生成的代码中——它们只是一种抽象,可以转换为硬编码的偏移量到内存缓冲区中。
那么,当您要求调试器在某个函数的入口处中断时,它如何知道在哪里停止呢?当您向它询问变量的值时,它如何设法找到要向您显示的内容?答案是——调试信息。
调试信息由编译器与机器代码一起生成。它是可执行程序与原始源代码之间关系的表示。此信息被编码为预定义格式并与机器代码一起存储。多年来,为不同的平台和可执行文件发明了许多这样的格式。
回答by Chinbold Gansukh
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.
JDK 是 JRE 的超集,包含 JRE 中的所有内容,以及开发小程序和应用程序所需的编译器和调试器等工具。JRE 提供了库、Java 虚拟机 (JVM) 和其他组件来运行用 Java 编程语言编写的小程序和应用程序。
回答by Nikhil Kumar
JRE
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.
JRE是Java Runtime Environment的首字母缩写,用于提供运行时环境,是JVM的实现,物理存在,包含JVM在运行时使用的一组库+其他文件。
JDK
JDK
JDK is an acronym for Java Development Kit.It physically exists.It contains JRE + development tools.
JDK是Java Development Kit的首字母缩写,物理存在,包含JRE+开发工具。
Link :- http://www.javatpoint.com/difference-between-jdk-jre-and-jvm
链接:- 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.
通常,当您只关心在浏览器或计算机上运行 Java 程序时,您只会安装 JRE。这就是你所需要的。另一方面,如果您打算进行一些 Java 编程,则还需要 JDK。
回答by Alex
Here's a simple response directly from Oracle http://docs.oracle.com/javase/7/docs/technotes/guides/
这是直接来自 Oracle http://docs.oracle.com/javase/7/docs/technotes/guides/的简单回复
Java SE Runtime Environment (JRE)
Java SE 运行时环境 (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.
JRE 提供了运行用 Java 编程语言编写的小程序和应用程序所需的库、Java 虚拟机和其他组件。此运行时环境可以与应用程序一起重新分发,使它们独立存在。
Java SE Development Kit (JDK)
Java SE 开发工具包 (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.
JDK 包括 JRE 和命令行开发工具,例如编译器和调试器,这些工具对于开发小程序和应用程序是必需的或有用的。
回答by Pruthvi Kumar
JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed.
JVM(Java Virtual Machine)是一个抽象的机器。它是一个规范,它提供了可以在其中执行 java 字节码的运行时环境。
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
JRE是Java Runtime Environment的首字母缩写,用于提供运行环境,是JVM的实现,物理存在,包含JVM在运行时使用的一组库+其他文件
JDK is an acronym for Java Development Kit.It physically exists.It contains JRE + development tools
JDK是Java Development Kit的首字母缩写,物理存在,包含JRE+开发工具
回答by nifCody
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
如果您想运行 Java 程序,但不想开发它们,请下载 Java 运行时环境或 JRE。如果要开发它们,请下载 Java 开发工具包或 JDK
JDK
JDK
Let's called JDK is a kit, which include what are those things need to developed and run java applications.
我们称之为 JDK 是一个工具包,其中包括开发和运行 Java 应用程序所需的那些东西。
JDK is given as development environment for building applications, component s and applets.
JDK 被用作构建应用程序、组件和小程序的开发环境。
JRE
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.
它包含以编译形式运行 Java 应用程序所需的一切。您不需要任何库和其他东西。您需要的所有内容都已编译。
JRE is can not used for development, only used for run the applications.
JRE 不能用于开发,只能用于运行应用程序。
回答by Jaimin Patel
In layman terms: JDK is grandfather JRE is father and JVM is their son. [i.e. JDK > JRE > JVM ]
通俗地说:JDK 是祖父,JRE 是父亲,JVM 是他们的儿子。 [即 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.
JDK = JRE + 开发/调试工具
JRE = JVM + Java 包类(如 util、math、lang、awt、swing 等)+运行时库。
JVM = 类加载器系统 + 运行时数据区 + 执行引擎。
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.
换句话说,如果您是 Java 程序员,那么您的系统中将需要 JDK,并且该软件包还将包含 JRE 和 JVM,但是如果您是喜欢玩网络游戏的普通用户,那么您将只需要 JRE,而该软件包将没有JDK在里面。
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.
在Java虚拟机(JVM)是运行Java字节码的虚拟机。JVM 不理解 Java 源代码,这就是您编译 *.java 文件以获取包含 JVM 可理解的字节码的 *.class 文件的原因。它也是让 Java 成为“可移植语言”(一次编写,随处运行)的实体。实际上,对于不同的系统(Windows、Linux、MacOS,请参阅维基百科列表)有 JVM 的特定实现,目的是使用相同的字节码,它们都给出相同的结果。
JDK and JRE
JDK 和 JRE
To explain the difference between JDK and JRE, the best is to read the Oracle documentation and consult the diagram :
要解释JDK和JRE之间的区别,最好阅读Oracle文档并参考图表:
Java Runtime Environment (JRE)
Java 运行时环境 (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运行时环境(JRE)提供的库,Java虚拟机和其他组件运行用Java编程语言applet和应用程序。此外,JRE 还包含两项关键部署技术: Java 插件,它使小应用程序能够在流行的浏览器中运行;和 Java Web Start,它通过网络部署独立的应用程序。它也是 Java 2 Platform, Enterprise Edition (J2EE) 中用于企业软件开发和部署的技术的基础。JRE 不包含用于开发小程序和应用程序的工具和实用程序,例如编译器或调试器。
Java Development Kit (JDK)
Java 开发工具包 (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.
JDK 是 JRE 的超集,包含 JRE 中的所有内容,以及开发小程序和应用程序所需的编译器和调试器等工具。
Note that Oracle is not the only one to provide JDK.
请注意,Oracle 并不是唯一提供 JDK 的公司。