+ 4

[DUPLICATE] String args [ ] or String [ ] args

In Java, When declaring main method, Sometimes we code : public static void main (String[ ] args) and other times : public static void main (String args[ ] ) Is there any difference between them? because result will be the same in Hello World Program. (I am novice in Java). And what if we code : public static void main (String[ ] args [ ] ) Any Explanation?

2nd Feb 2018, 4:23 PM
Uttam
Uttam - avatar
6 Answers
+ 4
There's no difference. You can use any and the result won't change. That is because that is an argument in the main method, an array of strings, soon in the course you will learn that, you can declare arrays in two ways string arr[1] string[1] arr
2nd Feb 2018, 4:29 PM
voidneo
+ 5
These are the declaration syntax if array.. Arrays can be declared in many ways... they are: String [ ]args ;recommended way. String args[ ] ; String ... args;(opertor... called ellipse opertor). but String[] args[] is the 2D array. (not valid argument in for main() method) but first 3 are valid arguments for main method.
2nd Feb 2018, 5:02 PM
Harsh Namdev
Harsh Namdev - avatar
+ 3
args doesn't have to be empty there can be passed something from command line when you start your program
2nd Feb 2018, 5:29 PM
michal
+ 2
Thank you @noname.
2nd Feb 2018, 4:42 PM
Uttam
Uttam - avatar
+ 1
@noname so does my program declare an empty array of strings?
2nd Feb 2018, 4:31 PM
Uttam
Uttam - avatar
+ 1
Not exactly your program, we all are taught to declare it on the main method, and I suppose it's got its purpose, but I don't know what is it, sorry
2nd Feb 2018, 4:41 PM
voidneo