Java Basics - Interview Questions and Answers

  1. What if I write static public void instead of public static void?
    Program compiles and runs properly.
  2. What if I do not provide the String array as the argument to the method?
    Program compiles but throws a runtime error "NoSuchMethodError".
  3. 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.
  4. 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.
  5. 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.
  6. 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.

« Prev   [ Page 3 of 17  Jump... Next »

Jump to page : 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |