logo

CuriousTab

CuriousTab

Discussion


Home Java Programming Objects and Collections Comments

  • Question
  • Which interface provides the capability to store objects using a key-value pair?


  • Options
  • A. Java.util.Map
  • B. Java.util.Set
  • C. Java.util.List
  • D. Java.util.Collection

  • Correct Answer
  • Java.util.Map 

    Explanation
    An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value.

    Objects and Collections problems


    Search Results


    • 1. What line of code should replace the missing statement to make this program compile?
      /* Missing Statement? */
      public class foo 
      {
          public static void main(String[]args)throws Exception 
          {
              java.io.PrintWriter out = new java.io.PrintWriter(); 
              new java.io.OutputStreamWriter(System.out,true); 
              out.println("Hello"); 
          } 
      }
      

    • Options
    • A. No statement required.
    • B. import java.io.*;
    • C. include java.io.*;
    • D. import java.io.PrintWriter;
    • Discuss
    • 2. Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?

    • Options
    • A. java.util.HashSet
    • B. java.util.LinkedHashSet
    • C. java.util.List
    • D. java.util.ArrayList
    • Discuss
    • 3. Suppose that you would like to create an instance of a new Map that has an iteration order that is the same as the iteration order of an existing instance of a Map. Which concrete implementation of the Map interface should be used for the new instance?

    • Options
    • A. TreeMap
    • B. HashMap
    • C. LinkedHashMap
    • D. The answer depends on the implementation of the existing instance.
    • Discuss
    • 4. You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order. Which interface provides that capability?

    • Options
    • A. java.util.Map
    • B. java.util.Set
    • C. java.util.List
    • D. java.util.Collection
    • Discuss
    • 5. What is the numerical range of char?

    • Options
    • A. 0 to 32767
    • B. 0 to 65535
    • C. -256 to 255
    • D. -32768 to 32767
    • Discuss
    • 6. Which of the following are Java reserved words?

      1. run
      2. import
      3. default
      4. implement

    • Options
    • A. 1 and 2
    • B. 2 and 3
    • C. 3 and 4
    • D. 2 and 4
    • Discuss
    • 7. Which collection class allows you to access its elements by associating a key with an element's value, and provides synchronization?

    • Options
    • A. java.util.SortedMap
    • B. java.util.TreeMap
    • C. java.util.TreeSet
    • D. java.util.Hashtable
    • Discuss
    • 8. Which is valid declaration of a float?

    • Options
    • A. float f = 1F;
    • B. float f = 1.0;
    • C. float f = "1";
    • D. float f = 1.0d;
    • Discuss
    • 9. Which three are methods of the Object class?

      1. notify();
      2. notifyAll();
      3. isInterrupted();
      4. synchronized();
      5. interrupt();
      6. wait(long msecs);
      7. sleep(long msecs);
      8. yield();

    • Options
    • A. 1, 2, 4
    • B. 2, 4, 5
    • C. 1, 2, 6
    • D. 2, 3, 4
    • Discuss
    • 10. Which of the following line of code is suitable to start a thread?
      class X implements Runnable 
      { 
          public static void main(String args[]) 
          {
              /* Missing code? */
          } 
          public void run() {} 
      }
      

    • Options
    • A. Thread t = new Thread(X);
    • B. Thread t = new Thread(X); t.start();
    • C. X run = new X(); Thread t = new Thread(run); t.start();
    • D. Thread t = new Thread(); x.run();
    • Discuss


    Comments

    There are no comments.

Enter a new Comment