Thursday, July 29, 2021

Difference between JVM, JIR, JRE, and JDK in Java? [Answered]

JRE, JVM, and JDK are three terms you often heard in conjunction with Java programming language, and most people either confuse them or think they all are the same. In this Java article, you will learn what is Java Run-time (JRE), what is Java Virtual Machine (JVM) and what is Java Development Kit (JDK) along with the Just in Time compiler or JIT. Once you know what JRE, JVM or JDK means you can differentiate them easily by yourself.  This article is in continuation of the Essential JVM options which every Java programmer should know. If you haven't read those articles, you can also read them as well. 

JRE, JVM, JIR, and JDK in Java Programming language

Now, let's understand all JRE (Java Runtime Environment), JVM (Java Virtual Machine), and JDK (Java Development Kit) in detail to learn the differences between them. 

1. Java Runtime Environment (JRE)

Difference between JVM JRE and JDK in Java Programming languageJava is everywhere in the browser, in mobile, in TV, or in set-top boxes, and if you are into Java programming language than you know that Java code which is bundled in JAR (Java archive) file requires Java virtual machine JVM to execute it. 

Now JVM is an executable or program like any other program and you can install that into your machine. You have seen browsers often suggesting download JRE run a Java Applet downloaded from the Internet. 

Various versions of JRE is available in java.oracle.com and most of the user who just wants to execute Java program inside a browser or standalone downloads JRE. All browsers including Internet Explorer, Firefox, and Chrome can work with JRE.



2. Java Virtual Machine (JVM)

When you download JRE and install on your machine you got all the code required to create JVM. Java Virtual Machine is get created when you run a java program using java commands like java HelloWorld. 

JVM is responsible for converting byte code into machine-specific code and that's why you have different JVM for Windows, Linux, or Solaris but one JAR can run on all this operating system. 

Java Virtual machine is at the heart of Java programming language and provides several features to Java programmers including Memory Management and Garbage Collection, Security, and other system-level services.


Java Virtual Machine can be customized like we can specify starting memory or maximum memory of heap size located inside JVM at the time of JVM creation. 

If we supplied an invalid argument to java command it may refuse to create Java Virtual Machine by saying "failed to create Java virtual machine: invalid argument". 

In short Java Virtual Machine or JVM is the one that provides Platform independence to Java.

And, if you are serious about improving your advanced JVM skill and learn things like taking and analyzing heap dumps then highly recommend checking these JVM internal courses on Medium. 





3. Java Development Kit (JDK)

JDK is also loosely referred to as JRE but its lot more than JRE and it provides all the tools and executable require to compile debug and execute Java Program. Just like JRE, JDK is also platform-specific and you need to use separate installers for installing JDK on Linux and Windows

The current version of JDK is 1.7 which is also referred to as Java7 and it contains javac (java compiler) based on programming rules of Java7 and Java which can execute java7 code with new features like String in Switch, fork-join framework or Automatic Resource Management

When you install JDK, the installation folder is often referred to as JAVA_HOME. All binaries are located inside JAVA_HOME/bin which includes javac, java, and other binaries and they must be in your system PATH in order to compile and execute Java programs. For details on Path see how to set PATH for Java in Windows and UNIX.


4. Difference between JRE, JDK, and JVM

In short, there are few differences between JRE, JDK, and JVM:

1)  JRE and JDK come as installers while JVM is bundled with them.

2)  JRE only contains an environment to execute a java program but doesn’t contain other tools for compiling a java program.
3)  JVM comes along with both JDK and JRE and is created when you execute the Java program by giving the “java” command.


4. Just in Time Compiler (JIT)

Initially, Java has been accused of poor performance because it’s both compiles and interprets instruction. Since compilation or Java file to class file is independent of the execution of Java program do not confuse. 

Here compilation word is used for byte code to machine instruction translation. JIT is an advanced part of Java Virtual machine which optimizes byte code to machine instruction conversion part by compiling similar byte codes at the same time and thus reducing overall execution time. 

JIT is part of Java Virtual Machine and also performs several other optimizations such as in-lining function. You can also join these advanced Java courses on Udemy to learn more bout JIT and how JVM optimizes code for faster executions. 





That’s all on JRE, JDK, and Java Virtual machines and the difference between them. Though they look similar they are different and having a clear idea of JVM, JIT or JDK helps in java programming.


