I've used three types of notation while passing argument to main
method in java.
public static void main(String[] args)
public static void main(String args[])
public static void main(String... args)
Can anyone tell me the difference between above? Someone has used terms packed and non-packed data for explanation of first two, what are they, and is it related to these?
I think first two is somewhat related to coding convention. Am I right?

- 1,890
- 21
- 34
-
When it comes down to it there is no true difference. – 3kings Nov 29 '15 at 05:25
-
No difference...All start the main thread' – Ruchir Baronia Nov 29 '15 at 05:27
-
Downvoters, please comment the reason for downvoting. – Kamal Nayan Nov 29 '15 at 05:45
2 Answers
There is no actual difference, the variants are due to the different ways you can define an array in java syntax.
The standard way to define and array
String[] args
C/C++ style exist from historical reasons
String args[]
Varargs style (When do you use varargs in Java?)
String… args
All will compile to the same bytecode. I would stick with
public static void main(String[] args)

- 1
- 1

- 11,508
- 6
- 44
- 70
First two are same.
Infact all three are same at base. But the third kind is called as varargs
and has a special purpose which is that it can be used as an optional parameter in methods. For example if you have a method that requires parameters int x, String... y
then even you call the parameter without passing String... y
as parameter argument, the code will compile. More information here: Methods, Optional Parameters and/or Accepting multiple Data Types
Also check this: Java varags method param list vs. array

- 1
- 1

- 2,034
- 3
- 17
- 33