It's prefence. As long a you have an String array as the argument, it can have any name, and be "formatted" anyway.
public static void main(String[] args)
public static void main(String args[])
public static void main(String[] s)
public static void main(String s[])
All of those are perfectly legal. Actually as long as it's public, static, void, named main, and as a String[] as a parameter, This is even legal:
static public void main(String[] args)
So basicly it comes down to personal preference.
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
For good practice I think it's best to put the braces after the data type:
String[]
That will save some confusion and readability down the road.
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
There is no difference in Java (in other languages there may be).
Just be consistent in your use in order to avoid confusing people.
The second syntax is preferred by many people because it more accurately describes what Java does under the hood (in Java an array of whatever is actually an object of an array type) but the first more closely describes what the user of the array expects, which is to see an array of objects and is preferred by a considerable minority of people.
Sun themselves uses both in different publications :)
In the JLS James Gossling talks about String[] arr, in the Java coding style guidelines I find Object arr[].
In fact, in that same document the authors state explicitly that that is the preferred way (section 8.1.3).
http://www.sun.com/software/sundev/whitepapers/java-style.pdf
But I've seen both used in coding style guides for different projects (and there are other things in the Sun guidelines I don't agree with).
8.1.3 Array declarations
The brackets “[] in array declarations should immediately follow the array name, not the type. The exception
is for method return values, where there is no separate name; in this case the brackets immediately
follow the type:
char[] buf; // WRONG
char buf[]; // RIGHT
String[] getNames() { // RIGHT, method return value
There should never be a space before the opening bracket “[.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
Hi everyone,
wow java rocks! there's so much depth, yet alot of freedom!
Well said
Richard West
freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 25
Solved Threads: 10