0% found this document useful (0 votes)
5 views

JVM

The Java Virtual Machine (JVM) is essential for executing Java programs, performing tasks such as code loading, verification, execution, and providing a runtime environment. It consists of three main subsystems: Class Loader, Memory Area, and Execution Engine, each responsible for different aspects of program execution. Additionally, the relationship between JDK, JRE, and JVM is clarified, with JDK being the development kit, JRE the runtime environment, and JVM operating within JRE.

Uploaded by

shreyassupe346
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

JVM

The Java Virtual Machine (JVM) is essential for executing Java programs, performing tasks such as code loading, verification, execution, and providing a runtime environment. It consists of three main subsystems: Class Loader, Memory Area, and Execution Engine, each responsible for different aspects of program execution. Additionally, the relationship between JDK, JRE, and JVM is clarified, with JDK being the development kit, JRE the runtime environment, and JVM operating within JRE.

Uploaded by

shreyassupe346
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Need for Java Virtual Machine

The need for Java Virtual Machine is to handle the tasks that
it performs which are necessary for the development of
programs involving Java. Java virtual machine performs the
following tasks:

• Loads the code.


• Verifies code.
• Executes the code.
• Provides a run-time environment for various applications.
• JVM provides a Memory area.
• Provides a Register set.
• JVM provides the garbage collection heap.
• Reports fatal errors.
• Provides a class file format
JVM Architecture in Java
• There are three main subsystems in
JVM Architecture:

1. Class Loader
2. Memory Area
3. Execution Engine
1. Loading

• This operation loads files from secondary


memory into the main memory (RAM) for
execution. The Classloader reads the .class
file, generates the corresponding binary data,
and saves it in the method area.
2. Linking
• This operation combines different files in the main program
together. It performs verification, preparation, and
(optionally) resolution.
• Verification: The Verification phase checks the correctness
of the .class file. It means that it checks that the file
formation and generation is by a valid compiler or not. If
the verification fails then we get a java.lang.Verify
Exception.
• Preparation: JVM allocates memory for class variables and
initializes the memory to default values.
• Resolution: Resolution is the process of replacing symbolic
references with direct references. It uses searching into the
method area to locate the referenced entity.
3. Initialization
• This operation involves the assignment of all
static variables with their specific values in the
block of the program.
• In this phase, there is an assignment of all
static variables with their values defined in the
code and static block.
JVM Memory area
1. Method Area– It stores the structure of each class
like method data, field data, runtime pool, metadata.
2. Heap– Heap is the runtime area where object
allocation takes place.
3. Stacks– Stacks store the partial results and local
variables of a program.
4. PC Registers – It stores the address of the currently
executing JVM instruction.
5. Native Method Stacks – It includes all the native
methods required in any application. It is not written in
java.
Execution Engine in Java
• It is the component of JVM that reads data from
memory locations and executes the instructions. It has
three major components namely a virtual processor,
an interpreter, and a JIT compiler.
• Virtual Processor
• Interpreter: Read the bytecode stream then execute
the instructions.
• Just-In-Time(JIT) compiler: It improves performance.
JIT compiles parts of the byte code with similar
functionality at the same time and reduces the
amount of time needed for compilation.
JDK, JRE, And JVM
• JVM stands for Java Virtual Machine.
• JDK stands for Java Development Kit.
• JRE stands for Java Runtime Environment.

• JDK is for the development environment whereas


JRE is for the run time environment.
• JVM runs inside the JRE environment. JRE contains
class libraries, Java Virtual Machine and other files
other than development tools like compiler and
debugger.
• JRE is a subset of JDK. JDK contains JRE along with
development tools such as compiler, debugger, etc.
Structure of
JAVA Program

You might also like