[DUPLICATE] Why do we need to include "String[ ] args" in the main function all the time ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

[DUPLICATE] Why do we need to include "String[ ] args" in the main function all the time ?

27th Aug 2016, 1:41 PM
M Shalem Raju
M Shalem Raju - avatar
2 Answers
+ 3
you need them to pass parameters to the program. In other words args are for command-line arguments. suppose you create a program called isEqual that needs two commad line arguments. if you run isEqual program and supply two parameters as below: java isEqual 5 9 Then args [0] 》 5 args [1] 》 9 Example to print all command-line parameters public class Program { public static void main(String[] args) { for(int i = 0; i < args.length; i++) { System.out.println(args[i]); } } }
28th Aug 2016, 3:17 AM
Tiger
Tiger - avatar
- 1
This makes jvm to underatand calling right method when program has run
27th Aug 2016, 6:09 PM
Mahender
Mahender - avatar