编者注:这个问题是在2009年提出的,世界在哪里不同。到2022年,标准的开源OpenJDK将只支持jdk。
JDK和JRE有什么区别?
它们的角色是什么,什么时候应该使用其中一个或另一个?
编者注:这个问题是在2009年提出的,世界在哪里不同。到2022年,标准的开源OpenJDK将只支持jdk。
JDK和JRE有什么区别?
它们的角色是什么,什么时候应该使用其中一个或另一个?
当前回答
如果你是一个Java程序员,你的系统中需要JDK,这个包将包括JRE和JVM,但如果你是一个喜欢玩在线游戏的普通用户,那么你只需要JRE,这个包中没有JDK。
JVM JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed. JVMs are available for many hardware and software platforms. JVM, JRE and JDK are platform dependent because configuration of each OS differs. But, Java is platform independent. 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. JRE is can not used for development, only used for run the applications. Java SE Development Kit (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.
(来源:GeeksForGeeks Q&A, Java平台概述)
其他回答
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。我相信还有更多的例子。
假设,如果你是一个开发人员,那么你的角色是开发程序以及执行程序。所以你必须有开发和执行的环境,这是由JDK提供的。
假设,如果你是一个客户,那么你不必担心开发。您只需要一个运行程序并只获得结果的环境,这是由JRE提供的。
JRE执行应用程序,但JVM逐行读取指令,因此它是解释器。
JDK = JRE +开发工具
JRE = JVM +库类
JDK包括JRE和命令行开发工具,如编译器和调试器,这对于开发applet和应用程序是必要的或有用的。
JRE基本上是运行Java程序的Java虚拟机。它还包括用于Applet执行的浏览器插件。
JDK是一个抽象机器。它是一个提供运行时环境的规范,在该环境中可以执行java字节码。
所以,基本上JVM < JRE < JDK就像@Jaimin Patel说的那样。
通俗地说:JDK是祖父,JRE是父亲,JVM是他们的儿子。 [即JDK > JRE > JVM]
JDK = JRE +开发/调试工具 JRE = JVM + Java包类(如util, math, lang, awt,swing等)+运行时库。 JVM =类装入器系统+运行时数据区+执行引擎。
换句话说,如果你是一个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.
JDK和JRE
要解释JDK和JRE之间的区别,最好是阅读Oracle文档并参考图:
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开发工具包(JDK)
JDK是JRE的超集,包含JRE中的所有内容,以及开发小程序和应用程序所需的编译器和调试器等工具。
注意,Oracle并不是唯一提供JDK的公司。
JIT编译过程(来源:Oracle文档)
JVM (Java虚拟机)是一种抽象机器。它是一个提供运行时环境的规范,在该环境中可以执行java字节码。
JRE是Java运行时环境的首字母缩写。它用于提供运行时环境。它是JVM的实现。它是物理存在的。它包含一组库+ JVM在运行时使用的其他文件
JDK是Java Development Kit的首字母缩写。它是物理存在的。它包含JRE +开发工具