You can figure out for yourself when a stack overflow occurs, if you know what the stack is.
The stack is a piece of memory that your program uses to store all the local variables in a method. Every time you call a method, Java adds a so called "stack frame" to the stack, this frame holds the local variables for the method you just called. When the method is finished, that frame is removed from the stack again, revealing the stack frame belonging to the calling method, so that method can resume execution.
The stack overflows when it has no more space to add the next stack frame. This happens when a method calls another method, and that method calls another method, etc; until there is no more memory. You will usually encounter this problem when you make a recursive method call.
In your first program, you can see that the main function calls doSomething(String) at line 12. This method in turn calls the main function, at line 34. This is a never ending loop, which keeps pushing frames on the stack, but the methods never get a chance to finish.