Java coding confusion about String args [] and String [] args

I am new to Java programming, and I am confused in the following two statements:

public static void main(String args[]) 

and

 public static void main(String[] args) 
They are the same? If not, how do they differ from each other?
+4
source share
6 answers

There is no semantic difference between the two forms, the only difference is stylistics.

+5
source

They mean the same thing. The second form is usually preferred because it declares an array declaration with a type declaration. By the way, there is nothing special in this main () method, arrays can be declared as anywhere in your code.

+3
source

While this is true for single statements, the difference is that you define more than one variable:

 String[] foo1, foo2; // both variables are of type String[] String bar1[], bar2; // here they're not. But you really shouldn't do this, causes // unnecessary confusion 
+3
source

Yes, they are the same, but the convention is to write String[] args , since String[] is a type.

+1
source

Both have exactly the same meaning. However, the former is unconventional and should not be used as it breaks down type information. This is a hold on C.

+1
source

It is also basically the same as

 public static void main(String... args) 

which i prefer.

+1
source

Source: https://habr.com/ru/post/1387588/


All Articles