Interview Questions 1 - 10  «Prev Next»

Java Collections Class, Map Interface

  1. In the Collections Class, what is the difference between Sorted Set and Sorted Map?

    Answer:
    1. Map: A map from keys to at most one value each. (map does not extend Collection)
    2. SortedMap: A map whose keys are sorted (extends Map)

  2. What is an Anonymous Inner Class?

    Answer:
    When a local inner class seems too much for your needs, you can declare anonymous classes that extend a class or implement an interface. These classes are defined at the same time they are instantiated using the keyword new.

  3. What is the Factory Method design pattern used for?

    Answer:
    Factory and Abstract Factory represent design patterns that are both good at decoupling applications.
    Creational Design Pattern
    The factory method creates objects through inheritance. To create objects using the Factory method, you need to extend a class and override a factory method.

  4. In which class is the getClass() method defined in ?

    Answer:
    The getClass() method is defined in the Object class.


  5. What does the keyword transient indicate?

    Answer:
    The reserved word transient indicates that this field is not saved during serialization.

  6. What is a reference in Java?

    Answer:
    Java manipulates objects by reference, and all object variables are references. However, Java does not pass method arguments by reference. Java passes method arguments by value.

  7. What happens when you declare a reference variable as a data field within a class but do not instantiate an object for it in a constructor?

    Answer:
    This field will be initialized to null.

  8. What must be remembered when inheriting from an abstract class?

    Answer:
    Only non-abstract subclasses of an abstract class can be instantiated.

  9. Which facts hold true with respect to thread creation in Java?

    Answer:
    1. To create a Thread, pass a runnable object to the Thread constructor.
    2. Subclass the Thread so that it defines its own run() method. isAvlie() returns true if a thread has been started, and the run() method has not yet exited.

  10. What are the characteristics of constructors?

    Answer:
    1. Constructors can have normal access modifiers.
    2. Constructors can take arguments including "var-args"
    3. Constructors must have the same name as the class.
    4. Constructors can not be marked static.
    5. Constructors can not be marked final or abstract.