User
Write something
Pass By Value With Reference Types
💡 Java Memory Tip: "Objects are passed by reference"... RIGHT? Wrong! A huge misconception in Java is how objects are passed to methods. Let's clear it up: Everything in Java is Pass-by-Value. Everything. When you pass an Object to a method, you are NOT passing the object itself. You are passing a copy of the reference (the memory address). 📺 Think of it like a TV and a remote control: The Object (the TV) lives in the Heap memory. Your variable in the Stack is just a remote control. When you pass it to a method, Java makes a photocopy of your remote. Now you have two remotes pointing to the SAME TV. If the method uses its remote to change the channel, your original remote will see the new channel too! Don't believe me? I've set up an interactive execution. Click the link, step through the code, and watch how the Stack and Heap interact in real-time 👇 🔗 Step through the memory visualizer here: > https://tinyurl.com/57wb886x
Pass-by-Value with Primitives
💡 Demystifying Java Memory: Pass-by-Value with Primitives One of the most common confusions when learning Java is understanding how variables are passed into methods. Here is the golden rule: In Java, EVERYTHING is passed by value. When dealing with primitive data types (like int, double, boolean), Java doesn't give the method the original variable. Instead, it creates a brand new box in the memory Stack and passes a photocopy of the value. 🤔 What does this mean? If you modify the variable inside the method, your original variable remains completely untouched. They live in different blocks of memory! I've set up a quick interactive example. Click the link below and use the "Forward" button to step through the execution. Watch closely how the Stack behaves when modifyCopy() is called! 🔗 Try the execution step-by-step here: > https://tinyurl.com/3zz7xfan
1
0
Small correction on "Reference Types and Objects Differences"
Great video. Really helpful explanation overall. Just a small technical correction: in the diagram it looks like object fields (like x and y) are stored in the stack inside a “frame for the object”, but in Java those fields actually live in the heap as part of the object itself. The stack only stores method frames and references to objects. Also, stack frames are created per method call (such as main) and are removed when the method finishes, they are not created per object. Might be worth clarifying this to avoid confusion, but the rest of the explanation is very good 👍 I'll add an image to show the correct visualization of the stack, heap, and string pool.
Small correction on "Reference Types and Objects Differences"
Welcome Post
Hello I am Refaat Ibrahim oracle certified - database developer with DBA Tasks I am really happy to join my Bro. Amigos Academy to become full stack developer inshaAllah It would be my pleasure to develop together in realistic projects and share ideas. Regards
Tajikistan ba pesh
Apparently I am the first tajik here. I love this academy
1-8 of 8
Amigoscode
skool.com/amigoscode
A free learning community led by Nelson Djalo. Master Programming & AI, get updates, and grow in a fast-moving industry.
Leaderboard (30-day)
Powered by