🚀 𝐇𝐨𝐰 𝐚 𝐉𝐚𝐯𝐚 𝐏𝐫𝐨𝐠𝐫𝐚𝐦 𝐑𝐮𝐧𝐬 – 𝐒𝐭𝐞𝐩 𝐛𝐲 𝐒𝐭𝐞𝐩 Ever wondered what actually happens when you run a Java program? Here’s the complete flow from .java file to output 👇 🔹 1️⃣ 𝑾𝒓𝒊𝒕𝒊𝒏𝒈 𝒕𝒉𝒆 𝑷𝒓𝒐𝒈𝒓𝒂𝒎 We write Java code in a file with .java extension. This code is human-readable but not understood by the machine. 🔹 2️⃣ 𝑪𝒐𝒎𝒑𝒊𝒍𝒂𝒕𝒊𝒐𝒏 (𝒋𝒂𝒗𝒂𝒄) The Java Compiler checks the syntax and converts the .java file into a .class file. ✔️ .class file contains bytecode ✔️ Bytecode is platform-independent 🔹 3️⃣ 𝑪𝒍𝒂𝒔𝒔 𝑳𝒐𝒂𝒅𝒆𝒓 The Class Loader loads the .class file into memory. It ensures classes are loaded only once and in the correct order. 🔹 4️⃣ 𝑩𝒚𝒕𝒆𝒄𝒐𝒅𝒆 𝑽𝒆𝒓𝒊𝒇𝒊𝒄𝒂𝒕𝒊𝒐𝒏 Before execution, JVM verifies bytecode for: ✔️ Security ✔️ Memory access ✔️ Illegal code This makes Java safe and reliable. 🔹 5️⃣ 𝑬𝒙𝒆𝒄𝒖𝒕𝒊𝒐𝒏 𝒃𝒚 𝑱𝑽𝑴 The Execution Engine runs the bytecode: Interpreter executes line by line 🔹 6️⃣ 𝑶𝒖𝒕𝒑𝒖𝒕 The JVM interacts with the OS and hardware, and finally you see the output. 📌 𝗞𝗲𝘆 𝗧𝗮𝗸𝗲𝗮𝘄𝗮𝘆: ➤ Java is compiled once and run anywhere ➤ .class file + JVM = Platform Independence #Java #CoreJava #JVM #JavaBasics #Compilation #LearningJourney #JavaDeveloper
Java Program Execution Flow: From .java to Output
More Relevant Posts
-
📌 📍 𝐃𝐚𝐲 𝟑 | 𝐀𝐈-𝐏𝐨𝐰𝐞𝐫𝐞𝐝 𝐉𝐚𝐯𝐚 𝐅𝐮𝐥𝐥 𝐒𝐭𝐚𝐜𝐤 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠 Today I focused on understanding the core execution flow of Java — JDK, JRE, and JVM ☕💻 🔹 𝐓𝐨𝐩𝐢𝐜𝐬 𝐂𝐨𝐯𝐞𝐫𝐞𝐝 ▪ JDK, JRE, JVM ▪ Java First Application ▪ JVM internals & memory basics 🧪 𝐉𝐚𝐯𝐚 𝐄𝐱𝐞𝐜𝐮𝐭𝐢𝐨𝐧 𝐅𝐥𝐨𝐰 Test.java → javac Test.java → Test.class ➡ Executed using java Test ➡ Output: Hello, Java! 🎉 🛠 𝐉𝐃𝐊 (𝐉𝐚𝐯𝐚 𝐃𝐞𝐯𝐞𝐥𝐨𝐩𝐦𝐞𝐧𝐭 𝐊𝐢𝐭) • Used to develop & compile Java programs • Contains JRE + developer tools (javac, debugger) 📌 JDK = JRE + Dev Tools 🏠 𝐉𝐑𝐄 (𝐉𝐚𝐯𝐚 𝐑𝐮𝐧𝐭𝐢𝐦𝐞 𝐄𝐧𝐯𝐢𝐫𝐨𝐧𝐦𝐞𝐧𝐭) • Used to run Java programs • Contains JVM + core libraries • ❌ No compiler 📌 JRE = JVM + Libraries 🔥 𝐉𝐕𝐌 (𝐉𝐚𝐯𝐚 𝐕𝐢𝐫𝐭𝐮𝐚𝐥 𝐌𝐚𝐜𝐡𝐢𝐧𝐞) 🧠 Brain of Java • Loads & verifies .class files • Manages memory (Heap, Stack, Method Area) • Executes bytecode ⚙️ 𝐖𝐡𝐲 𝐉𝐚𝐯𝐚 𝐢𝐬 𝐇𝐲𝐛𝐫𝐢𝐝 ✔ Compiled → Bytecode ✔ Interpreted / JIT-compiled at runtime 👉 JVM does both interpreting & compiling 🍳 𝐊𝐢𝐭𝐜𝐡𝐞𝐧 𝐀𝐧𝐚𝐥𝐨𝐠𝐲 • JDK = Kitchen + tools + ingredients • JRE = Stove + utensils • JVM = Stove that actually heats the food 🔥 🎯 𝐊𝐞𝐲 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 JVM makes Java platform-independent, secure, and high-performance — that’s why Java is still a top industry language 🚀 #Java #JavaFullStack #JVM #JDK #JRE #LearningJourney #SoftwareEngineering #TechLearning
To view or add a comment, sign in
-
Java caches Integer objects. Not all of them. Just the ones between -128 and 127. You write a method to check for duplicate orders. Something simple that compares two order IDs with ==. Your tests pass because you're using stub data with small values like 1, 2, or 100. Every comparison works exactly as expected. Then it ships to production. Real order IDs are in the thousands. Suddenly your duplicate order detection stops working. Same code. Same logic. Completely different behavior. Why? Java caches small integers for performance. Loop counters, status codes, array indices all use small numbers constantly. Creating new objects every time would be wasteful. So Java caches from -128 to 127. Cross that threshold and == stops comparing values. It compares object references instead. Want to add more fun? The JVM flag -XX:AutoBoxCacheMax changes the upper bound. Your code works in dev where you set that flag, then breaks in production where you forgot to set it. Same code, different JVM settings, different behavior. The fix is simple and is probably taught in every Java 101 course around the world... use .equals() for object comparison. Always. No compile error. No runtime exception. Just silent logical bugs that only appear with certain values in certain environments. The kind of bug you debug once, then hopefully never make again. #Java #SoftwareEngineering #Coding #SoftwareDevelopment
To view or add a comment, sign in
-
-
How return Keyword Returns a Value in Java? We write it every day. We never question it. When a method is called in Java, JVM creates a Stack Frame for that method. This stack frame contains: Method parameters Local variables Return address Reference to previous stack frame Temporary space for return value Step-by-step Flow int result = add(2, 3); Step 1️⃣ Caller method stack frame already exists. Step 2️⃣ add(2,3) is called → JVM creates a new stack frame (callee). Step 3️⃣ Inside callee stack frame: Parameters: a = 2, b = 3 Local variables Return address (where to go back) Step 4️⃣ When return a + b; executes: The value 5 is placed in the callee’s return value slot Step 5️⃣ JVM copies that value to the caller’s variable result Step 6️⃣ Callee stack frame is destroyed Execution continues in caller method Gurugubelli Vijaya Kumar #Java #JVM #CallStack #StackFrame #ReturnKeyword #CoreJava #JavaInternals #JavaDeveloper #LearningJava #ProgrammingConcepts
To view or add a comment, sign in
-
-
Java☕ — Interface vs Abstract Class finally clicked 💡 For a long time, I used them randomly. If code compiled, I thought it was correct. Then I learned the real difference 👇 📝Interface = what a class CAN do 📝Abstract class = what a class IS #Java_Code interface Flyable { void fly(); } abstract class Bird { abstract void eat(); } A plane can fly — but it’s not a bird. That single thought cleared everything for me. Use interface when: ✅Multiple inheritance needed ✅Behavior matters ✅You’re defining a contract Use abstract class when: ✅You share base state ✅You provide common logic ✅Relationship is strong Understanding this saved me from messy designs. #Java #Interface #AbstractClass #OOP #LearningJava
To view or add a comment, sign in
-
Java☕ — Stream API💡 At first, streams felt confusing. Too many methods. Too much chaining. Then I understood this: A stream is just a data pipeline. #Java_Code list.stream() .filter(n -> n > 10) .map(n -> n * 2) .reduce(0, Integer::sum); The core idea is simple 👇 🔹 filter() → select data 🔹 map() → transform data 🔹 reduce() → combine data Once I thought in steps instead of syntax, streams became readable — not scary. Real lesson for me: Streams describe “what”, not “how”. #Java #StreamAPI #FunctionalProgramming #Java8
To view or add a comment, sign in
-
-
Java is getting cleaner. Are you using Records yet? For years, creating a simple Data Transfer Object (DTO) in Java meant writing a lot of boilerplate code: getters, toString(), equals(), and hashCode(). Even with Lombok, it’s an extra dependency. The Tip: If you are on Java 14+, start using Records for your DTOs. Before (Standard Class): public class UserDTO { private final String name; private final String email; // ... plus constructor, getters, equals, hashcode, toString... } After (Record): public record UserDTO(String name, String email) {} Why it matters: 1. Immutability: Records are immutable by default (safer code). 2. Conciseness: One line of code does the work of 50. 3. No Magic: It’s native Java—no external libraries required. Small changes like this make our codebases much easier to read and maintain. #Java #SpringBoot #CleanCode #SoftwareDevelopment #Tips
To view or add a comment, sign in
-
-
I agree, but let’s not oversell it. They’re final, immutable, can’t extend classes, and always include all components in equals/hashCode. Also, JPA/Hibernate support is still limited.
Senior Java Full Stack Developer | Java 17, Spring Boot, Microservices | AWS & Azure Cloud | React & Angular | Kafka & Event-Driven Architecture | Kubernetes & CI/CD | Available for C2C/C2H
Java is getting cleaner. Are you using Records yet? For years, creating a simple Data Transfer Object (DTO) in Java meant writing a lot of boilerplate code: getters, toString(), equals(), and hashCode(). Even with Lombok, it’s an extra dependency. The Tip: If you are on Java 14+, start using Records for your DTOs. Before (Standard Class): public class UserDTO { private final String name; private final String email; // ... plus constructor, getters, equals, hashcode, toString... } After (Record): public record UserDTO(String name, String email) {} Why it matters: 1. Immutability: Records are immutable by default (safer code). 2. Conciseness: One line of code does the work of 50. 3. No Magic: It’s native Java—no external libraries required. Small changes like this make our codebases much easier to read and maintain. #Java #SpringBoot #CleanCode #SoftwareDevelopment #Tips
To view or add a comment, sign in
-
-
Behind the scenes: How Java objects are created:- What happens step by step inside the JVM: The Java source code is compiled and .class files are generated. When the program runs, Animal.class and AnimalMain.class are loaded into the Method Area (Metaspace). A java.lang.Class object is created in the Heap, which holds runtime metadata of the class. JVM creates the main thread and its stack. When, new Animal() is executed: Memory is allocated in the Heap Area. All instance variables are initialized with default values (age = 0, legs = 0). The constructor is executed. A reference to the newly created object is returned. This reference is stored in the stack variable buzo. Note:- Heap → stores objects Stack → stores references and method frames Method Area / Metaspace → stores class metadata Important: ->The reference variable does not store the actual object or a memory address. ->HashCode is generated only when hashCode() is called, not during object creation. Learning Java internals makes concepts much clearer. #Java #JVM #CoreJava #ObjectOrientedProgramming #ComputerScience #objects
To view or add a comment, sign in
-
-
Most confusing fundamental concepts in Java: == vs equals(). Key Learnings: • == operator - Compares references for objects (memory location) - Compares values for primitives - For objects, it checks whether both references point to the same object • equals() method - Defined in Object class - Default behavior compares references - Many classes like String, Integer, wrapper classes, and collections override equals() to compare actual values/content • Why this matters - Two objects can be different in memory but still be logically equal - Example: new String("Java") == new String("Java") → false new String("Java").equals("Java") → true • Important rule - If a class overrides equals(), it should also override hashCode() - This is critical for correct behavior in HashMap and HashSet Final takeaway: Use == for primitive comparison. Use equals() for object content comparison. Always know which equals() implementation is being executed. Strong fundamentals make debugging easier and code more reliable. #Java #CoreJava #Equals #HashCode #Programming #SoftwareEngineering #LearningJourney #100DaysOfLearning
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development