Explanation on Java Architecture & its Components

Explanation on Java Architecture & its Components

Community classroom Blog - Day 4

Introduction to Java Architecture

Compilation and interpretation are the two stages in Java. The Java Compiler that convert Java code into byte codes. The Java Virtual Machine (JVM) transforms byte codes into executable code that is directly executed by the machine.

This procedure may be broken down into the following steps:

  1. The Java Compiler receives the source code.
  2. It is converted into byte codes by the Java Compiler.
  3. The Java Virtual Machine receives the byte codes.
  4. Finally, it is sent to the operating system (OS)

Now that we have a basic understanding of how the Java architecture works, we can look at its many components:

JVM (Java Virtual Machine)

Java's developers meant it to be WORA (Write Once Run Anywhere). This implies that its programs can run on any platform, but the JVM is what gives Java its excellence. The JVM provides the environment in which Java code may be executed. It translates the bytecode and transforms it to machine code so that the Java application may be executed by the machine.

The code is loaded into the JVM, verified, and executed. It also gives the code a runtime environment so that it can execute on the computer.

JRE (Java Runtime Environment)

The JRE creates a runtime environment in which Java programs may be executed. It takes Java code and mixes it with the libraries that are necessary. The JRE also starts the JVM so that it can run. To execute the applications, you'll need the Java Runtime Environment, which includes the necessary tools and libraries.

JDK (Java Development Kit)

The JDK is used to create Java applications and programs. It's a software development environment that includes the Java Runtime Environment (JRE), a compiler, an interpreter, a documentation generator, and an archiver, among other things.

JVM's Components

Let's look at the components of the JVM to have a better understanding of it. The JVM contains numerous components because it performs one of Java's most important functions. We'll go over each point in detail:

ClassLoader Subsystem

ClassLoader is a Java Virtual Machine component that loads class files. It's the initial part of the architecture since it loads the software and allows other activities to run. It also initializes and connects the class files. Its operation may be broken down into three sections:

Loading

The classes are loaded using this component. The BootStrap ClassLoader is responsible for loading classes from the bootstrap classpath. The Extension ClassLoader loads classes from the ext folder, whereas the Application ClassLoader loads files from the location given in the Environment Variable.

Linking

The subsystem includes a validator that checks if the bytecode is accurate. The verification error will be generated if the bytecode is incorrect. The linking section sets the default values for all static variables and allocates memory for them. It also replaces memory's symbolic references with new ones.

download (1).png

Initialization

The system sets the static variables to their original values and performs the static block in this part of ClassLoading.

Data Area for Runtime

The following categories are as follows this part of the JVM:

The Area of Method

All of the class-level data is stored in the method area. There is just one method section in every JVM.

The Area of Heap

All of the Objects, as well as their instance arrays and variables, are stored in the heap area. A JVM has only one heap area, much like the method area.

The Area of Stack

This component generates an entry in the stack memory for each method call and builds distinct runtime stacks for each threat (also known as Stack Frame). It has a Local Variable Array associated with the method, an operand stack that serves as a workspace for intermediate operations, and frame data that contains all symbols associated with the method. Unless there is an exception, the frame data keeps the catch block information.

PC Registers

Each thread has its own PC Register, which stores the address of the currently running instructions. The PC register updates itself with the following instruction once an instruction has completed execution.

Stacks of Native Methods

This section contains information regarding the native technique, as the name implies. For each danger, it builds a custom native method stack.

It's worth noting that the Runtime Data Area's first two components are shared resources, but the stack area is not.

Engine of Execution

The bytecode is executed by the Execution Engine. It reads it piece by piece and then executes it. It also includes the following elements:

Interpreter

This component efficiently interpreters bytecode but is a little sluggish to execute. It has a big disadvantage in that it demands a fresh interpretation every time the system calls one method. The interpreter's flaw significantly reduces the efficiency of the procedure.

JIT Compiler

The interpreter has a disadvantage that the JIT Compiler does not. When the Execution Engine detects repetitive code, it switches to the JIT Compiler rather than the interpreter. After compiling the bytecode, the JIT Compiler transforms it to native code. The native code is directly used by the system.

The JIT Compiler includes an intermediate code generator and a code optimizer for creating and optimizing intermediate code. It also includes a target code generator that generates the native doe as well as a profile that locates hotspots.

Garbage Collector

The garbage collector is the final component of the Execution Engine, and it collects and disposes of unreferenced objects. It can be triggered by calling system.gc(), but this does not ensure that it will be executed.

The JVM also contains the JNI (Java Native Interface) and the Native Method Libraries in addition to these components. The former communicates with the latter and supplies the Native Libraries required for execution.

That's it for today!

Reference: Introduction to Java - Architecture

This video will undoubtedly assist you in gaining a better understanding of Java Architecture