JVM, JDK, JRE和OpenJDK之间的区别是什么?

我在用Java编程时遇到了这些短语,它们之间有什么区别?


当前回答

JVM

The Java Virtual Machine (JVM) is the virtual machine that runs the Java bytecodes. The JVM doesn't understand Java source code; that's why you need compile your *.java files to obtain *.class files that contain the bytecodes understood 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和JRE

要解释JDK和JRE之间的区别,最好是阅读Oracle文档并参考图:

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.

注意,Oracle并不是唯一提供jdk的公司。

OpenJDK

OpenJDK是JDK的开源实现,也是Oracle JDK的基础。Oracle JDK和OpenJDK之间几乎没有区别。

区别在这个博客中说明:

Q: What is the difference between the source code found in the OpenJDK repository, and the code you use to build the Oracle JDK? A: It is very close - our build process for Oracle JDK releases builds on OpenJDK 7 by adding just a couple of pieces, like the deployment code, which includes Oracle's implementation of the Java Plugin and Java WebStart, as well as some closed source third party components like a graphics rasterizer, some open source third party components, like Rhino, and a few bits and pieces here and there, like additional documentation or third party fonts. Moving forward, our intent is to open source all pieces of the Oracle JDK except those that we consider commercial features such as JRockit Mission Control (not yet available in Oracle JDK), and replace encumbered third party components with open source alternatives to achieve closer parity between the code bases.

JDK 11的更新

Donald Smith的一篇文章试图消除Oracle JDK和Oracle的OpenJDK之间的差异:https://blogs.oracle.com/java-platform-group/oracle-jdk-releases-for-java-11-and-later

正如@Alan Evangelista在评论中提到的,Java Web Start已被Oracle在Java SE 9中弃用,并在Java SE 11中删除。

其他回答

JVM Java虚拟机,实际执行Java字节码。 它是JAVA平台上的执行块。它将字节码转换为机器代码。

JRE Java运行时环境,提供了执行Java应用程序的最低要求;它由Java虚拟机(JVM)、核心类和支持文件组成。

JDK Java开发工具包,它拥有开发应用程序软件的所有工具。它是JRE+JVM

Open JDK是Java平台的免费开源实现。

总而言之:

JRE = JVM + Java包(如util, math, lang, awt, swing等)+ 运行时库 JDK = JRE +开发/调试工具

如果你想用java开发,你需要JDK,但如果你只想运行java,你需要JRE。

另一个值得一提的方面是:

JDK (java开发工具包)

正如名称所示,您将需要它用于开发目的。

例如:一家软件公司会在他们的计算机中安装JDK,因为他们需要开发新的软件,其中包括编译和运行他们的Java程序。

因此我们可以说JDK = JRE + JVM。

JRE (java运行时环境)

运行Java程序需要它。你不能用它来编译Java程序。

例如:一个普通的计算机用户想要运行一些在线游戏,那么他的系统中就需要JRE来运行Java程序。

java虚拟机

你可能知道它运行字节码。它使Java平台独立,因为它执行你编译Java程序后得到的.class文件,而不管你是在Windows、Mac还是Linux上编译。

开放的JDK

就像我上面说的。现在JDK是由不同的公司制作的,其中一个是开源的,免费供公众使用的是OpenJDK,而其他一些是Oracle公司的jrocit JDK或IBM JDK。

然而,对于普通用户来说,它们可能都是一样的。

结论

如果你是一个Java程序员,你的系统中需要JDK,这个包将包括JRE和JVM,但如果你是一个喜欢玩在线游戏的普通用户,那么你只需要JRE,这个包中没有JDK。

换句话说,JDK是祖父,JRE是父亲,JVM是他们的儿子。

Java是一种语言,它包含严格的强类型语法。

Java 2平台标准版,也称为J2SE,指的是平台,并包括Java中的类。Lang和java。IO包,等等。它是构建Java应用程序的基础。

Java虚拟机(JVM)是运行已编译Java代码的软件虚拟机。因为编译后的Java代码只是字节码,JVM负责在运行字节码之前将其编译为机器码。(这通常被称为即时编译器或JIT编译器。)JVM还负责内存管理,这样应用程序代码就不必这么做了。

Java开发工具包,或称JDK,过去是,现在仍然是Java开发人员用来创建Java应用程序的软件。它包含一个Java语言编译器、一个文档生成器、用于处理本机代码的工具,以及(通常)用于平台的Java源代码,以启用调试平台类。

Java运行时环境(JRE)过去是,现在仍然是最终用户下载来运行已编译的Java应用程序的软件。它包含一个JVM,但不包含JDK中绑定的任何开发工具。但是,JDK确实包含JRE。

Java虚拟机(JVM)是可以执行Java字节码的虚拟机。它是Java软件平台的代码执行组件。

Java开发工具包(JDK)是Oracle公司针对Java开发人员的产品。自Java引入以来,它一直是迄今为止使用最广泛的Java软件开发工具包(SDK)。

Java运行时环境,也被称为Java运行时、运行时环境

OpenJDK (Open Java Development Kit)是Java编程语言的免费开源实现。这是太阳微系统公司在2006年开始努力的结果。该实现是根据GNU通用公共许可证(GPL)许可的,有一个链接例外。