1
JavaIntermediate#gc#memory
Stack stores method frames, local variables, and references — fast, thread-local, LIFO. Heap stores all objects and class instances — shared across threads, managed by the garbage collector. The JVM also has Metaspace for class metadata.
void method() {
int x = 5; // stack
Person p = new Person(); // reference on stack, object on heap
}