Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is StackOverflowError in Java ? When it occurs? [closed]

Can anybody tell me what is StackOverflowError in Java ?

like image 356
Puru Avatar asked Jun 17 '10 11:06

Puru


1 Answers

A stack overflow occurs when too much data is put on the stack, which is a limited resource.

Here's an example:

public class Overflow {
    public static final void main(String[] args) {
        main(args);
    }
}

That function calls itself repeatedly with no termination condition. Consequently, the stack fills up because each call has to push a return address on the stack, but the return addresses are never popped off the stack because the function never returns, it just keeps calling itself.

like image 192
T.J. Crowder Avatar answered Oct 04 '22 20:10

T.J. Crowder