Interview Questions 1 - 10  «Prev Next»

Map Interface, HashMap Class

  1. (J2SE) What is the difference between a HashMap and Map?

    Answer:
    A Map is an Interface and a Hashmap is class that implements that interface.

  2. What are 2 facts with respect to arrays?

    Answer:
    1. The type of the element of the array is the called the base type of the array.
    2. The array will always be an object on the heap.

  3. What is the purpose of the volatile modifier?

    Answer:
    The volatile modifier tells the compiler that the variable modified by volatile can be changed unexpectedly by other parts of your program. One of these situations involves multithreaded programs. In a multithreaded program, sometimes two or more threads share the same variable. For efficiency considerations, each thread can keep its own, private copy of such a shared variable.

  4. What is the difference between static methods and instance methods?

    Answer: The basic paradigm in Java is that you write Objects, and that those objects are instantiated. Instantiated objects (an instance of an object) have attributes associated with them (member variables) that affect their behavior; when the instance has its method executed it will refer to these variables.
    A static method does not have an explicit reference to any particular instance of the class.

  5. How can you remember the number of bits of a float and double datatype?

    Answer:
    Float is 32 bit and double is 64 bits.

  6. What does it mean if a developer is programming to an interface?

    Answer:
    Programming to an interface is the concept that code should interact based on a defined set of functionality instead of an explicitly defined object type.

  7. What kind of datatypes can characters accept?

    Answer:
    1. Integers
    2. hexadecimal
    3. octal
    4. character literals

  8. Can a static method call a non-static method?

    Answer:
    No.

  9. What do static methods have access to?

    Answer:
    Static methods can access only other static methods and variables.

  10. What are the this and super keywords used for in Java?

    Answer:
    The this and super keywords are used to access Java elements explicitly in relation to the current class.