Overview: From .java → Running Program

A highly motivated and experienced full-stack developer with a proven track record of developing and deploying web applications. Skilled in a range of programming languages and frameworks, as well as database technologies. Comfortable working in a fast-paced environment and able to adapt to new technologies quickly. A team player who is also able to work independently when required.
YourCode.java
↓ (javac compiler)
YourCode.class (bytecode)
↓ (JVM - Java Virtual Machine)
Runs on any OS (Windows, Linux, Mac, etc.)
This is the magic of Java: Write Once, Run Anywhere (WORA).
Step-by-Step: What Happens Behind the Scenes
1. You write OOP code (classes, objects, inheritance, etc.)
Example:
public class Dog extends Animal {
private String name;
public Dog(String name) {
this.name = name;
}
public void bark() {
System.out.println(name + " says Woof!");
}
public static void main(String[] args) {
Dog d = new Dog("Buddy");
d.bark();
}
}
2. Compilation with javac (Java Compiler)
When you run:
javac Dog.java
Here’s what happens internally:
| Phase | What Happens |
| 1. Lexical Analysis | Code → tokens (like public, class, Dog, {, etc.) |
| 2. Parsing | Tokens → Abstract Syntax Tree (AST) — checks syntax |
| 3. Semantic Analysis | Checks types, access rules (e.g., can you access private field?), resolves inheritance, method overriding, etc. |
| 4. Bytecode Generation | Converts the AST into Java Bytecode (.class file) — low-level, platform-independent instructions |
The resulting Dog.class contains bytecode — not machine code!
This bytecode understands OOP concepts like:
Classes and objects
Inheritance (
extends)Polymorphism (method overriding)
Encapsulation (private/public)
this,super, virtual method calls
3. How OOP Features Are Handled in Bytecode
| OOP Feature | How Java Handles It Internally |
| Objects | Created on heap using new → triggers <init> constructor |
| Inheritance | Each class has a superclass pointer. Method calls use virtual method table (vtable) |
| Polymorphism | Method calls like animal.speak() are virtual calls — JVM looks up actual method at runtime using vtable |
| Encapsulation | private fields → bytecode can't access directly (enforced by verifier) |
| Interfaces | Implemented via interface method tables |
4. Execution by JVM (java command)
When you run:
java Dog
The JVM (Java Virtual Machine) loads Dog.class and starts executing:
Class Loader
Loads
.classfilesVerifies bytecode is safe (no illegal memory access)
Links (resolves references to other classes)
Bytecode Interpreter or JIT Compiler
Initially: Interprets bytecode line by line
After some runs: JIT (Just-In-Time) Compiler converts hot (frequently used) bytecode → native machine code (super fast!)
Runtime Data Areas
Heap: All objects live here (
new Dog())Stack: Local variables, method calls
Method Area: Class info, static variables
PC Register: Current instruction pointer
Native Method Stack: For native (C/C++) code
Garbage Collector (GC)
Automatically frees memory when objects are no longer used
Huge benefit of Java OOP — no manual
free()ordelete
Summary: Behind the Scenes Flow
Dog.java
↓ javac
Dog.class (bytecode with OOP info: vtables, inheritance, etc.)
↓ JVM ClassLoader → Verification → Linking
↓ JVM Execution Engine (Interpreter + JIT)
↓ Runs as native code on your CPU
↓ Objects created on heap, GC cleans up
Why This Design?
OOP at language level → easy for developers
Bytecode + JVM → portable, secure, high-performance (thanks to JIT)
Supports advanced OOP cleanly (even reflection, dynamic proxies, etc.)
Fun Fact
You can see the actual bytecode using:
javap -c Dog.class
It shows instructions like:
invokespecial #3 <Dog.<init>>
invokevirtual #4 <Dog.bark>
These are how OOP method calls become real instructions!


