About Java Virtual Machine

The Java language is both compiled and interpreted. The compiler converts the source code that resides in files whose extension is .java, to a set of instructions that are called bytecodes that are saved in a file whose extension is .class. These instructions are independent of the type of computer. The interpreter executes each of these instructions on a specific computer. It is only necessary, therefore, to compile the program once, but it is interpreted each time it is executed on a computer.

What is JVM

♦ Each Java interpreter is an implementation of the Java Virtual Machine (JVM). 

♦ The bytecodes allow the objective of “write once, run anywhere”, to write the program once and that can run on any platform that has an implementation of the JVM. For example, the same Java program can run on Windows 98, Solaris, Macintosh, etc.

♦ The Java Virtual Machine form an intermediate layer that isolates the Java program from hardware specificities.

What it does

The Java Virtual Machine (JVM) is the environment in which Java programs are executed, its main mission is to guarantee the portability of Java applications. It essentially defines an abstract computer and specifies the instructions that this computer can execute. The specific Java interpreter executes the instructions that are saved in files whose extension is .class. The main tasks of the JVM are the following:

ο Reserve memory space for created objects

ο Release unused memory (garbage collection).

ο Assign variables to registers and stacks

ο Call the host system for certain functions, such as access to devices

ο Monitor compliance with the security standards of Java applications

This last task is one of the most important tasks performed by the JVM. In addition, the Java languages own specifications contribute extraordinarily to this objective:

References to arrays are verified at the time of program execution

There is no way to directly manipulate pointers

The JVM automatically manages the use of memory, so that no gaps remain.

Certain conversions (casting) between different types of data are not allowed.

JVM Architecture

 

1) Classloader

It is a subsystem of JVM Architecture which is used to load class files. Java contains three type of inbuild classloader. 

Bootstrap ClassLoader: This is the classloader which is basically the Extension of the superclass. It contains all class files of Java Standard Edition.

• Extension ClassLoader: This is the extension of Bootstrap ClassLoader and called its child. It loads the jar files which are place in the located directory.

• System/Application ClassLoader: This is the called the child of Extension classloader. This classloader is set on to the current directory. It another name is Application classloader.

public class SpiritSha {

           public static void main(String arg[]){
            Class<SpiritSha> cl= SpiritSha.class;
            System.out.println(cl.getClassLoader());
            System.out.println(String.class.getClassLoader());

        }

    }

Output

jdk.internal.loader.ClassLoaders$AppClassLoader@6659c656
null

2) Class(Method) Area

This area store constant, field and method data and the code for methods.

3) Heap

Objects are allocated at runtime.

4) Stack

JVM stacks store local variables and partial results.

5) Program Counter Register

It holds the address of the Java virtual machine instruction which are at present in running mode.

6) Native Method Stack

Hold native methods

7) Execution Engine

It contains A virtual processor, Interpreter, and Just-In-Time(JIT) compiler.

8) Java Native Interface

It provides the gateway to make a connection with other application which is written in other programming languages like C, C++ etc. Java uses this framework to send output to the console.