Java Execution Flow: Class Loader, JRE Internals, and Static vs Instance

🚀 Day 30 – Core Java | How Java Actually Executes (Static, Class Loader & JRE Internals) Today completely changed our understanding of Java execution. For 30 days, we believed: “Java program execution starts from the main method.” Today we proved — that is NOT the complete truth. 🔹 What Really Happens When a Java Program Runs? Step-by-step execution flow: 1️⃣ OS gives control to JVM 2️⃣ JVM loads the class (via Class Loader) 3️⃣ During class loading: Static Variables are initialized Static Blocks are executed 4️⃣ Only then → main() method is executed So execution does NOT start from main directly. It starts from: Static members during class loading. 🔹 Class Loader – The Hidden Hero When a class is required during execution: JVM does not load it alone It takes help from Class Loader Class Loader loads required .class files into memory Important Interview Point: Class Loader is a part of JDK that helps JVM load classes during execution. 🔹 File Name vs Class Name – Biggest Myth Broken We proved practically: File name does NOT have to match class name. A single .java file can contain multiple classes. Multiple classes can even contain main() methods. JVM executes only the class you explicitly give while running. Example: javac Code.java java Demo JVM executes only Demo.class. 🔹 Inside RAM – JRE Structure When binary code is loaded into RAM: It enters JRE and is divided into: Code Segment Static Segment Heap Segment Stack Segment Execution order inside memory: 1️⃣ Static Variables 2️⃣ Static Block 3️⃣ main() 4️⃣ Object Creation → Heap 5️⃣ Instance Block 6️⃣ Constructor 7️⃣ Instance Methods This is the real execution hierarchy. 🔹 Static vs Instance (Golden Rule) Static belongs to Class Instance belongs to Object Static members are loaded during class loading. Instance members are created during object creation. Static cannot directly access instance members. Instance can access static members. This single rule clears 50% of Java confusion. 💡 Biggest Takeaway Java execution is not about writing syntax. It is about understanding: Class loading Memory allocation Stack & Heap behavior Static vs Instance lifecycle Execution flow order Strong fundamentals in memory behavior = Strong technical interviews. Day 30 built real internal clarity of Java execution. From here onwards, we move deeper into static concept and its real-world importance 🚀 #Day30 #CoreJava #JavaExecution #StaticKeyword #ClassLoader #JVM #JavaInternals #DeveloperJourney

To view or add a comment, sign in

Explore content categories