Some Java fundamentals that I read recently. Yes a bit ashamed ( : ( ) of myself that I never really considered their differences apart from knowing that they both relates to a lack of memory. But essentially the cause of their problems are actually quite different! : O
OutOfMemoryError:
Thrown when Java is running out of memory and cannot allocate any more memory in the heap for the object
StackOverflowError:
The stack space lives at the top-end of the address space and the heap lives at the bottom-end of the address space. As stack grows, it grows downwards. As heap grows, it grows upwards. So there is a potential that the two can collide and when that happens, you get a
StackOverflowError thrown. Typically happens when you call some methods recursively (that keeps going-and-going).
(Really good explanation on StackOverflowError here:
http://stackoverflow.com/questions/214741/what-is-a-stack-overflow-error)