aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Confused statement on main method in K&B's book? 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Confused statement on main method in K&B Watch "Confused statement on main method in K&B New topic
Author

Confused statement on main method in K&B's book?

Aaron Raja
Ranch Hand

Joined: Jun 07, 2007
Posts: 206
K&B's Book say
"Don�t forget that you can have a main() method with any legal
signature you like, but if it isn�t public static void main (String []
args), the JVM won�t be able to invoke it to start your program running."

That means
static public void main (String [] args)
JVM won�t be able to invoke it to start your program running
only
public static void main (String [] args)
but i tested both envoking and it work. Can anybody clearify me this? what K&B try to say please? I am confused!!!
[ August 07, 2007: Message edited by: Aaron Raja ]

Thanks, AR
SCWCD 5, SCJP 1.4, OCA (PL/SQL)
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

"public static" and "static public" are interchangeable -- they mean exactly the same. But if you left out "static" (for example) altogether, then the method couldn't be used to launch your application. And more commonly, your arguments have to be an array of Strings (which can be written many different equivalent ways: "String[] args", "String args[]", "String[] anyOtherVariableName", and even "String... args" in Java 5 and up). But if you make your arguments (for example), an array of ints like "main(int[] args)", then again, it isn't valid.


[Jess in Action][AskingGoodQuestions]
jibs parap
Ranch Hand

Joined: Dec 07, 2004
Posts: 134
What they meant to say was:

JVM can invoke only main() to start your programme running and the main() should have the following features:
1. it should have String[] as parameter
2. it should be public, static
3. it should return void

public static void main (String []args) is same as
static public void main (String []args)
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

The order of the modifiers "public" and "static" don't change the signature, so either will work.


"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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Confused statement on main method in K&B's book?