After understanding how Java code gets executed, the next question is: Where does the data actually get stored? In JVM, memory is mainly divided into two parts: Heap Memory: - Used to store objects and class instances - Shared across all threads - Managed by Garbage Collection - Objects generally have a longer lifetime Stack Memory: - Stores method calls and local variables - Each thread has its own stack - Automatically managed - Data exists only during method execution Key difference: Heap → Stores Objects Stack → Handles Execution (methods & variables) Understanding this difference helps in writing better and more efficient Java applications. #Java #JVM #BackendDevelopment #Learning
Java JVM Memory: Heap vs Stack
More Relevant Posts
-
#Day02 After understanding how Java code gets executed, the next question is: 👉 Where does the data actually get stored? In JVM, memory is mainly divided into two parts: 🔹 Heap Memory • Used to store objects and class instances • Shared across all threads • Managed by Garbage Collection • Objects generally have longer lifetime 🔹 Stack Memory • Stores method calls and local variables • Each thread has its own stack • Automatically managed • Data exists only during method execution 📌 Key difference: Heap → Stores Objects Stack → Handles Execution (methods & variables) Understanding this difference helps in writing better and more efficient Java applications. #Java #JVM #BackendDevelopment #Learning
To view or add a comment, sign in
-
-
Day 46-What I Learned In a Day(JAVA) Today I explored the execution of a Java program and understood how it works inside the JVM: JVM Memory Structure: • Method Area Stores class-level data like methods, static variables, and metadata • Class (Static) Area Holds static variables and static initializers • Stack Area Manages method calls, local variables, and execution flow • Heap Area Stores objects and instance variables Execution Order of Java Program: 1️⃣ Class is loaded into Method Area 2️⃣ Static variables & static initializers are executed (Class Area) 3️⃣ Main method is pushed into Stack Area 4️⃣ Objects are created in Heap Area (if any) 5️⃣ Methods execute using Stack (LIFO order) Program Components: • Methods -Define program behavior • Variables -Store data (local, instance, static) • Static Initializers -Execute once when the class loads #Java #JVM #Programming #LearningJourney #CoreJava #TechSkills
To view or add a comment, sign in
-
-
Day 52 – Deep Dive into Static Concepts in Java ☕ Today I revised static concepts with a focus on understanding their internal behavior and execution flow. Topics covered: 🔹 Order of execution (static blocks, static variables, and methods) 🔹 Why static members are called class members 🔹 Difference between class members and instance (object) members 🔹 How static variables are shared across all objects 🔹 Why static members can be accessed without creating objects 🔹 Why instance variables cannot be accessed directly in static context Revisiting these concepts helped me understand how Java manages memory and execution at the class level. Strengthening my core understanding of Java internals step by step 🚀 #Day52 #JavaJourney #Static #CoreJava #OOP #Consistency
To view or add a comment, sign in
-
📖 New Post: Java Memory Model Demystified: Stack vs. Heap Where do your variables live? We explain the Stack, the Heap, and the Garbage Collector in simple terms. #java #jvm #memorymanagement
To view or add a comment, sign in
-
Day 33/100 — Threads & Multithreading ⚡ Java can do multiple things at the same time using threads. Thread lifecycle: NEW → RUNNABLE → RUNNING → WAITING → TERMINATED 2 ways to create threads: // Method 1: extend Thread class MyThread extends Thread { public void run() { println("Running!"); } } new MyThread().start(); // NOT run()! // Method 2: Runnable lambda (preferred!) Thread t = new Thread(() -> println("Lambda thread!")); t.start(); Most important rule: ALWAYS call start() — NOT run()! → run() = normal method call (same thread) → start() = creates new thread and calls run() 3 things to remember: → Prefer Runnable over extending Thread → start() not run() → Multiple threads = race conditions possible! 🎯 Challenge: Create 3 threads that each print their name 5 times. Observe the interleaved output! #Java #Threads #Multithreading #CoreJava #100DaysOfJava #100DaysOfCode
To view or add a comment, sign in
-
-
🧬 Java Collections – Understanding List vs Set vs Map Yesterday I focused on building a deeper understanding of core Java Collection types and their practical usage. ✔️ List – Maintains order and allows duplicates ✔️ Set – Ensures uniqueness (no duplicate elements) ✔️ Map – Stores data in key–value pairs for efficient lookup Understanding these differences is essential for selecting the right data structure based on the problem context. 💡 Hands-on Practice: • Implemented frequency counting using Map • Identified unique elements using Set These exercises helped reinforce how theoretical concepts translate into real problem-solving scenarios. ⌨️ Additionally, continued daily typing practice to improve speed and accuracy. Consistent practice and clarity in fundamentals are key to writing efficient and scalable code. #Java #Collections #DataStructures #DSA #BackendDevelopment #SoftwareEngineering #LearningInPublic
To view or add a comment, sign in
-
Day 36/100 – Working with ArrayList in Java 📚 Today I practiced using ArrayList in Java, a dynamic array that allows flexible storage and manipulation of data. Unlike normal arrays, ArrayList can grow and shrink dynamically, making it very useful in real-world applications. Key learnings: • Adding elements using add() • Storing multiple values dynamically • Finding size using size() • Easier and more flexible than traditional arrays Understanding collections like ArrayList is important for handling data efficiently in Java. Building strong fundamentals step by step. 🚀 #100DaysOfCode #Java #ArrayList #DataStructures #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
-
Java Architecture Explained: JDK, JRE & JVM 🚀 Want to truly understand how Java works behind the scenes? Start here 👇 🔹 JDK (Java Development Kit) The complete toolkit to build Java applications Includes compiler (javac), debugger, and JRE 👉 Without JDK, you can’t develop Java programs 🔹 JRE (Java Runtime Environment) Provides the environment to run Java programs Includes JVM + standard libraries 👉 Without JRE, you can’t run Java programs 🔹 JVM (Java Virtual Machine) The core engine that executes Java bytecode Handles memory (Garbage Collection) and converts bytecode → machine code 👉 This is what makes Java platform-independent The compilation flow: 📄 .java → [javac] → 📦 .class → [JVM] → 💻 Runs on any OS 🧠 Behind the scenes (important 👇) ✔ Bytecode is platform-independent ✔ JVM is platform-specific ✔ JIT compiler improves performance ✔ Garbage Collector manages memory automatically 🎯 Simple way to remember: JDK = Develop JRE = Run JVM = Execute ✨ That’s the power of Java: Write Once, Run Anywhere 😏 Python is easy to write Java is hard to break😂 #Java #JDK #JRE #JVM #Programming #BackendDevelopment #FullStackDeveloper #TechExplained
To view or add a comment, sign in
-
-
☕ Most developers use Java every day, but many still don’t know what actually happens inside the JVM. When you run a Java program, it doesn’t execute your ".java" file directly. Here’s the real flow: 1️⃣ Source Code (".java") 2️⃣ "javac" converts code into Bytecode (".class") 3️⃣ Class Loader loads classes into memory 4️⃣ JVM creates Runtime Memory Areas ✔ Heap ✔ Stack ✔ Method Area ✔ PC Register 5️⃣ Execution Engine runs the program using: ✔ Interpreter ✔ JIT Compiler ✔ Garbage Collector 💡 Why this matters: ✅ Better debugging ✅ Better performance tuning ✅ Better memory management ✅ Stronger Java fundamentals Most developers learn Java syntax. Smart developers learn how Java works internally. 🚀 Let’s connect and share experiences. #Java #JVM #JavaDeveloper #BackendDevelopment #Programming #Coding #SoftwareEngineer #Tech #SpringBoot
To view or add a comment, sign in
-
-
🧠 Most Java developers use memory every day — but do they really understand how it works internally? Here are 3 things that surprised me about Java Memory Management: 🔹 It's the OS that creates threads and allocates Stack & Heap memory — NOT the JVM. JVM just manages it! 🔹 Every method call creates a Stack Frame — and it gets automatically destroyed after execution. This is why local variables don't exist outside their method! 🔹 Garbage Collection uses Mark & Sweep — it first marks all referenced objects, then sweeps away everything else. Fully automatic! Understanding this deeply will: ✅ Make you write better Java code ✅ Help you debug memory issues faster ✅ Give you an edge in Java interviews I just published a complete visual explanation of Java Memory Management covering: → Stack vs Heap Memory → JVM Internals → String Constant Pool (SCP) → Stack Frames & Method Execution → Garbage Collection & Mark and Sweep Full video link in the comments 👇 #Java #JavaDeveloper #JavaProgramming #JVM #MemoryManagement #GarbageCollection #StackVsHeap #LearnJava #SoftwareDevelopment #CodeOpsTrek #JavaTutorial #Programming #SystemDesign #SoftwareEngineering #DevOps
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
Nice breakdown 👍 From performance side, this becomes super important when dealing with GC. Too many object allocations in heap can really slow things down, while stack usage is usually more predictable.