JDK (Java Development Kit), JRE (Java Runtime environment), JVM (java virtual machine), Differences between JDK, JRE and JVM, OpenJDK, JIT Compiler (Just In Time Compiler) internal working



Contents of page :
  • 1) JDK (Java Development Kit)
    • In short  JDK = JRE + JVM.
    • JDK diagram >


  • 2) JRE (Java Runtime environment)
In short  JRE = JVM + class libraries (rt.jar)  + other libraries (if any).
JRE diagram >



How is java platform independent language?
Diagram to show java is platform independent>


  • Differences between JDK, JRE and JVM  


  • 4) OpenJDK


  • 5) JIT Compiler (Just In Time Compiler)
    • JIT Compiler internal working >
    • How JIT improves performance of Most frequently used methods ?
    • Disabling JIT compiler >


  • 6) More about JDK >
  • Java Compiler (javac)
    • There are 2 ways of using javac command >
      • For compiling one file
      • For compiling more than one files.
  • Java Disassembler
  • Java Documentation
  • Java Debugger

1) JDK (Java Development Kit)
As the name suggests, JDK is required for java development.
You need to have JDK in your system for >
  • developing,
  • compiling and
  • running Java programs.
In short  JDK = JRE + JVM.


JDK diagram >


2) JRE (Java Runtime environment)
JRE provides environment for running/executing programs.
You need to have JRE in your system for >
  • running Java programs.
JRE contains-
  • JVM,
  • class libraries (rt.jar)  and
  • other supporting libraries (external jars, Ex - ojdbc.jar for JDBC) for executing java program.
In short  JRE = JVM + class libraries (rt.jar)  + other libraries (if any).
JRE diagram >


JVM is the virtual machine on which java code executes.
JVM is responsible for converting byte code into machine specific code.


How is java platform independent language?
Once source code (i.e. .java file) is compiled on one platform(bytecode is formed). That bytecode can be executed (interpreted) on any other platform running a JVM.
Every platform have different JVM implementation. From here you can download JVM for different platforms.
Example -
JVM for windows platform is different from JVM for linux platform.


Diagram to show java is platform independent>



Differences between JDK, JRE and JVM  
JDK
JRE
JVM
Java Development Kit
Java Runtime environment
java virtual machine
JDK is required for java development.

JRE provides environment for running/executing programs.

JVM is the virtual machine on which java code executes.

JVM is responsible for converting byte code into machine specific code.
You need to have JDK in your system for >
  • developing,
  • compiling and
  • running Java programs.

JDK contains-
  • JRE and
  • JVM
You need to have JRE in your system for >
  • running Java programs.


JRE contains-
  • JVM,
  • class libraries and
  • other supporting libraries.
-
In short  JDK = JRE + JVM
In short  JRE = JVM + class libraries (rt.jar)  + other libraries (if any).




4) OpenJDK

  • The OpenJDK is the open-source implementation of the Java SE 7.
  • There is hardly any difference between the Oracle JDK and the OpenJDK.
  • Oracle in 2011 moved to OpenJDK as the official Java SE 7 Implementation.


  • Difference between the source code of OpenJDK & OracleJDK?
As compared to OpenJDK code  OracleJDK code consists of additional information like
deployment code (implementation of Oracle's Java Plugin and Java WebStart),
third party components like graphics rasterizer,
some open source third party components like Rhino.


However OpenJDK & OracleJDK might appear same to general user.



5) JIT Compiler (Just In Time Compiler)

JIT compiler is a part of the JVM.
JIT compiles bytecodes to machine code at run time and improves the performance of Java applications.
JIT Compiler internal working >
JIT compilation does require processor time and memory usage. When the JVM first starts up, lots of methods are called. Compiling all of these methods might can affect startup time significantly, though program ultimately may achieve good performance.
Methods are not compiled when they are called first time. For each and every method JVM maintains a call count, which is incremented every time the method is called. The methods are interpreted by JVM until call count not exceeds JIT compilation threshold (The JIT compilation threshold improves performance and helps the JVM to start quickly. The threshold has been selected carefully by java developers to obtain an optimal performances. Balance between startup times and long term performance is maintained).
Therefore, very frequently used methods are compiled as soon as JVM has started, and less used methods are compiled later.


How JIT improves performance of Most frequently used methods ?
After a method is compiled, its call count is reset to zero and subsequent calls to the method increment it call count. When the call count of a method reaches a JIT recompilation threshold, the JIT compiler compiles method second time, applying more optimizations as compared to optimizations applied in previous compilation. This process is repeated until the maximum optimization level is reached. Most frequently used methods are always optimized to maximize the performance benefits of using the JIT compiler.
Example -
Let’s say JIT recompilation threshold = 2
After a method is compiled, its call count is reset to zero and subsequent calls to the method increment it call count. When the call count of a method reaches a 2 (i.e. JIT recompilation threshold), the JIT compiler compiles method second time, applying more optimizations as compared to optimizations applied in previous compilation.


Disabling JIT compiler >
The JIT compiler can also be disabled, if disabled the entire Java program will be interpreted. Disabling the JIT compiler is not recommended. We must disable JIT to diagnose JIT compilation problems only.

6) More about JDK >
  • Java Compiler - Java compiler is javac tool located in /bin folder of the directory in which JDK is installed. The javac compiles .java file into .class (bytecode) files.
    • There are 2 ways of using javac command >
      • For compiling one file
      • For compiling more than one files >
Enter name of all java files in a file (separated by blank or line breaks(next line) ).  Then enter javac @ fileName
Example -
Let’s say we have three java files  
E:\MyClass1.java  
E:\MyClass2.java
E:\MyClass3.java


Enter name of  name of all java files in a MyFile separated by blank.


E:\MyFile will look like this >
E:\MyClass1.java  E:\MyClass2.java  E:\MyClass3.java


C:\Users\ankitmittal01>e:

E:\>javac @MyFile

E:\>

  • Java Disassembler - javap command disassembles class files. output depends on option used with command.
If no option is used than, javap prints out
  • package,
  • protected and public fields/methods of the classes passed to it.


  • Java Documentation - javadoc contains information about class and methods.


  • Java Debugger -  jdb is debugger for Java classes.

/** Copyright (c), AnkitMittal JavaMadeSoEasy.com */


RELATED LINKS>

Java tutorial - Advantage, Where is java used in real world, platform independent language


eEdit
Must read for you :