Java internal working
Created on: Sep 19, 2024
Let's understand java internal working with hello world program. We will looks what happens internally behind the program.
Let's create a file Test.java
and write below program.
public class Test { public static void main(String[] args) { System.out.println("Hello world"); } }
java code can't be directed executed, it has to be compiled into bytecode. This will produce a file with .class
extension which is bytecode. bytecode is a middle code between human-readable code and machine code. It is platform-independent and is saved in a .class file.
javac Test.java
Let's run the code.
java Test
For below code,below process happens
- Class Loading: Java Virtual Machine (JVM) loads
Test.class
code in memory which is primarily RAM. - Bytecode Verification: JVM performs bytecode verification process to ensure the bytecode does not violate any security constraints. It checks for issues like stack overflows or illegal data access, memory corruption, illegal instructions
- Conversion: Just-In-Time(JIT) which is a part of JVM translates the bytecode into machine code that can be directly executed by the host machine.
- Execution: JVM looks for
main()
method, and starts executing the code. - After execution, JVM terminates.