What is JDK, JRE and JVM ??

We must know the differences between JDK, JRE and JVM before proceeding further in java.

What is JVM ??

JVM (Java Virtual Machine) is a abstract machine that enables the computer to run a Java program. A bytecode is generated from the java code when the java compiler first compiles the java code. After that, the JVM translates the bytecode into a set of instructions that the CPU can understand and directly executes it.

Java Development Kit(JDK)

Components of jvm are :

  • Class Loaders
  • Run-Time Data areas
  • Exceution engine

Class Loaders:

During runtime, Class loaders are responsible for dynamically loading java classes to the JVM (Java Virtual Machine) and they are the part of JRE (Java Runtime Environment). It is due to class loaders that in order to run java code the JVM doesn’t need to know about the underlying files or file systems. Class loaders are responsible for loading classes into memory because these Java classes aren’t loaded into memory all at once, but when required by an application.

Run-Time Data areas:

To execute a Java program different memory areas are defined by the JVM known as run-time data areas and are used during runtime. Some of these areas are created when JVM starts and destroyed when JVM exits while when a thread is created some of these areas are created and when a thread exits they are destroyed.

Following are the different runtime data areas :

Method Area:
Method area is storage area for compiled code. It stores structures such as field, method-data, constructors, code for methods and class names. For each and every class these structure is stored by the JVM . This memory area is shared by all the threads present in the JVM.

Heap Area:
It is the area where memory for all the arrays and class instances are allocated by the JVM. The heap memory for objects is reclaimed by the Garbage Collector (GC).
As soon as JVM starts, it creates heap area. This area is shared by all the threads present in the JVM. For heap area the memory does not need to be together in sequence.

Stack Area:
Stack area is the area where each frame stores nested method calls, partial results and local variables and data is stored as frames. JVM creates the stack area whenever new thread is created. This area is private for each thread.
In JVM stack, the memory does not need to be in a sequence.

PC Registers:
The PC Register which stores the address of the currently executing instruction is a part of JVM thread. This value is not defined if the currently executing instruction is a part of the native method.

Excecution engine:

Execution engine executes the instructions using information present in the memory areas.
It has following three parts:

Once classloaders load and verify bytecode, the interpreter executes the bytecode line by line. This execution is quite slow. The disadvantage of the interpreter is that when one method is called multiple times, every time new interpretation is required.

Just-In-Time (JIT) Compiler:
It is responsible for the optimization of the Java programs. During run-time it compiles the bytecode of the often-called methods into native code.
JVM automatically monitors which methods are being executed. It schedules for compilation into machine code when a method becomes eligible for JIT compilation. A different JVM thread is used for the compilation into machine code.
It does not interrupt the execution and runs the java code faster after the compilation is completed.

Garbage Collector:Garbage Collection feature helps Java to takes care of memory management. By looking at heap memory, it identifies which objects are being used and which are not being used and then deletes the objects which are unused.
Garbage collector is a "daemon thread". System.gc() method can be used to call it explicitly. However, it won’t be executed immediately, JVM decides when to invoke GC.

Java Native Method Interface:

It acts as an interface between the native (C/C++) libraries and the Java code.

What is JRE ??

JRE (Java Runtime Environment) is a software package that provides Java class libraries, along with Java Virtual Machine (JVM), and other components to run applications written in Java programming. It is used to provide the runtime environment.
Core components of the JRE include:

  • An implementation of a Java Virtual Machine (JVM)
  • Classes required to run the Java programs
Java Runtime Environment(JRE)
JRE is the specification of JVM & JVM is the implementation of JRE.

What is JDK ??

JDK is also known as the Java Development Kit. JDK (Java Development Kit) is a software development kit to develop applications in Java. Whenever we download JDK, JRE is also downloaded so there is no need to download it separately. In addition to JRE, JDK also contains a number of development tools like Java debugger, compilers, JavaDoc etc .
Core components of the JDK include:

Java Development Kit(JDK)
  • JRE
  • Development Tools

Some of the development tools that we need for compiling, debugging, archiving, generating Javadocs includes:

  • Javac : It is a command that reads and compiles the java program to generate the class files which contains the instructions written in bytecode.

  • Java : Java application is launched using this command.

  • Javadoc : From Java source files it generates HTML pages of API documentation.

  • Appletviewer : Without a web browser it allows us to run Java applets .

  • Jar - The Packaging of java application and applets are done into a single archive .

  • Jdb : It is used to find and fix bugs in Java applications and is also a command-line debugging tool .

  • Javah : From a Java class it produces C header and source files.

  • Javap : It deconstruct the class files and displays information about methods, fields, and constructors present in a class file .

  • Jconsole : It lets us monitor and manage Java applications by providing a graphical console.

  • Jps : On the target system it lists the instrumented JVMs.

  • Jstat : The statistics of JVM is monitered .

  • jstatd : monitors creation and termination of instrumented JVMs

  • Jmap : It prints the memory information of a specified process which can be the heap memory or object memory.

  • Jsadebugd : It acts as a debug server .

  • Jstack - For a given Java process it prints Java stack traces of Java threads .

  • Extcheck : Detects version conflicts between target Java Archive (JAR) file and currently installed extension JAR files.

Here, we get the knowledge of the basic difference between JVM, JRE, and JDK .

Do You Know?