Header Ads

JDK Architecture | JVM architecture | JIT Complier | JRE architecture | How Java source code is converted into machine understandable language | Software testing interview Question 2

 What is JDK


JDK architecture


This is the second article on software testing interview question. In this,  we will discuss JDK architecture and JVM architecture, the different components of the JVM, what is a JIT compiler, what is garbage collector, how a Java program works, and how it is converted into a machine-understandable language and many more.

JDK stands for Java Development Kit.
It is a package that consists of Java Development tools like Java compiler (Javac) & JRE for execution.

JDK=JRE + Development tool

JRE= JVM + Library classes

JDK Architecture


What is JRE:

JRE stands for Java Runtime environment
It is an environment consisting of JVM and built-in class files required for the execution of the Java Program.

What is JVM

JVM stands for Java virtual machine

It helps to convert bytecode into current system understandable language i.e low level language with the help of an interpreter & JIT compiler. The main task of JVM is to convert byte code into machine code.

First of all, it loads the code into the memory and verifies it. Then it executes the code and provides a run time environment.

Now let's understand the architecture of JVM:

In JVM , three layer are there
1. Class loader
2. JVM memory
3. Execution engine

JVM architecture


Claas loader: 

The class loader is used to load the class files. It first loads the Java code whenever we run it. In class loader, three components are there.

To load the class into a memory location, three components are there 
1). Bootstrap class loader 
2). Extension class loader 
3). Application class loader.

The second component of the class loader is linking. Under linking, there are three components 
1). Verify 
2). Prepare 
3). Resolve.

Verify component will verify the .class file and this feature will make Java more secure. If some issues are there in the .class file then it will tell the invalid .class file.

Prepare component will provide the memory to class-level data like static variables etc and initialize their value.
The resolve component will replace the symbolic name with the original name.

Third component of class loader is Initialization: 

In this ,the below actions will be done
1). All static variables are assigned the original value
2). Static block will be executed from top to bottom.

JVM Memory : 

JVM memory will destroyed as the JVM exits. JVM memory divided into various parts

  1. Class(Method) Area
  2. Heap
  3. Stack
  4. Native Method Stack

Method area:

Class method area is the area in memory which stores the class data during the execution of code. It holds the data of static variable, static varibale, static block and instance method etc.

Heap:

It is created when JVM starts. Its size may be decrease or increase while running the application. It will store object, array etc.

Stack:

It is also known as thread stack.
It is created for the single execution thread inside the JVM memory.
it is used by a thread to store various elements i.e. local variable, partial results, and data for calling methods and returns.

Execution engine:

  1. JIT Compiler
  2. Garabage collector

What is JIT complier:

JIT stands for just in time compiler
It is an integral part of JVM. It helps to improve the performance of Java programs by compiling byte code into native machine code at run time. It will increase the  execution performance many times over the previous level one. JIT compiler is enabled by default    

What is Garbage collector

As the name suggests it will used to collect the unused materials. It will track each and every object available in the JVM heap space and remove the unwanted ones.

Garbage collectors work in two simple steps known as mark and sweep:
Mark: it is where the garbage collector identifies which piece of memory is in use and which is not.
Sweep: it removes object identified during the "mark" phase

Now understand Java source code is converted into machine understandable language:


First source code will be converted into a class file and this is done with the help of compiler. The class file is in the byte code format and that class file is used by JRE ( internally JVM ) to convert it into object file. Object file is in machine-understandable language

how java program works

I hope this article will be helpful to you. In the upcoming article, we will discuss more software testing interview questions, please do share this article on your social media handles

Thanks,
Rajat Bhatti
Ping me for more details :
Linkedin :Let's connect on LinkedIn.
For more details Join our Whatsup Group : Whatup Group
To get daily job updates on software testing: To get Daily Job updates, click me
9050358180

No comments

Powered by Blogger.