Java Basics - Interview Questions and Answers
What if I write static public void instead of public static void?
Program compiles and runs properly.
What if I do not provide the String array as the argument to the method?
Program compiles but throws a runtime error "NoSuchMethodError".
What is the first argument of the String array in main() method?
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.
If I do not provide any arguments on the command line, then the String array of main() method will be empty or null?
It is empty. But not null.
How can one prove that the array is not null but empty using one line of code?
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.
What environment variables do I need to set on my machine in order to be able to run Java programs?
CLASSPATH and PATH are the two variables.