This week's book giveaway is in the Testing forum.
We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

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

 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The order of the modifiers "public" and "static" don't change the signature, so either will work.
 
First, you drop a couch from the plane, THEN you surf it. Here, take this tiny ad with you:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic