Java Basics - Interview Questions and Answers


  1. How many objects are created in the following piece of code?
    MyClass c1, c2, c3;
    c1 = new MyClass ();
    c3 = new MyClass ();
    Only 2 objects are created, c1 and c3. The reference c2 is only declared and not initialized.
  2. Can a public class MyClass be defined in a source file named YourClass.java?
    No. The source file name, if it contains a public class, must be the same as the public class name itself with a .java extension.
  3. Can main() method be declared final?
    Yes, the main() method can be declared final, in addition to being public static.
  4. What is HashMap and Map?
    Map is an Interface and Hashmap is the class that implements Map.
  5. Difference between HashMap and HashTable?

    The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls. (HashMap allows null values as key and value whereas Hashtable doesnt allow).

    HashMap does not guarantee that the order of the map will remain constant over time. HashMap is unsynchronized and Hashtable is synchronized.

  6. Difference between Vector and ArrayList?
    Vector is synchronized whereas arraylist is not.

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

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