This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes StackOverflowError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "StackOverflowError" Watch "StackOverflowError" New topic
Author

StackOverflowError

Janki Shah
Ranch Hand

Joined: Nov 23, 2011
Posts: 136
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575


is same as


so, every recursive call a stack object created by jvm endlessly, hence that error.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4425
    
    8

Or to put it another way: every time you create a Test1, that creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1...
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Matthew Brown wrote:which creates a new Test1...

Yes, at last no instances are created *fully*/consistenly
Janki Shah
Ranch Hand

Joined: Nov 23, 2011
Posts: 136
Thank you Seetharaman and Matthew. So, in this case #2 will cause a Test1 class to load and while loading it will create another class instance at #1 and while loading that instance it will load another class instance at #1 and so on... Is this where the recursion happening?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

when you say java x.y.z.ClasstoRun then Jvm load that class and search for a main method...and then creating instance etc.. got the difference?
Janki Shah
Ranch Hand

Joined: Nov 23, 2011
Posts: 136
So, in this case, when jvm load the class what line will be executed first #1 or #2 (from main method)?
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

#2
then
#1
#1
#1

...

ad infinitum (well, until Stack overflows)

WP
Janki Shah
Ranch Hand

Joined: Nov 23, 2011
Posts: 136
Understood the point. Thank you William.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: StackOverflowError