Other JVM Internal Articles you may like
  • Difference between Stack and Heap memory in Java? (answer)
  • 10 Essential JVM options for Production apps (article)
  • Top 5 Courses to learn JVM internals in-depth (courses)
  • Top 5 Books to learn about Java Memory Management and GC? (books)
  • How Garbage Collection works in Java? (article)
  • Difference between 32-bit and 64-bit JVM? (answer)
  • 10 pints about heap memory in Java? (article)
  • What does -XX:UseCompressedOOPS does in 64-bit JVM? (article)
  • How do you find CPU and Memory usage of Java applications? (article)
  • When a class is loaded or initialized in JVM? (article)
  • How Classloader works in Java? (article)
  • Top 5 Advanced Java Courses to learn Performance? (courses)

Thanks for reading this article so far. If you find this JRE, JVM, and JDK article useful then please share it with your friends and colleagues. If you have any questions or feedback then please drop a note. 

P. S. - If you are new to the Java world and looking for a free online training course to learn Java then you can also check out these free Java Programming courses on Udemy. It's completely free and you just need a Udemy account to join this online course.

16 comments :

JDK Guru said...

Another differnce over JDK vs JRE is that when you install JDK in your machine , JRE comes automatically and you can check this by going to your JAVA_HOME or Java installation directory. JRE should be in PATH JAVA_HOME/jre. Also all certificates used by Java are stored in keystore which exists inside JRE folder.

Anonymous said...

Can we run Java program without JRE? does JRE only contains java or javaw command or something else ?

Unknown said...

If JVM is platform independent then why JVM is different for Windows and Linux?

amit said...

I Couldn't understand the JIT part.

Anonymous said...

I came to know that jvm is not a program it is just doccumentation containing specifications on what should be the format of exe etc.jre is responsible for the execution of java program .

Anonymous said...

Amit
Every program need to satisfy the security policies after loading till execution. this affected the execution speed .jit is both compiler and interpreter used to compensate this loss.most of the compiler now are jit.

Unknown said...

which is platform independent JDK or JRE

Anonymous said...

JRE : jre contains the jvm and some other libraries and file which is helpful for jvm to execute the java program.

JDK : jdk contains JRE and Development tools like javac ,java etc

Shubham said...

To Nitin Jain. JVM is not platform independent, Java is platform independent. In-fact JVM creates a environment, so that Java could be platform independent. JVM is according to platforms like windows/linux/Mac. A .class file of a .java file could be executed on any JVM, and it gives same result on each platform (thus platform independence). actually the Machine code (of this .class file) which is generated by JVM is according platform.

Shubham said...

To Amit : In java, code is interpreted i.e. converted line by line. While in compilation whole code is converted in a go. But Java also support JIT compilation, in which a common chunk of code which is repetitively used, can be compiled once and placed at some place. Now rest of the Java code is interpreted, and when call comes to repetitive part, the compiled code is used (instead of interpreting the part again). You can relate it with a Loop, where code related to loop is compiled separately, and this compiled code is referred when call comes to loop, instead to interpreting the code related to loop n times.

Anonymous said...

To Amit: In short words, what is platform independant is the java bytecode
JVM need to be platform specific because it will translate this bytecode into machine code.
As Shubham said, for example if you write your program in Windows and you create your .class, then this .class file is platform independant, the hosting JVM (let´s give another example here, let´s say we have as destiny a client with a JVM in Linux and other client in Solaris, well you don´t need to recompile your code again and again, the given JVM will know what this .class bytecode means so then the given JVM will translate your code into the given machine code, that´s it

hopes this helps :)

Unknown said...

JVM isn't platform independent, instead JVM provides platform independent feature to Java code(byte code).
When byte code is generated after compiling your written code, it can be taken to any operating system for running it which is possible due to JVM (specific to OS) which converts the byte code into the machine language depending on the OS.

javin paul said...

@vaibhavi, well said, that's exactly why you have different JVM for 32-bit and 64-bit, windows, Linux, Mac OS X or Solaris.

Unknown said...

Becoz of byte code conversion java is platform independent in the sense it once the code us written it need to write again in a different pattern once its written it translates the code into understandable language through the byte code.It is common in very language

Unknown said...

Hi,
Thanks for Sharing the Article.
Could you explain the

Anonymous said...

Not clear at at all.

Post a Comment