File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

main method

 
Tone Tucker
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have seen the main method in two forms and I know both work but which would be considered correct?

(a) public static void main(String args[] )

(b) public Static Void main (String[] args )


Thanks
Newbie
Tone...
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12020
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really, this has nothing to do specifically to the main method. Any array can be declared either way.

In general, the "String [] args" is preferred or more common, from my experience.
 
Manu Somasekhar
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both are correct.
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tone. Welcome to the Ranch!

Actually, not both are correct. Because you've got the capitalisation wrong of static and void in the second example - Java is case-sensitive, and so that won't compile. But I don't suppose that was what you were actually asking about .
 
Vijay Vishwa
Ranch Hand
Posts: 38
1
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the above 2 way mentioned is from screening test or any exam then the (b) is wrong as Matthew mentioned but (a) is correct

The preferred one is


Another way to declare from Java 5 onwards is

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic