File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Aaron Raja
Ranch Hand
Posts: 206
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
jibs parap
Ranch Hand
Posts: 134
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The order of the modifiers "public" and "static" don't change the signature, so either will work.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic