jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes main method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "main method" Watch "main method" New topic

main method

shandilya popuru
Ranch Hand

Joined: Dec 21, 2004
Posts: 95
hi everyone

though main method is said to be declared public it works fine without it
what is the reason n why it shoud be decld public

Ed Lance
Ranch Hand

Joined: Aug 02, 2000
Posts: 38
Not sure what you mean about "works fine". My guess is it COMPILES fine but with out the correct signature it is not the entry point to your program. Double check to make sure you aren't really running your previously compiled file.

Another example is that I can have the following main method:
public static void Main(String[] args){
...but again it's not the entry point for my application.
Natesh Kurup

Joined: Nov 23, 2004
Posts: 19
The entry point into the program has to be

The code would compile perfectly if it has not been declared public but wont run. Check whether an existing program with same name exists in the classpath


Mani Ram
Ranch Hand

Joined: Mar 11, 2002
Posts: 1140
There is some inconsistency between the Java versions in the way they treat the non-public main methods.
If I remember correctly, non-public main methods will work fine in 1.3 & 1.2.2, but not in other versions.
With version 1.4.1, it gives Runtime error "Main method not public"
Which version are you using?

Quaerendo Invenietis
I agree. Here's the link: http://aspose.com/file-tools
subject: main method
It's not a secret anymore!