File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Joined: Jan 11, 2013
Jan 11, 2013 14:05:26
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(
(b) public Static Void main (String args )
Joined: Oct 02, 2003
Jan 11, 2013 14:44:08
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
Joined: May 22, 2012
Jan 12, 2013 00:20:07
Both are correct.
Joined: Apr 06, 2010
Jan 12, 2013 03:56:11
Hi Tone. Welcome to the Ranch!
Actually, not both are correct. Because you've got the capitalisation wrong of
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
Joined: Nov 21, 2010
Jan 12, 2013 07:37:12
If the above 2 way mentioned is from screening
or any exam then the (b) is wrong as Matthew mentioned but (a) is correct
The preferred one is
public static void main(String args)
Another way to declare from Java 5 onwards is
public static void main(String... args)
SCJP 5.0 OCBCD 5.0(Formerly SCBCD)
I agree. Here's the link:
subject: main method
JAVAC not found ??? I cant compile - help
problems running code
Static Variable Problem
none applicable in Eclipse IDE
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014