What is the difference between stack and heap memory?

What is the difference between stack and heap memory?

Approach: Compare allocation speed and lifetime.

Stack is used for static memory allocation and local variables, managed automatically (LIFO). Heap is used for dynamic memory allocation, managed manually or by garbage collection.

Follow-up: Which one causes a StackOverflowError?

Key concepts: static allocation, dynamic allocation, scope.