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

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


当前回答

JVM: java的虚拟机。告诉机器用Java代码做什么。不能按原样下载JVM。它被打包在其他组件中。

JRE:上面提到的其他组件是JRE。 它是JVM+其他jar创建运行时环境

JDK:包含JRE(JRE又包含JVM)。获得JDK后,不需要分别安装JRE和JVM。它包含编译器,编译你的.java文件到.class文件

其他回答

JVM is abbreviated as Java Virtual Machine, JVM is the main component of java architecture. JVM is written in C programming language. Java compiler produce the byte code for JVM. JVM reading the byte code verifying the byte code and linking the code with the ibrary. JRE is abbreviated as Java Runtime Environment. it is provide environment at runtime. It is physically exist. It contain JVM + set of libraries(jar) +other files. JDK is abbreviated as Java Development Kit . it is develop java applications. And also Debugging and monitoring java applications . JDK contain JRE +development tools(javac,java)

OpenJDK是sun JDK的开源版本。Oracle JDK是Sun的官方JDK。

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中删除。

JDK (Java Development Kit):

包含开发Java程序所需的工具。 如果您想编写自己的程序并编译它们,则需要JDK。 JDK主要针对java开发。

JRE (Java Runtime Environment)

Java运行时环境包含JVM、类库和其他支持文件。 JRE的目标是执行Java文件。

JVM (Java虚拟机)

JVM根据底层操作系统和硬件组合将字节码解释为机器码。它负责所有的事情,比如垃圾收集、数组边界检查等等……Java虚拟机提供了一种平台独立的代码执行方式。

简单的图片来说明JDK、JRE、JDK。

JDK一般来说,它只会安装在开发环境中,比如在开发人员中,在公司的实时QA系统中。在服务器上运行的原始代码将没有JDK。

JRE是JDK的一部分,也可以独立安装在服务器上。在处理用户请求的实时服务器中,只安装JRE和开发人员开发的代码(*.class格式)

JVM Developer开发的代码>在开发机器上测试和执行。执行阶段需要Java的媒介。

.class文件不是本地代码(cpu能理解的代码)。如果.java文件直接转换为本机代码,则无法实现WORA(一次编写,随处运行)的概念。

本机代码因操作系统而异。所以,Java创建了一个叫做。class的中间文件和一个叫做“JVM”的神奇程序。将.class转换为本机代码是JVM的职责。

通俗来说:JDK = JRE +开发/调试工具,其中JDK是我们与Java一起工作的完整包,从创建编译到运行它。另一方面,JRE只是代码(字节码)的运行。

注意:-无论我们是安装JDK还是JRE, JVM都会与这两个包捆绑在一起,JVM是JIT编译器将字节代码转换为机器特定代码的部分。

只需阅读关于JDK、JRE、JVM和JIT的文章即可