Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

error in code

Thread view: 
chandu - 21 Dec 2005 14:02 GMT
hai
i am getting run time excepton  Stack overflow exceptin in mai n thread
for below code
class a{
           a a1=new a();
           void f(){}
    }
class my{
             public static void main(String aa[]){
                                                      a a2=new a();
                                                      a a3=new a();
                                                               }
}

and if i do not create any object of a in main or i keep stmt a a1=new
a();in f() erro r not coming.can u please tell me reason.y cont i
instantiate a class with in the same class.are there any issues..
Haider Albassam - 21 Dec 2005 14:21 GMT
This is because when you instantiate an object a2 in main, it will
instantiate the object a1 *before* calling the constructor, and because
a1 has it's own a1 you will never execute the constructor, and this
loop will overflow the stack. Still, you can use object a1 inside the
class (a) but without instantiate it.
Cheers,

Haider
chandu - 22 Dec 2005 08:32 GMT
hai thanx for your solution..and i want to ask you one more question
..why cont java support main functions without string
parameteres(command liine arguments)  like in other languages
c,c++...and suggest me any site or book which hav advanced topics of
core javA
Andrew Thompson - 22 Dec 2005 09:41 GMT
> hai thanx for your solution..and i want to ask you one more question
> ...why cont java support main functions without string
> parameteres(command liine arguments)  

The main(String[] args) method is *the* method called as the
entry point to a Java program, but the length of args[] can be
0 - no parameters.

Also, rather confusingly, you can have a main() method in
your applicaton, just it is not *the* 'main' method.  It
will *not* be called by default by the VM.

HTH

Signature

Andrew Thompson
physci, javasaver, 1point1c, lensescapes - athompson.info/andrew

Malte Christensen - 22 Dec 2005 09:59 GMT
> hai thanx for your solution..and i want to ask you one more question
> ..why cont java support main functions without string
> parameteres(command liine arguments)  like in other languages
> c,c++...and suggest me any site or book which hav advanced topics of
> core javA

Start here:

http://java.sun.com/docs/books/tutorial/index.html
Malte Christensen - 21 Dec 2005 14:24 GMT
> hai
> i am getting run time excepton  Stack overflow exceptin in mai n thread
[quoted text clipped - 13 lines]
> a();in f() erro r not coming.can u please tell me reason.y cont i
> instantiate a class with in the same class.are there any issues..

Looks to me as if you keep spawning instances of class a. Why would you
do this?
Alan Krueger - 21 Dec 2005 18:47 GMT
>> hai
>> i am getting run time excepton  Stack overflow exceptin in mai n thread
>> for below code
[...]

> Looks to me as if you keep spawning instances of class a. Why would you
> do this?

A lame distributed denial-of-service attack?  I suspect there were a few
that plugged the program into a Java IDE, compiled it, and ran it to see
what would happen.
Monique Y. Mudama - 21 Dec 2005 17:19 GMT
> hai
> i am getting run time excepton  Stack overflow exceptin in mai n thread
[quoted text clipped - 13 lines]
> a();in f() erro r not coming.can u please tell me reason.y cont i
> instantiate a class with in the same class.are there any issues..

Even in such short code, it's a good idea to stick to java naming
conventions.

Specifically, class A and class My (horribly named as they are) are at
least obviously classes because of the capitalization.  Lowercase
classes are jarring (no pun intended).

Signature

monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.