What is the difference between JDK and JRE?

2018-12-31 07:13发布

What is the difference between JDK and JRE?
What are their roles and when should I use one or the other?

标签: java
20条回答
孤独寂梦人
2楼-- · 2018-12-31 07:21

The answer above (by Pablo) is very right. This is just additional information.

The JRE is, as the name implies, an environment. It's basically a bunch of directories with Java-related files, to wit:

  • 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.

The JDK is also a set of directories. It is a superset of the JRE, with some additions:

  • bin/ has been enlarged with development tools. The most important of them is javac; others include jar, javadoc and jshell.
  • jmods/, which holds JMOD files for the standard library, has been added. These files allow the standard library to be used with jlink.
查看更多
有味是清欢
3楼-- · 2018-12-31 07:26

jdk is necessary to compile to code and convert java code to byte codes while jre is necessary for executing the byte codes.

查看更多
梦该遗忘
4楼-- · 2018-12-31 07:27

The JRE is the Java Runtime Environment. It is a package of everything necessary to run a compiled Java program, including the Java Virtual Machine (JVM), the Java Class Library, the java command, and other infrastructure. However, it cannot be used to create new programs.

The JDK is the Java Development Kit, the full-featured SDK for Java. It has everything the JRE has, but also the compiler (javac) and tools (like javadoc and jdb). It is capable of creating and compiling programs.

Usually, if you only care about running Java programs on computer you will only install the JRE. It's all you need. On the other hand, if you are planning to do some Java programming, you need to install the JDK instead.

Sometimes, even if you are not planning to do any Java development on a computer, you still need the JDK installed. For example, if you are deploying a web application with JSP, you are technically just running Java programs inside the application server. Why would you need the JDK then? Because the application server will convert JSP into Java servlets and needs to use the JDK to compile the servlets. I am sure there are be more examples.

查看更多
冷夜・残月
5楼-- · 2018-12-31 07:36

JVM, JRE and JDK are platform dependent because configuration of each OS differs. But, Java is platform independent.

Java Virtual Machine (JVM) is a run-time system that executes Java bytecode.

JRE is the environment (standard libraries and JVM) required to run Java applications.

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.

查看更多
萌妹纸的霸气范
6楼-- · 2018-12-31 07:36

If you are a Java programmer you will need JDK in your system and this package will include JRE and JVM as well but if you are normal user who like to play online games then you will only need JRE and this package will not have JDK in it.

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.

(Sources: GeeksForGeeks Q&A, Java Platform Overview)

查看更多
无与为乐者.
7楼-- · 2018-12-31 07:36

The difference between JDK and JRE is that JDK is the software development kit for java while JRE is the place where you run your programs.

查看更多
登录 后发表回答