File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "main method " Watch "main method " New topic

main method

Tone Tucker

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 )

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11957

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

Joined: Apr 06, 2010
Posts: 4544

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

Joined: Nov 21, 2010
Posts: 32
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:
subject: main method
It's not a secret anymore!