×

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

Awesome explanation of Strings in Java

What do you mean by String? Strings are a collection of characters that are commonly used in Java programming. Strings are regarded as objects in the Java programming language. “String” is a...

4 minutes read.

How to Convert Integer to String in Java

How to Convert int to String in Java It is used when you want to convert an integer to String. You can convert int to String by using the following methods: Using...

3 minutes read.

Collections in Java

Collection framework is one of Java's most powerful subsystems. It is a set of classes and interfaces that is all-the-rage technology for superintending objects and a group of objects. In...

6 minutes read.

How to uninstall the Java in Ubuntu

We need java on our computers in our daily lives because there are lots of different applications that are developed using the java environment, so we have to install java...

4 minutes read.

This Operator Using in Java

this keyword in Java has a wide range of applications. this reference variable in Programming language refers to the object of interest. This keyword is used in Java. this keyword is...

5 minutes read.

Java Viva Questions and Answers

Question: Explain Java programming language. Answer: It is a high-level programming language. This programming language is based on the principles of object-oriented programming. Large-scale applications can be developed by using this...

16 minutes read.

Java Math floorMod() Method

The floorMod() method of Math class returns the floor modulus of the specified arguments. It firstly divides the dividend and divisor and then returns an integer that is equal to...

1 minute read.

Sublime Number in Java

In this tutorial, we will understand what is meant by sublime number in java. From the point of the coding interview, it is one of the important topics. We will we will...

4 minutes read.

How to set timer in Java

In this article, you will be very well equipped with the knowledge to set timer in java. The timer in java can be set by using timer class provided by...

3 minutes read.

What’s new in Java 12

On March 19th, 2019, the Java 12th edition was released. After releasing this edition, they have decided to release every new edition every six months. This version is the advanced...

5 minutes read.

Array Slicing in Java

Array slicing is a method in Java for obtaining a subarray of a specified array. Assume a[] is an array. It contains eight items indexed from a[0] to a[7].a[] =...

3 minutes read.

Collection Programs in Java

Collection Programs in Java Collection in Java provides a way to manipulate or store a group of objects. Each object in a collection is called element. Collection programs in Java mainly...

4 minutes read.

Java Integer doubleValue() method

The doubleValue() method of Integer class returns a double value for this Integer after a widening primitive conversion. Syntax public double doubleValue() Parameters NA Specified by This method is specified by doubleValue in class Number Return Value This...

1 minute read.

How to check valid date in Java?

Every time we get data for any application, we must first ensure that it is accurate before continuing with any further processing. We might have to confirm the following while dealing...

4 minutes read.

Switch Case Program in Java

Switch Case Program in Java The switch case program in Java controls which code snippet gets executed on the basis of the value of the expression mentioned in the switch statement....

22 minutes read.

Java StringBuffer vs StringBuilder

Java StringBuffer vs StringBuilder StringBuffer The StringBuffer class is used to create mutable string. StringBuffer shows writable and growable character sequences. Java StringBuffer program FileName: StringBufferExample.java // A basic program that demonstrates the working...

2 minutes read.

Logger class in Java

Logging is a crucial component of Java that aids developers in tracking down mistakes. The logging technique is included with the computer language Java. The possibility of collect the log...

7 minutes read.

Normal and Trace of a Matrix in Java

Normal of a matrix The square root of the total squares of each element in a matrix is known as the matrix's normal. Think of the following matrix as an example. Example: [[1,2,3]  ...

3 minutes read.

Types of Logical Operators in Java

In this tutorial, we are going to study logical operators. A logical operator is an operator that accomplishes a logical operation that is to connect two or more operations. These...

5 minutes read.

The final Keyword in Java

The final keyword is employed in several instances. Firstly, the non-access modifier final only applies to variables, methods, and classes. The final can be used in the following situations. Final Variables When...

6 minutes read.