×

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 Pi

What is Pi? There are many formulas in geometry that employ the Pi constant to calculate things like circumference, area, and volume. A circle's circumference divided by its diameter yields a...

3 minutes read.

Program to Implement FLAMES Game in Java

Friends, Lovers, Affectionate, Marriage, Enemies, and Sibling are all represented by the acronym FLAMES, which also serves as the name of a well-known game. Although, it can be entertaining to...

4 minutes read.

XNOR operator in Java

The opposite of the binary equivalent of XOR is given by XNOR. Truth table: XYXNOR001010100111 If the bits are the same, it returns 1, else it returns 0. Examples:  Input: 10 20 Output : 1 A Binary...

3 minutes read.

Java String getBytes() method

getBytes() method returns sequence of bytes. Syntax: There are three variants of getBytes() method: public byte[] getBytes()        public byte[] getBytes(String charsetName) public byte[] getBytes(Charset charset) Returns: It returns sequence of bytes. Java String getBytes() Example...

2 minutes read.

Java RandomAccessfile

Writing and reading to random access files are done using this class. An array of many bytes is how a random access file operates. By changing the implied file pointer...

3 minutes read.

Merge Sort in Java

Merge Sort in Java Merge sort in Java uses the divide and conquer approach to sort the given array/ list. There are three steps involved in the merge sort. 1) Divide the...

5 minutes read.

Vectors in Java

Vector Class We may make resizable arrays comparable to the ArrayList class using the Vector class, which implements the List interface. A vector is similar to a dynamic collection that can...

4 minutes read.

Blocking Queue in Java Example

Let's first briefly comprehend queue before moving on to the topic of "Blocking Queue." A queue seems to be an orderly list of items in which elements are added from...

8 minutes read.

Java String toUpperCase() methods

Java String toUpperCase() method is used to convert all the characters of the String into upper case. Syntax public String toUpperCase() public String toUpperCase(Locale locale) Returns It returns upper case String. Java String toUpperCase() Example 1: public...

1 minute read.

Java Byte Keyword

Byte: The Keyword Byte in Java programming language is a primitive data type.Digital content that is most used for eight bits is called as a byte.The Java Byte Keyword is used...

3 minutes read.

String Array in Java

String Array in Java An array is alinear data structure that stores similar type of data. It allows us to store fixed number of elements.It can be of different data types...

6 minutes read.

Java Integer min() method

The min()  method of Integer class returns the smaller of two int values. It returns the same result as by calling Math.min.  Syntax public static int min(int a, int b) Parameters The parameters ‘a’...

2 minutes read.

How to enable java in chrome

The Java module is huge for the Java Runtime Environment (JRE). It permits a program to work with the Java stage to run Java applets. Essentially, each of the undertakings connect...

3 minutes read.

Difference between JIT and JVM in Java

In this tutorial, we will discuss the difference between JIT (Just In Time Compiler) and JVM (Java Virtual Machine) in Java. Before we move to the differences, let's understand what...

4 minutes read.

Set Matrix Zeros in Java

In coding round interviews, it is frequently asked as the most significant challenge. an m*n matrix is provided. Set the entire column and row of the matrix to 0 if any...

6 minutes read.

Thread Synchronization in Java

In Java, the smallest processing component is a thread, which is a small subprocess. It follows a different course of action. Threads are autonomous. If an exception occurs in one thread,...

6 minutes read.

Java Architecture

Java architecture is a combination of three parts they are JVM, JRE and JDK. These components will help in the functioning of the java programs. The process of code interpretation...

6 minutes read.

Segment Tree in Java

Binary trees can address a variety of issues; however, the Segment Tree is more efficient in terms of time complexity. The segment tree in Java is represented using an array. Native...

4 minutes read.

Java Program to Add Digits Until the Number Becomes a Single Digit Number

We will develop Java programme that increase a number's digit count in order to reduce it to one. The issue is also known as the digit root problem. Example Consider the case where...

3 minutes read.

The Diamond Operator in Java 7

The Diamond operator is a comparatively recent Java operator originally developed in JDK 7 to enhance type identification and eliminate boilerplate Java code. The Diamond operator is characterized by a...

2 minutes read.