wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes main method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "main method " Watch "main method " New topic
Author

main method

Tone Tucker
Greenhorn

Joined: Jan 11, 2013
Posts: 1
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

Joined: Oct 02, 2003
Posts: 11497
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Manu Somasekhar
Ranch Hand

Joined: May 22, 2012
Posts: 44
Both are correct.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4490
    
    8

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
Greenhorn

Joined: Nov 21, 2010
Posts: 28
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


SCJP 5.0 OCBCD 5.0(Formerly SCBCD)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: main method