Java Virtual Machine (JVM)

Shehara Luvis
2 min readJul 25, 2022

--

The Java Virtual Machine (JVM) is a specification that defines a runtime environment for executing Java bytecode. The term specification means ‘what must be done.’

Java as you already know is platform independent. Which means it can run on any platform which is a combination of software and hardware. Platform independence does not imply that it can operate on any operating system. That is why I specifically stated ‘combination of software and hardware’ which indicates the word ‘Platform’.

The JVM starts when we type the keyword ‘java’ and the name of the class file (java test). There are 2 types of threads in Java. They are Demon and Non-Demon. As soon as you type the keyword ‘java’ and your file name it creates a main method which is a Non-Demon thread that will start the JVM. There can be multiple main methods. As long there is a Non-Demon thread, the JVM will not be terminated. In other words, if there’s no Non-Demon thread the JVM will terminate.

Now let’s try to understand the architecture of a Java virtual machine

1. Classloader

Ø The Classloader is a subsystem of the JVM which is responsible for loading class files. The classloader loads the java application first whenever we execute it. Java has three built-in classloaders.

i. Bootstrap ClassLoader

ii. Extension ClassLoader

iii. System/Application ClassLoader

2. Class area

Ø Class structures such as metadata, the constant runtime pool, and method code are stored in the Method Area.

3. Heap

Ø This is where objects are stored at runtime

4. Stack

Ø Local variables and partial results are stored in the stack, which also helps with method invocation and returns.

5. PC register

Ø The address of the Java virtual machine instruction presently being executed is stored in the program counter (PC) register.

6. Native method stack

Ø It includes all of the application’s native methods.

7. Execution engine

Ø It’s a kind of program that’s used to test hardware, software, or entire systems. The test execution engine never stores any data about the product being tested.

8. Native Method interface

ØThe Java Native Interface (JNI) is a framework that allows you to communicate with another program built in a different language, such as C, C++, or Assembly. To transmit output to the Console or communicate with OS libraries, Java employs the JNI framework.

References

Hartman, J., 2022. guru99. [Online]
Available at: https://www.guru99.com/java-virtual-machine-jvm.html
[Accessed 15 June 2022].

Javatpoint, 2022. Javatpoint. [Online]
Available at: https://www.javatpoint.com/jvm-java-virtual-machine
[Accessed 15 June 2022].

Sierra, K. & Bates, B., 2005. Head first Java. 2nd ed. Sebastopol,: O’Reilly Media, Inc.

--

--