Java – Correct syntax for main method

java

This is a total beginners question. I am new to java and have been browsing StackOverflow and CodeReview. I am finding these two different formats being used:

example 1:

public static void main(String args[])

or
example 2:

public static void main(String[] args)

This is what I have in my course notes:

These words are called modifiers. The main() method is also preceded by the word void to indicate that it does not return any value. Also the main() method always has a list of command line arguments that can be passed to the program

main(String[] args)

which we are going to ignore for now.

So, as you can see, we have been told to ignore this for now, but I'd like to know:

Is there an actual difference between these, if so, what?

Best Answer

From the Java Language Specification:

The [] may appear as part of the type at the beginning of the declaration, or as part of the declarator for a particular variable, or both.

For example:

byte[] rowvector, colvector, matrix[];

This declaration is equivalent to:

byte rowvector[], colvector[], matrix[][];
Related Topic