JVM, JRE, JDK Surface Knowledge

BuddhiK
5 min readDec 19, 2023

- Java Virtual Machine — JVM -

As per the name, JVM does not physically exist. It just provides a run time environment to execute Java byte code and convert it into machine language. It also can run programs written in other languages and convert(compile) them into Java byte code and then into the machine language. JVM enables run your program on your machine or in the cloud environment.

Features of JVM

  • It can execute programs line by line and interpret byte code to machine code
  • It’s independent of OS and the hardware, make once you write Java code you can run it anywhere.
  • JVM is customizable. ex: JVM heap size, thread size, garbage collection time, etc.

Further reading…

Things that JVM do

  1. Load the code
  2. Verify the code
  3. Execute the code
  4. Providing run-time environment

JVM Architecture

fig 01: JVM architecture

Class Loader

Class loader performs Loading, Linking, and Initialization. Class loader loads necessary classes to run your Java program. There are three main categories of classes loader loads.

  1. The bootstrap class loader is the supper class extension of the class loader here. It loads the rt.jar class files of packages in Java standard edition like the java.lang package class, java.net package class, etc.
  2. Then the extension class loader is the child class of the bootstrap class. It loads the jars from $JAVA_HOME/jre/lib/ext directory.
  3. System Class Loader is the child of the Extension class and loads the class files from the current directory (default location class file path). If you want to have your own class loader you have to extend the ClassLoader class.
fig 02: Class Loader Architecture

JVM Memory areas

Class/Method area: Runtime constant pool, field and method data, and the code for methods.

Heap: Common memory shared across multiple threads which contain,

  • Objects
  • Objects instance variables
  • Object instance arrays

Language Stack:

  • Stores frames that contain local variables and partial results.
  • When a thread is created each time, JVM creates its own private new Language stack.
  • When a method invokes a frame will be created and after the invocation is completed the frame will destroy automatically.

PC Register: Program Counter Reg

  • Each thread has its own pc register.
  • The address of the JVM instruction which is currently executing stored in the PC register.

Native Method Stack

  • Contains the native methods/instructions used in your application.
  • It's written in other languages, not in Java.

Execution Engine

  • Contains a virtual processor, interpreter, and JIT compiler(Just In Time).
  • The virtual processor processes the code and then the interpreter interprets the byte code and executes the instructions.
  • JIT is used to enhance the performance of the process by translating Java code into fast native machine code. It reduces the burden on the CPU.
  • JIT Further

Not like in other compilers that translate the entire program into machine code before execution, JIT dynamically translates and optimizes the code at runtime, just before it is executed by the computer’s processor.

JIT can make decisions depending on the codes by analyzing the code behavior and characteristics of the performance such as applying techniques like inlining, loop unrolling, and dead code elimination

Native Method Interface

Is a framework that provides an interface to communicate with the applications written in languages other than Java.

Native Method Libraries

Collection of native libraries like C+, C#, C++, etc ..which are used by the execution engine.

- Java Runtime Environment — JRE -

  • Java RTE is a set of software tools that are used to develop Java applications. But it does not contain any tool for Java development like a debugger, compiler, etc.
  • Therefore developer can write the code using JRE but cannot compile it.
  • It contains class libraries, loader class, and JVM
  • Unlike the JVM JRE physically exists.

JRE Functions

fig 03: JRE Functions

JRE Architecture

fig 04: Java Runtime Environment Architecture
  • rt.java
  • Contains math, swing, util, lang, awt, etc class libraries.

- Java Developmet Kit- JDK-

  • JDK is a software development environment for making Java applications.
  • Java developers can use the JDK on any platform like Windows, macOS, Solaris, and Linux.
  • It helps to code, compile, and run your code.
  • It is made out of the required tools to write a program and JRE to execute the program.

JDK Architecture

JDK Installation

You can notice there are two kinds of JDKs, Oracle JDK and Open JDK. Mainly Oracle JDK is not free for commercial use and open JDK is free for commercial use.

Download Open JDK's newest stable version from below

Download Oracle JDK from below

You should download and set paths and Java home according to your OS.

--

--

No responses yet