by @kodeazy
Java what is command line arguments? how to resolve java.lang.ArrayIndexOutOfBoundsException Index 0 out of bounds for length 0
Command Line Arguments
are the arguments that are passed during the run time of java program.- These arguments helps to specify configuration information while launching our application.
-
Below is the sample example of
Command Line Arguments
.public class CommandLine { public static void main(String args[]){ System.out.println(args[0]); } }
-
After compiling and running the program with below commands
javac CommandLine.java java CommandLine
- Here we did not specify any argument while running the code and we are trying to access
args[0]
so we got the above error. -
we have to specify command line arguments while
running the program
as below.java CommandLine firstCommandLineArgument
Output:
firstCommandLineArgument
- we can specify
n
number of command line arguments.