File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes main() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "main()" Watch "main()" New topic
Author

main()

cybel sheriden
Ranch Hand

Joined: Jan 18, 2005
Posts: 50
can main() be private.k&b says tht for the exam assume main() is public.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
try compiling this:


java amateur
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
Actually, that will compile. Try running that!


James Carman, President<br />Carman Consulting, Inc.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281

oops
i meant that
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Prior to Java 1.4, main was not required to be public.

This was reported as a bug in 1.2.2, then closed with the curious determination, "will not be fixed."

Ref: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4252539

Fortunately, it was fixed, and main (as an entry point) is now required to be public.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
I don't know that it's really that big of a deal if it's private, do you? It seems obvious that it should be public, though.
Surasak Leenapongpanit
Ranch Hand

Joined: May 10, 2002
Posts: 341

When I run this code on JVM1.4.2, it complains "Main method not public.".
[ March 11, 2005: Message edited by: Surasak Leenapongpanit ]
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
Originally posted by Surasak Leenapongpanit:

When I run this code on JVM1.4.2, it complains "Main method not public.".

[ March 11, 2005: Message edited by: Surasak Leenapongpanit ]


That's the point!
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by James Carman:
I don't know that it's really that big of a deal if it's private, do you? It seems obvious that it should be public, though.

Yes, it certainly makes sense that it's required to be public. But because it's an "entry method," it seems a bit on the fringe, so I don't know how big of a deal this might be.

In other words, the initial call to main is not coming from another object, or even a static method of another class. So in this special case, since we're telling to JVM to load the class and invoke main, might we even consider this a de facto call from within the same class?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: main()