r/javahelp • • 9d ago

Java Beginner – Struggling with OOP and Understanding Stack and Heap

Hi everyone!
I’ve been learning Java for a few weeks now, and I’m starting to get into OOP. However, I’m finding it difficult to fully understand some of the core concepts, especially how objects work and the difference between the stack and heap memory.
I don’t want to just memorize definitions. I want to actually understand what’s happening behind the scenes and how everything connects.
For those of you who have been through the same learning process:
What helped you understand OOP?
How did you learn the difference between stack and heap?
Are there any resources, exercises, or learning methods you would recommend?
I’d really appreciate any advice from more experienced Java developers.

14 Upvotes

15 comments sorted by

View all comments

1

u/Duck_Devs 9d ago

The stack is a very restrictive segment of memory. Local variables are the only things that are stored there. While your variables can include object references, the actual object data is stored on the heap. Along with objects, the heap also stores arrays, as well as any primitive values or object references held by objects and arrays.

There also exists “off-heap memory”, but that’s not something a beginner should worry much about.