1. How Java Executes
Java Execution Process:
Client → Java Code (Hello.java) → Compiler → Byte Code (Hello.class) → JVM (JRE, JDK)
Important Components :
The .class file Code can't Directly runs on the System.We need JVM to run this.The Reason behind is Java is Plaftom Independent
JVM – Java Virtual Machine
JRE – Java Runtime Environment
JDK – Java Development Kit
Platform Independence meaning :
i) Platform independence means the same code can run on all operating systems,Source code must be converted to machine code for the computer to understand,A compiler helps convert human-readable code into executable form.
ii) After compiling C/C++ code, we get .exe files which are platform-dependent.
iii)But Java compiles to bytecode, which is Platform-independent.
iv)The JVM converts bytecode to machine code.
v) Java is platform-independent, but JVM is platform-dependent.
2.Architecture of Java
Layered View:
JDK
└── JRE (JVM + Library classes)
└── JVM
└── JIT (Just-In-Time Compiler)
2.1 JDK:(Development tools + JRE)
Provides the environment to develop and run Java programs.
A package that includes:
i) Development tools – Environment to build programs.
ii) JRE – Executes your program.
iii)Compiler – javac
iv) Archiver – jar
v) Docs Generator – javadoc
vi) Interpreter/Loader
2.2 JRE:(JVM + Library Classes)
An installation package that provides the environment to run Java programs.
JRE includes:
i) Deployment technologies
ii) User interface toolkits
iii)Integration libraries
iv) Base libraries
v) JVM
3. How JVM Works (Class Loader & Execution)
At Compile Time:
Java File (.java) → Compilation → .class file
At Runtime:
.class → Class Loader → Bytecode Verifier → Interpreter/JIT → Runtime → Hardware
JVM allocates:
Heap Memory → Stores objects
Stack Memory → Stores function calls and variables
4.How JVM Works (Class Loader)
i). Loading:
Reads .class
file and generates binary data.
An object of the class is created in heap memory.
ii). Linking:
Verification – Validates the .class
file.
Preparation – Allocates memory for class variables and sets default values.
Resolution – Replaces symbolic references with actual references.
iii). Initialization:
Assigns values to static variables.
Executes static blocks in the class.
iv)Interpreter:
- Line-by-line execution.
- Each method is called every time from the beginning.
v)JIT (Just-In-Time Compiler):
- Optimizes performance.
- Replaces repeated interpreter steps with compiled native code.
- Avoids repeated interpretation.
- Speeds up execution.
- Useful for garbage collection too.
5.Working of Java Architecture
The source code is compiled by JDK into bytecode.
The JVM takes bytecode and converts it into machine code.
The program runs in JRE, and you get the output on screen.
Top comments (0)