Most probably you heard “Write Once & Run Everywhere” before, this sentence is because the same java code can run on any machine that has JVM installed.
Java Virtual Machine
- It’s a virtual machine that is responsible for running the java code over any operating system, as every operating system has its own version of JVM.
- Platform independent execution environment that converts Java Byte Code into Machine Code and executes it.
Under the hood
- You write Java code in a .java file.
- The compiler converts each .java file into a corresponding .class file, which consists of the Byte Code.
- During the execution, the ClassLoader loads the .class files on the RAM.
- Then the Execution Engine will convert the Byte Code into a native Machine Code, using JIT (Just In Time) compiling.
- The JIT Compiler runs after the user clicks to start the program, the compiler converts the bytecode to machine code on the fly.
- Class Loader: loads the .class files into the RAM.
- Byte Code Verifier: checks if there is any access restriction violation in the code.
- Execution Engine: converts the bytecode into a native machine code.