编者注:这个问题是在2009年提出的,世界在哪里不同。到2022年,标准的开源OpenJDK将只支持jdk。
JDK和JRE有什么区别?
它们的角色是什么,什么时候应该使用其中一个或另一个?
编者注:这个问题是在2009年提出的,世界在哪里不同。到2022年,标准的开源OpenJDK将只支持jdk。
JDK和JRE有什么区别?
它们的角色是什么,什么时候应该使用其中一个或另一个?
当前回答
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的。
其他回答
上面的答案(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一起使用。
JDK是JRE的超集,包含JRE中的所有内容,以及开发小程序和应用程序所需的编译器和调试器等工具。JRE提供库、Java虚拟机(JVM)和其他组件来运行用Java编程语言编写的小程序和应用程序。
简单:
JVM是执行Java代码的虚拟机
JRE是运行Java应用程序所需的环境(标准库和JVM)
JDK是带有开发人员工具和文档的JRE
从调试的角度来看,有一个不同之处:
要调试到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.
下面是甲骨文的一个简单回应 http://docs.oracle.com/javase/7/docs/technotes/guides/
Java SE运行环境(JRE)
JRE提供了运行用Java编程语言编写的applet和应用程序所需的库、Java虚拟机和其他组件。这个运行时环境可以与应用程序一起重新分发,使它们独立。
Java SE开发套件(JDK)
JDK包括JRE和命令行开发工具,如编译器和调试器,这对于开发applet和应用程序是必要的或有用的。