编者注:这个问题是在2009年提出的,世界在哪里不同。到2022年,标准的开源OpenJDK将只支持jdk。
JDK和JRE有什么区别?
它们的角色是什么,什么时候应该使用其中一个或另一个?
编者注:这个问题是在2009年提出的,世界在哪里不同。到2022年,标准的开源OpenJDK将只支持jdk。
JDK和JRE有什么区别?
它们的角色是什么,什么时候应该使用其中一个或另一个?
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一起使用。
从官方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小程序和应用程序所需的附加文件。
从调试的角度来看,有一个不同之处:
要调试到Java系统类,如String和ArrayList,你需要一个特殊版本的JRE,它是用“调试信息”编译的。JDK中包含的JRE提供了这些信息,但常规的JRE没有。常规JRE不包含此信息,以确保更好的性能。
什么是调试信息?以下是这篇博文的简要解释:
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.
JDK是JRE的超集,包含JRE中的所有内容,以及开发小程序和应用程序所需的编译器和调试器等工具。JRE提供库、Java虚拟机(JVM)和其他组件来运行用Java编程语言编写的小程序和应用程序。
JRE
JRE是Java运行时环境的首字母缩写。它用于提供运行时环境。它是JVM的实现。它是物理存在的。它包含一组库+ JVM在运行时使用的其他文件。
JDK
JDK是Java Development Kit的首字母缩写。它是物理存在的。它包含JRE +开发工具。
链接:- http://www.javatpoint.com/difference-between-jdk-jre-and-jvm
通常,当您只关心在浏览器或计算机上运行Java程序时,您只会安装JRE。这就是你所需要的。另一方面,如果您计划进行一些Java编程,则还需要JDK。
下面是甲骨文的一个简单回应 http://docs.oracle.com/javase/7/docs/technotes/guides/
Java SE运行环境(JRE)
JRE提供了运行用Java编程语言编写的applet和应用程序所需的库、Java虚拟机和其他组件。这个运行时环境可以与应用程序一起重新分发,使它们独立。
Java SE开发套件(JDK)
JDK包括JRE和命令行开发工具,如编译器和调试器,这对于开发applet和应用程序是必要的或有用的。
JVM (Java虚拟机)是一种抽象机器。它是一个提供运行时环境的规范,在该环境中可以执行java字节码。
JRE是Java运行时环境的首字母缩写。它用于提供运行时环境。它是JVM的实现。它是物理存在的。它包含一组库+ JVM在运行时使用的其他文件
JDK是Java Development Kit的首字母缩写。它是物理存在的。它包含JRE +开发工具
如果您想运行Java程序,但不想开发它们,请下载Java运行时环境(JRE)。如果您想开发它们,请下载Java开发工具包或JDK
JDK
JDK是一个工具包,包括开发和运行java应用程序所需的东西。
JDK是用于构建应用程序、组件和小程序的开发环境。
JRE
它包含以编译形式运行Java应用程序所需的所有内容。你不需要任何库和其他东西。你需要的所有东西都编译好了。
JRE不能用于开发,只能用于运行应用程序。
通俗地说: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文档)
假设,如果你是一个开发人员,那么你的角色是开发程序以及执行程序。所以你必须有开发和执行的环境,这是由JDK提供的。
假设,如果你是一个客户,那么你不必担心开发。您只需要一个运行程序并只获得结果的环境,这是由JRE提供的。
JRE执行应用程序,但JVM逐行读取指令,因此它是解释器。
JDK = JRE +开发工具
JRE = JVM +库类
清楚地理解这些术语(JVM、JDK、JRE)对于掌握它们的用法和区别至关重要。
JVM Java虚拟机(JVM)是执行Java字节码的运行时系统。JVM就像一台虚拟计算机,可以执行一组编译好的指令并操作内存位置。当Java编译器编译源代码时,它会在.class文件中生成一组高度优化的指令,称为字节码。JVM解释这些字节码指令,并将它们转换为特定于机器的代码以供执行。
JDK Java开发工具包(JDK)是一个软件开发环境,您可以使用它来开发和执行Java应用程序。它包括JRE和一组编程工具,如Java编译器、解释器、appltviewer和文档查看器。JDK通过Java SE、Java EE或Java ME平台实现。
JRE Java运行时环境(JRE)是JDK的一部分,它包括JVM、核心类和几个支持应用程序开发的库。尽管JRE可以作为JDK的一部分提供,但您也可以单独下载并使用它。
要完全了解,你可以看看我的博客:Jdk Jre Jvm和差异
如果你是一个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平台概述)
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和命令行开发工具,如编译器和调试器,这对于开发applet和应用程序是必要的或有用的。
JRE基本上是运行Java程序的Java虚拟机。它还包括用于Applet执行的浏览器插件。
JDK是一个抽象机器。它是一个提供运行时环境的规范,在该环境中可以执行java字节码。
所以,基本上JVM < JRE < JDK就像@Jaimin Patel说的那样。
JVM、JRE和JDK依赖于平台,因为每个操作系统的配置不同。但是,Java是平台独立的。
Java虚拟机(JVM)是执行Java字节码的运行时系统。
JRE是运行Java应用程序所需的环境(标准库和JVM)。
JDK包括JRE和命令行开发工具,如编译器和调试器,这对于开发applet和应用程序是必要的或有用的。
JRE
JRE是Java运行时环境的首字母缩写。它用于提供运行时环境。它是JVM的实现。它是物理存在的。它包含一组库+ JVM在运行时使用的其他文件。
除了Sun Micro Systems之外,其他公司也积极发布jvm的实现。
JDK
JDK是Java Development Kit的首字母缩写。它是物理存在的。它包含JRE +开发工具。