×

Java Virtual Machine (JVM)

JVM is a virtual runtime environment to execute Java byte codes. The JVM doesn’t understand the keywords we used to write code. That is why it is converted into bytecode.

It controls the execution of the Java programs and enables features such as automated exception handling, Garbage Collection.  When we compile any Java file, the file got translated into the .class file that contains the bytecodes. That “.class” file dives into the number of steps when we execute it. The whole process together describes the JVM.

Java Virtual Machine

ClassLoader

It handles below three activities

  • Loading: It reads the .class file and generates the equivalent binary data and stores it in the method area. For every .class file, it saves fully qualified names of the loaded class, its immediate parent class, modifier, variables, and method information in the method area. JVM creates an object of type Class in the heap memory after loading the .class file.
  • Linking: It checks whether the .class file is formatted correctly and generated by a valid compiler or not. It returns a run-time exception if verification fails. JVM allocates memory for class variables and initializes the memory to default value.
  • Initialization: JVM assigns values to all the static variables defined in the code. It follows the top to bottom approach, i.e. the values assigned from top to bottom or parent to child in the class hierarchy.

Below are three built-in class loaders in Java:

  1. Bootstrap ClassLoader: It is the superclass of the Extension classloader, which loads the rt.jar file that contains all the class files of Java Standard Edition packages such as java.lang, java.net, java.util etc..
  2. Extension ClassLoader: It is the child classloader of Bootstrap and parent classloader that loads the jar files located inside $JAVA_HOME/jre/lib/ext directory or any other directory specified by the java.ext.dirs system property.
  3. System/ Application ClassLoader:It is the child classloader of the Extension classloader. It loads classes from application classpath and internally uses Environment Variable which is associated with java.class.path.

JVM Memory

The JVM memory area divided into these following area:

Method area: It consists of all class level information such as class name, immediate parent class name, variables including static variable and methods details, etc.

Heap area: The heap area is a shared resource that stores the information of all objects at the runtime.

Stack area: For each thread, there is a private JVM stack created at the same time as thread created. It stores frames and holds local variables and play a role in method invocation and return. After the termination of the thread, its runtime stack will be destroyed.

PC Registers: Each thread has its separate PC register and stores the address of the instruction being executed currently.

Native method stacks: Contains all the native methods used in the application.

Execution Engine

The execution engine executes the .class file and reads the byte-code line by line. It contains:

  • A virtual processor.
  • An interpreter that translates the bytecode line by line and executes.
  • Just-In-Time (JIT) compiler: It compiles the bytecode and changes it into native code.

Java Native Interface (JNI)

JNI interacts with the Native Method Libraries and makes available its libraries required for the execution and communicates to libraries written in another language like C/C++.

Native Method Libraries

A collection of the libraries that are written in another language such as C/C++ that are required by the Execution Engine.


Related Topics

Java Program to Sort an Array of 0's, 1's, and 2’s | Dutch National Flag Problem in Java

The famed Dutch computer programmer Edsger Dijkstra's Dutch Nation Flag (DNF) challenge ranks among the most well-known programming challenges. The Dutch tricolor flag, comprising red, white, and blue, is the...

3 minutes read.

Java program to count the occurrences of each character

The count of each character is the frequency of the characters. For example, the given String is “Programming”. In the given string, the count of the characters ‘P’ -1, ’r’-2,...

6 minutes read.

How to convert float to String in Java

How to convert float to String in java There are following methods to convert float to String: Convert using Float.toString(float) Convert using String.valueOf(float) Convert using Float.toString(float) The Float class has a static method that returns...

2 minutes read.

Swastika Pattern in Java

This part teaches us how to create the Swastika Pattern in Java utilizing user-defined columns and rows as well as stars or other special characters.A Java pattern application that is...

2 minutes read.

Sphenic Number in Java

In this section, we will learn what is a sphenic number is and show you how to write Java programmes to determine if a specific number are sphenic or not....

3 minutes read.

Java Trim

Leading and leaving spaces are removed by the built-in Java String trim() method. Space seems to have the Unicode element of "x0040." Java trim() function looks for all of these...

3 minutes read.

Java List Implementations

ArrayList and LinkedList are the two implementations of List that are for general-purpose. You'll probably utilise an array list the majority of the time because it's quick and provides constant-time...

3 minutes read.

How to declare string array in Java

Introduction Array is a data structure with a fixed size, which allows us to store elements of similar type. Data of primitive types like int, char, float, string, etc. can be...

2 minutes read.

Jdoodle Java

Everything is instantaneous and fast-paced in the modern world. Online compilers available via the internet are immensely helpful for programmers seeking to learn a new programming language but lacking the...

4 minutes read.

Different Ways to Print Exception Message in Java

In this section, we will learn how to use various Java Throwable class methods to print exception messages. The Throwable class has the three methods listed below for printing the...

4 minutes read.

Types of Statements in Java

In natural languages, statements and sentences are roughly equivalent. In general, statements are similar to valid English sentences. We will talk about a statement in Java and the different kinds...

11 minutes read.

Session Tracking in Java

When a series of requests from the same User (i.e., requests coming from the same browser) occurs over an extended period of time, servlets employ a mechanism known as session...

3 minutes read.

Java Set Interface

We use set when we don't want to allow duplicate entries. All Set implementations do not allow duplicates. HashSet: This class stores its elements in hash tables. It uses the hashCode()...

3 minutes read.

Types of Sockets in Java

The fundamental idea behind Java's networking capability is the socket. Early in the 1980s, the Berkeley UNIX 4.2BSD version included the socket paradigm. Berkeley socket is the term employed as...

9 minutes read.

Java Do While Loop

When we wish to test the exit condition at the end of the loop, we use a do-while loop. The do-while loop always executes its body at least once, because...

1 minute read.

Java Xmx

This section will explain what Xmx in Java is and how to establish a Java application's maximum heap size. When we execute a Java application, it occasionally displays an error message...

3 minutes read.

How to Call a Method in Java

In Java, a method is a collection of statements that perform a specific task or action.It can accept data with the help ofitsarguments. It  is also called a function. In order...

9 minutes read.

Java Math sin() Method

The sin() method of Java Math class returns the trigonometric sine of the specified angle. Syntax: public static double sin(double a) Parameters: The parameter ‘a’ represents an angle measured in radians. Return Value: The sin() method...

1 minute read.

CopyOnWriteArrayList in Java

The CopyOnWriteArrayList is used to implement the List Interface. It is the improved version of ArrayList. The operations like add, remove, set, update etc, these operations are done by creating...

5 minutes read.

Ordinal Number in Java

What is the Ordinal Number in Java? An object's or person's position or rank can be expressed mathematically using an ordinal number. Depending on the criteria used to establish the positions,...

3 minutes read.