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 why should always write public static void main( ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why should always write public static void main( )" Watch "why should always write public static void main( )" New topic
Author

why should always write public static void main( )

mohan gavande
Ranch Hand

Joined: Oct 07, 2004
Posts: 39
Why Should always write in program as
public static void main()

public means access by every class even it is out of package
static means call that class before making object
void u know very well
main should be write from where program is actually starting
Mahesh Bhatt
Ranch Hand

Joined: Sep 15, 2004
Posts: 88
That is right mohan,

You have all the reasons right there, if that is the main method we are talking about, then the parameter list is missing (String args[]) this is to pass some parameters at the time of running the program, also note that you can also have overloaded main methods in your class however the "public static void main(String args[]){} will be the one that will be called when you run your program.

Hope it clears all the things.


Impossible is I M Possible
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
The presence of the main method means you can start the class from the command line. If you have a system of many classes you need at least one that can be started this way. All the other classes don't really need a main method.

I used to put a main on a lot of classes that didn't really require one and put some tests in there. Call a few methods, check the results. You may still see some main methods just for testing. But nowadays I've switched to doing that kind of thing from JUnit tests instead.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why should always write public static void main( )
 
Similar Threads
Public static void main()
a strange question
main argument
inner class very confusing
methods in methods