If MyProg.java were compiled as an application and then run from the command line as:
java MyProg I like tests
what would be the value of args[ 1 ]
inside the main( )
method?
- MyProg
- "I"
- "like"
- 3
- 4
- null until a value is assigned
If MyProg.java were compiled as an application and then run from the command line as:
java MyProg I like tests
what would be the value of args[ 1 ]
inside the main( )
method?
Arguments come in as an array, which are 0-based.
java myProgram a b c
means
args[0] == 'a'
args[1] == 'b'
args[2] == 'c'
It'd be a String
, "like
". The class file being run isn't included in the arguments array.
class CommandLine
{
public static void main(String args[])
{
System.out.println(args[0]);
System.out.println(args[1]);
}
}
For Running : java CommandLine aaa bbb
Output -
aaa
bbb
Here aaa is treated as first and bbb is treated as second argument for command line.