Thursday, February 11, 2016

Java : "String[] args" arguement in Main Method



public static void main(String [] args)

Those are for command-line arguments in Java.
In other words, if you run
java MyProgram one two
Then args contains:
[ "one", "two" ]
public static void main(String [] args) {
   String one = args[0]; //=="one"
   String two = args[1]; //=="two"
}
The reason for this is to configure your application to run a particular way or provide it with some piece of information it needs.

No comments:

Post a Comment