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 The method main must be declared public, static, and void. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "The method main must be declared public, static, and void." Watch "The method main must be declared public, static, and void." New topic
Author

The method main must be declared public, static, and void.

Siva kandasamy
Ranch Hand

Joined: Dec 31, 2002
Posts: 139
Hi there,
As per the JLS,
The method main must be declared public, static, and void.
See the code below at "<===", it do not have the key word public,
but it works. I am little confused.
thanks
siva
x38020

Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Most cultures have laws against stealing. In theory, if you steal a loaf of bread, you get sent to jail. But in practice, you may or may not get caught, yes?
Same here. The rule says it must be public. Some JVMs might catch you if you violate this rule. Others, however, won't. Sun's won't.


[Jess in Action][AskingGoodQuestions]
Siva kandasamy
Ranch Hand

Joined: Dec 31, 2002
Posts: 139
Thanks. Got it.
thanks
siva
x38020
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Hi Sivanantham
From JDK 1.4 onwards not using public for the main method is wrong.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: The method main must be declared public, static, and void.