+3

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

8/27/2016 1:41:57 PM

M Shalem Raju

2 Answers

New Answer

+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]); } } }

-1

This makes jvm to underatand calling right method when program has run