| Author |
Where to use of the "main" method
|
william christensen
Greenhorn
Joined: Oct 14, 2005
Posts: 7
|
|
Hello Does there need to be a "main (...)" method declared in at least one class that is in a package? If so, does the class holding the "main(...)" method need to be in a class whose name is the same as the package name? Can you enlighten me on the proper use of naming and lauching packages. Many thanks William
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24054
|
|
An application needs to have a main() for Java to be able to launch it. If main() is in a class that's in a package other than the default, it needs to be in a public class. The signature of main() must be public static void main(String[] args) That's it. There are no other rules. It is never the case that a class name needs to be the same as a package name, for any reason; in fact, it's always a bad idea to name a class this way.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Akshay Kiran
Ranch Hand
Joined: Aug 18, 2005
Posts: 220
|
|
package files need not have a main at all but if you want to use the "java" command on a class, it should have a main method that is in a class and the file containing it must have the same name as this class. it need not be public, but in that case, no other class in the file should be public. don't get confused, make a start somewhere and start exploring, a good place to ask such questions is the SCJP forum, you'll get replies with a lot of insights from beginners and experts
|
"It's not enough that we do our best; sometimes we have to do<br />what's required."<br /> <br />-- Sir Winston Churchill
|
 |
 |
|
|
subject: Where to use of the "main" method
|
|
|