One more point regarding Command line arguments,
If Command line arguments are not provided then empty
String array is created. If we try to access the arguments of this String array or try to modify any argument then
array index out of bound exception exception will occur.
e.g. The following code is from one of the
SCJP question
Case 1: No command line arguments are provided
In this case, assigning null value to String array reference like
will work fine, but if any argument is initialized like
then array
index out of bound exception will occur, this is because we are initializing the arguments of empty array.
Case 2: Command line arguments are provided
In this case, if we provided command line arguments, then the no. of arguments which are provided, those many arguments can be only re-initialized
e.g. If command line arguments = 2
"Arg1" "Arg2"
Then following code will work,
args[0] = "test";
args[1] = "test";
The out will be the overriden values
If no. arguments provided are less than re-initialized size then also
index out of bound exception will occur.