Why we use (String [] args) in main method of Java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why we use (String [] args) in main method of Java?

Is it necessary to keep it as parameters of main method?

2nd Oct 2019, 2:40 AM
Sanjaya Acharya
Sanjaya Acharya - avatar
4 Answers
+ 5
As long as you provide a string array, the name doesn't really matter.
2nd Oct 2019, 4:00 AM
Sonic
Sonic - avatar
+ 3
It stores Java command line arguments and is an array of type String. Here, the name of the String array is “args” but it is not fixed and user can use any name in place of it
2nd Oct 2019, 3:36 AM
Wardy Spirit
Wardy Spirit - avatar
+ 3
I also wonder why is that compulsory. Not every java program is going to be run from command line. So why we need to pass String array . String array parameter might be helpful but making it compulsory don't make sense. Passing String array to main is the thing that I forget the most.(I'm beginner of java) I would like to hear why is that *Compulsory*
2nd Oct 2019, 6:51 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
0
It's used it for work with string values
3rd Oct 2019, 5:03 PM
Islombek
Islombek - avatar