Java

Java Virtual Machine

A high level programming language is called ava. High level programming languages cannot be directly executed on any computer. It must first be converted into that specific machine language. The javac compiler performs this; it converts the source code from a java program (a.java file) into machine code (referred as byte code or .class file).

The machine language for the Java Virtual Machine (JVM), a virtual machine that lives in the actual machine (your computer), is byte code. As a result, the compiler’s job is made simpler because it just needs to produce JVM-specific bytes rather than distinct machine code for each type of machine. JVM produces output by running the bytes of code produced by the compiler. Java is made platform agnostic via the JVM.

We now know that the main purpose of the JVM is to run the byte code generated by the compiler. Although each operating system uses a different JVM, they all generate the same result when byte code is executed. Thus, byte code produced on Windows may be executed on Mac OS and vice versa. Java is referred to as a platform agnostic language for this reason.

JVM Architecture

Lets see how JVM works:

Class Loader: Reading the.class file and storing the byte code in the method area are done by the class loader.

Method Area: Each class in a JVM has access to the same single method area. This contains details about each.class file’s class level.

Heap: In the JVM’s memory, heap is where objects are allocated. Each.class file generates a Class object thanks to JVM.

Stack: Like Heap, Stack is a component of the JVM’s memory, although it is only used to store temporary variables.

PC Registers: These record which instructions have been carried out and which ones are about to do so. Since threads execute instructions, each thread has its own PC register.

The class loader reads the.class file and saves the bytes in the method area.

Method Area: Each class in a JVM has access to the same single method area. This contains details about each.class file’s class level.

Heap: In the JVM’s memory, heap is where objects are allocated. Each.class file generates a Class object thanks to JVM.

Stack: Like Heap, Stack is a component of the JVM’s memory, although it is only used to store temporary variables.

PC Registers: These record which instructions have been carried out and which ones are about to do so. Since threads execute instructions, each thread has its own PC register.

Native Method Stack: A native method has access to the virtual machine’s runtime data regions.

Native Method interface: It makes it possible for native apps to call or be called by Java code. Native apps are applications designed specifically for a system’s hardware and operating system.

Garbage collection: For the purpose of memory management, a class instance is expressly created by the Java code and is automatically deleted after usage.

JVM Vs JRE Vs JDK

Note: Read on for a quick explanation of the distinctions between JDK, JRE, and JVM in the section that follows.

JRE: The environment in which the Java virtual machine operates is known as JRE. JRE comes with the Java Virtual Machine (JVM), class libraries, and other files but not with the compiler or debugger that are used for development.
This implies that while JRE may be used to run code, it cannot be used to create or compile code.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button