Let say I am not a java developer and an ordinary person, and installing any application that is written in Java. So, do I need to first install the JRE or no all operating systems already have JRE installed on them?
Do all operating systems already have JRE installed for running java applications?
No.
First of all, Java is not necessarily available for all operating systems. (It is probably available for most operating systems that are targeted by your application ... but it might not be.)
Secondly, most operating system platforms don't have Java installed by default. Indeed many OS vendors don't support Java at all: Java is provided by a 3rd-party vendor.
So, do I need to first install the JRE or no all operating systems already have JRE installed on them?
Prior to Java 9, the answer is that you have to install a JRE or a JDK. This can be done by downloading and installing it directly, or installing it via a package management system on some OSes. It can also be done by embedding a JRE in your application's installer.
From Java 9 onwards, you can also use "jlink" to create an executable that contains a cut-down JRE which is tailored to run your application on a specific target platform. This is the approach recommended by Oracle for people who want to distribute "consumer grade" Java applications.
And from Java 11 onwards, for some Java vendors (Oracle for example), the JRE option is no longer available. For these vendors, if you want "full" Java to run your application, you / your users need to install a JDK.
The Java Runtime Environment has nothing to do with the OS. You could install any OS with or without the JRE. If you installed the OS yourself, I'd guess it doesn't have it. If you bought the computer with the OS on it, it depends who you bought it from.
Checking if you have JRE installed is pretty much the same on all OS. Open a Terminal (on windows run CMD) and type java --version.
If you don't have it, you need to install it. Just google install JRE on [insert your os here]
What is the difference between JVM, JDK, JRE & OpenJDK?
I was programming in Java and I encountered these phrases, what are the differences among 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 need 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
OpenJDK is an open-source implementation of the JDK and the base for the Oracle JDK. There is almost no difference between the Oracle JDK and the OpenJDK.
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.
Update for JDK 11
An article from Donald Smith try to disambiguate the difference between Oracle JDK and Oracle's OpenJDK : https://blogs.oracle.com/java-platform-group/oracle-jdk-releases-for-java-11-and-later
As mentioned in comments by #Alan Evangelista, Java Web Start has been deprecated by Oracle in Java SE 9 and removed in Java SE 11.
JVM is the Java Virtual Machine – it actually runs Java ByteCode.
JRE is the Java Runtime Environment – it contains a JVM, among other things, and is what you need to run a Java program.
JDK is the Java Development Kit – it is the JRE, but with javac (which is what you need to compile Java source code) and other programming tools added.
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
i.e. JRE = JVM + Java Packages Classes(like util, math, lang, awt,swing etc)+runtime libraries.
JDK is mainly targeted for java development. I.e. 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.
A Java virtual machine (JVM) is a virtual machine that can execute Java ByteCode. It is the code execution component of the Java software platform.
The Java Development Kit (JDK) is an Oracle Corporation product aimed at Java developers. Since the introduction of Java, it has been by far the most widely used Java Software Development Kit (SDK).
Java Runtime Environment, is also referred to as the Java Runtime, Runtime Environment
OpenJDK (Open Java Development Kit) is a free and open source implementation of the Java programming language. It is the result of an effort Sun Microsystems began in 2006. The implementation is licensed under the GNU General Public License (GPL) with a linking exception.
JVM is the virtual machine Java code executes on
JRE is the environment (standard libraries and JVM) required to run Java applications
JDK is the JRE with developer tools and documentations
OpenJDK is an open-source version of the JDK, unlike the common JDK owned by Oracle
JDK (Java Development Kit) :
contains tools needed to develop the Java programs.
You need JDK, if at all you want to write your own programs, and to compile them.
JDK is mainly targeted for java development.
JRE (Java Runtime Environment)
Java Runtime Environment contains JVM, class libraries, and other supporting files.
JRE is targeted for execution of Java files.
JVM (Java Virtual Machine)
The JVM 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… Java Virtual Machine provides a platform-independent way of executing code.
JDK - Compiles java to ByteCode. Consists of debuggers, Compilers etc.
javac file.java // Is executed using JDK
JVM - Executes the byte code. JVM is the one which makes java platform independent. But JVM varies for platforms.
JRE - JVM along with java runtime libraries to execute java programs.
JVM : A specification which describes the the way/resources to run a java program. Actually executes the byte code and make java platform independent. In doing so, it is different for different platform. JVM for windows cannot work as JVM for UNIX.
JRE : Implementation of JVM. (JVM + run time libraries)
JDK : JRE + java compiler and other essential tools to build a java program from scratch
Another aspect worth mentioning:
JDK (java development kit)
You will need it for development purposes like the name suggests.
For example: a software company will have JDK install in their computer because they will need to develop new software which involves compiling and running their Java programs as well.
So we can say that JDK = JRE + JVM.
JRE (java run-time environment)
It's needed to run Java programs. You can't compile Java programs with it .
For example: a regular computer user who wants to run some online games then will need JRE in his system to run Java programs.
JVM (java virtual machine)
As you might know it run the bytecodes. It make Java platform independent because it executes the .class file which you get after you compile the Java program regardless of whether you compile it on Windows, Mac or Linux.
Open JDK
Well, like I said above. Now JDK is made by different company, one of them which happens to be an open source and free for public use is OpenJDK, while some others are Oracle Corporation's JRockit JDK or IBM JDK.
However they all might appear the same to general user.
Conclusion
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.
In other words JDK is grandfather JRE is father and JVM is their son.
Developers develop using JDK, and first we write .java source code
Developers debug the code and compile the code into .class bytecode executable files in JRE
The executable files are executed by JVM, translating the bytecode into native machine code which machines can execute
Here is they relations:
Reference:
Java JDK, JRE and JVM
Java is the language and includes a strict and strongly typed syntax.
Java 2 Platform, Standard Edition, also known as J2SE, referred to the platform and included the classes in the java.lang and java.io packages, among others. It was the building block that Java applications were built upon.
A Java Virtual Machine, or JVM, is a software virtual machine that runs compiled Java code. Because compiled Java code is merely bytecode, the JVM is responsible for compiling that bytecode to machine code before running it. (This is often called the Just In Time Compiler or JIT Compiler.) The JVM also takes care of memory management so that application code doesn’t have to.
The Java Development Kit, or JDK, was and remains the piece of software Java developers use to create Java applications. It contains a Java language compiler, a documentation generator, tools for working with native code, and (typically) the Java source code for the platform to enable debugging platform classes.
The Java Runtime Environment, or JRE, was and remains the piece of software end users download to run compiled Java applications. It includes a JVM but does not contain any of the development tools bundled in the JDK. The JDK, however, does contain a JRE.
JVM : this actually means the byte code interpreter .It is platform dependent. For eg: in Windows platform the 'java.exe' or 'javaw.exe' precess is the jvm process.
JDK : is a toolkit containing necessary libraries and utilities to develop and execute java program/application
JRE: is the execution environment for a java application.ie, it only support runtime dependencies including jvm for compiled program. If we want to compile a java program we need jdk.
JVM : virtual machine of java. tells machine what to do with the Java Code. You cannot download JVM as is. It comes packaged in some other component.
JRE: Some other component referred as above is the JRE.
It is JVM+ other jars to create runtime environmeny
JDK: contains JRE(which in turn contains JVM). Once you get JDK you need not install JRE and JVM separately. It contains compiler which compiles your .java files to .class files
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.
JRE
JRE is an acronym for Java Runtime Environment.It is used to provide runtime environment.It is the implementation of JVM.It physically exists.It contains set of libraries + other files that JVM uses at runtime.
JDK
JDK is an acronym for Java Development Kit.It physically exists.It contains JRE + development tools.
Link :- http://www.javatpoint.com/difference-between-jdk-jre-and-jvm
In summary:
JRE = JVM + Java Packages (like util, math, lang, awt, swing etc) +
runtime libraries
JDK = JRE + Development/debugging tools
If you want to develop in java, you need the JDK, but if you just want run java, you need the JRE.
Simple image to illustrate JDK, JRE, JDK.
JDK In general this will be installed only in development setups like in developers, QA systems in real-time at corporate companies. Original code which is running in servers will not have JDK.
JRE is a part of JDK and independently too installable in servers. In real-time servers which serving user requests will have only JRE installed and code developed by developers (in *.class format)
JVM Developer developed code > tested and executed in development machines. Execution phase require a medium for Java.
.class files are not native code (code which understands by cpu). To achieve WORA (Write Once Run Anywhere) concept can't be achieved if .java file is directly converted to native code.
Native code differs from OS to OS. So, Java created a intermediate file called .class and magical program called "JVM". Its JVM's duty to convert .class into native code.
JVM Java Virtual Machine , actually executes the java bytecode.
It is the execution block on the JAVA platform. It converts the bytecode to the machine code.
JRE Java Runtime Environment , provides the minimum requirements for executing a Java application; it consists of the Java Virtual Machine (JVM), core classes, and supporting files.
JDK Java Development Kit, it has all the tools to develop your application software. It is as JRE+JVM
Open JDK is a free and open source implementation of the Java Platform.
In layman terms:- JDK = JRE + Development/debugging tools, where JDK is our complete package to work with Java, from creating compiling till running it.On the other hand JRE is just of running of code(Byte Code).
Note:- Whether we are installing JDK or JRE, JVM would come bundled with both the packages and JVM is the part where JIT compiler converts the byte code into the machine specific code.
Just read the article on JDK,JRE ,JVM and JIT
JDK: The complete package which you need to write and run java code
OpenJDK: An independent implementation of JDK for making it much better
JVM: Converts Java code into bytecode and provides the specifications which tells how should a Java code be compiled, loaded, verified, checked for errors and executed.
JRE: Implementation of the JVM with which some Java libraries are used to Run the program
JRE executes the application but JVM reads the instructions line by line so it's interpreter.
JDK=JRE+Development Tools
JRE=JVM+Library Classes
JVM is abbreviated as Java Virtual Machine, JVM is the main component of java architecture. JVM is written in C programming language. Java compiler produce the byte code for JVM. JVM reading the byte code verifying the byte code and linking the code with the ibrary.
JRE is abbreviated as Java Runtime Environment. it is provide environment at runtime. It is physically exist. It contain JVM + set of libraries(jar) +other files.
JDK is abbreviated as Java Development Kit . it is develop java applications. And also Debugging and monitoring java applications . JDK contain JRE +development tools(javac,java)
OpenJDK OpenJDK is an open source version of sun JDK. Oracle JDK is Sun's official JDK.
JDK - Tools like javac used to compile *.java files to *.class bytecode files (basically develop Java programs)
JRE - Tools to run *.jar files (basically run Java programs)
JVM - Tools to compile *.class files to executable machine code (run all Java bytecode)
OpenJDK is just a distribution of the Java JDK.
What's the difference between the JRE included with the JDK (located inside of the jre folder) and the standalone JRE? Is there any?
The "standalone JRE" (sometimes also referred to as the "Public JRE") generally does not contain the server version of HotSpot. It also lacks the tools included with the JDK (JavaDB, javac, tools.jar, etc).
Otherwise, the runtimes are identical. Also, note that a JDK may install one (or more) JREs.
Finally, all of the above notes are in regards to Sun's Java installers for Windows. Other vendors and platforms may (and sometimes do) vary.
There is no difference (unless you have a different version of the JRE). Here is the official definition from SUN/Oracle:
http://java.sun.com/javase/6/docs/technotes/guides/index.html
JRE and JDK Sun Microsystems provides
two principal software products in the
JavaTM Platform, Standard Edition
(JavaTM SE) family:
Java SE Runtime Environment (JRE)
The JRE provides the libraries, Java
virtual machine, and other components
necessary for you to run applets and
applications written in the Java
programming language. This runtime
environment can be redistributed with
applications to make them
free-standing.
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.
If you run a binary compare against the standalone JRE and the JRE included in the JDK they are binary different (at least in Windows version).
The class count in rt.jar is equal but out of curiosity, I ran 'javap' on all classes in both and compared results.
The only difference I see is that the JDK verison has lines like 'Compiled from "Serializable.java' before the class code.
I don't think this should have any impact on end user, so these JREs should be in fact behaving the same way.
The difference is legal. JDK is for development, JRE is for execution. You can include JRE with a product
The "JDK" is the Java Development Kit. The JDK is bundle of software that you can use to develop Java based software. The "JRE" is the Java Runtime Environment. The JRE is an implementation of the Java Virtual Machine which actually executes Java programs.
Typically, each JDK contains one (or more) JRE's along with the various development tools like the Java source compilers, bundling and deployment tools, debuggers, development libraries, etc.
Could anyone please tell how jre directory help in the running java programs? I'm calling java interpretor by using java command, and that is in JDK directory, then how could jre directory help in running java programs and jdk for compiling?
When you install the JDK (development kit, compiler and so on), you get the JRE (runtime environment) as part of that (under my install, there's actually a jre subdirectory in the jdk folder) - this is because you will probably want to run code that you develop if only to test it a little bit before inflicting it on the rest of the planet :-).
But it's by no means necessary to install the JDK to run Java programs. All you need is the JRE and that is, by far, the normal situation for most people out there.
The JRE is just the interpreter (java.exe or whatever) - it's a smaller install that is typically used by people who just need to run Java applications and aren't Java developers. The JRE handles the conversion and execution of java bytecode for the target platform.
The JDK is meant for developers. Along with the runtime it provides the compiler and all the Java libraries that are used to build Java programs. The compiler is responsible for converting Java source code to bytecode.
So - when you are delivering your Java application to customers, all they need to install is the JRE.
The Java Runtime Environment (JRE) interprets byte code to platform specific machine code. JRE is minimal set of programmes which executes the java class files.
The JDK (Java Developmental Toolkit) comes along with java libraries and JRE embedded in it. Apart from these it comes along with the utility tools for byte code compilation "javac".