Set - 9

Question 21 :

What if I write static public void instead of public static void?

Answer :

Program compiles and runs properly.

Question 22 :

What if I do not provide the String array as the argument to the method?

Answer :

Program compiles but throws a runtime error "NoSuchMethodError".

Question 23 :

What is the first argument of the String array in main method?

Answer :

The String array is empty. It does not have any element. This is unlike C/C++ where the first element by default is the program name.

Question 24 :

If I do not provide any arguments on the command line, then the String array of Main method will be empty or null?

Answer :

It is empty. But not null.

Question 25 :

How can one prove that the array is not null but empty using one line of code?

Answer :

Print args.length. It will print 0. That means it is empty. But if it would have been null then it would have thrown a NullPointerException on attempting to print args.length.