What is the difference between JVM, JDK, JRE & OpenJDK?

What is the difference between JVM , JDK , JRE & OpenJDK ?

I was programming in Java and I encountered these phrases, what are the differences between them?


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 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 and JRE

To explain the difference between JDK and JRE, the best is to read the Oracle documentation and consult the diagram:

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.

Note that Oracle is not the only one to provide JDKs.

OpenJDK

The OpenJDK is the open-source implementation of the Java SE 7 JSR (JSR 336). Now there is almost no difference between the Oracle JDK and the OpenJDK. Last year, Oracle took this decision : Moving to OpenJDK as the official Java SE 7 Reference Implementation

The differences are stated in this blog :

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.

Depending on the used version, the VM can differ: Correspondence between Sun/Oracle JDK, OpenJDK and HotSpot VM versions


  • JVM is Java Virtual Machine -- the JVM actually runs Java bytecode.
  • JDK is Java Developer Kit -- the JDK is what you need to compile Java source code.
  • JRE is Java Runtime Environment -- is what you need to run a Java program and contains a JVM, among other things.
  • OpenJDK is a specific JDK implementation.


    JDK (Java Development Kit)

    Java Developer Kit contains tools needed to develop the Java programs, and JRE to run the programs. The tools include compiler (javac.exe), Java application launcher (java.exe), Appletviewer, etc…

    Compiler converts java code into byte code. Java application launcher opens a JRE, loads the class, and invokes its main method.

    You need JDK, if at all you want to write your own programs, and to compile them. For running java programs, JRE is sufficient.

    JRE is targeted for execution of Java files

    ie JRE = JVM + Java Packages Classes(like util, math, lang, awt,swing etc)+runtime libraries.

    JDK is mainly targeted for java development. Ie You can create a Java file (with the help of Java packages), compile a Java file and run a java file.

    JRE (Java Runtime Environment)

    Java Runtime Environment contains JVM, class libraries, and other supporting files. It does not contain any development tools such as compiler, debugger, etc. Actually JVM runs the program, and it uses the class libraries, and other supporting files provided in JRE. If you want to run any java program, you need to have JRE installed in the system

    The Java Virtual Machine provides a platform-independent way of executing code; That mean compile once in any machine and run it any where(any machine).

    JVM (Java Virtual Machine)

    As we all aware when we compile a Java file, output is not an 'exe' but it's a '.class' file. '.class' file consists of Java byte codes which are understandable by JVM. Java Virtual Machine interprets the byte code into the machine code depending upon the underlying operating system and hardware combination. It is responsible for all the things like garbage collection, array bounds checking, etc… JVM is platform dependent.

    The JVM is called “virtual” because it provides a machine interface that does not depend on the underlying operating system and machine hardware architecture. This independence from hardware and operating system is a cornerstone of the write-once run-anywhere value of Java programs.

    There are different JVM implementations are there. These may differ in things like performance, reliability, speed, etc. These implementations will differ in those areas where Java specification doesn't mention how to implement the features, like how the garbage collection process works is JVM dependent, Java spec doesn't define any specific way to do this.

    链接地址: http://www.djcxy.com/p/72352.html

    上一篇: Oracle JDK和OpenJDK之间的差异

    下一篇: JVM,JDK,JRE和OpenJDK有什么区别?