SCJP Mock exam for new Java 6 features


The new Java 6 features of SCJP exam are presented through 80 original questions.

Questions 1-30 are about Console, 31-50 about NavigableSet and 51-80 about NavigableMap.

  1. Console is a class. (1 correct answer)
    1. true
    2. false
  2. Console belongs to the java.io package. (1 correct answer)
    1. true
    2. false
  3. All the following methods are defined in Console.
        ⇒ readLine()
        ⇒ readPassword()
        ⇒ flush()
        ⇒ reader()
        ⇒ writer()
        ⇒ printf()
        ⇒ format()

    1. True.
    2. False.
  4. Consider these methods.
        ⇒ readLine()
        ⇒ readPassword()
        ⇒ flush()
        ⇒ reader()
        ⇒ writer()
        ⇒ printf()
        ⇒ format()
    How many of them are static? (1 correct answer)

    1. Two.
    2. Four.
    3. All.
    4. None.
  5. Consider these methods.
        ⇒ readLine()
        ⇒ readPassword()
        ⇒ flush()
        ⇒ reader()
        ⇒ writer()
        ⇒ printf()
        ⇒ format()
    How many of them declare a checked exception? (1 correct answer)

    1. Two.
    2. Four.
    3. All.
    4. None.
  6. What’s the signature of the method readPassword()? (1 correct answer)
    1. public char[] readPassword()
    2. public byte[] readPassword()
    3. public String readPassword()
  7. What’s the signature of the method format()? (1 correct answer)
    1. public void format(String, Object…)
    2. public String format(String, Object…)
    3. public Console format(String, Object…)
  8. There are 2 overloaded methods of Console with the name readLine. (1 correct answer)
    1. true
    2. false
  9. There are 2 overloaded methods of Console with the name getPassword. (1 correct answer)
    1. true
    2. false
  10. There’s maximum one object of type Console available per JVM. (1 correct answer)
    1. True.
    2. False.
  11. Will the following code compile successfully? (1 correct answer)
    import java.io.Console;
    
    public class MyConsole implements Console {
    
    }
    
    1. Yes.
    2. No.
  12. Will the following code compile successfully? (1 correct answer)
    import java.io.Console;
    
    public class MyConsole extends Console {
    
    }
    
    1. Yes.
    2. No.
  13. Will the following code compile successfully? (1 correct answer)
    import java.io.Console;
    
    public class Test {
        public static void main(String[] args) {
            Console console = new Console();		
        }
    }
    
    1. Yes.
    2. No.
  14. Will the following code compile successfully? (1 correct answer)
    import java.io.Console;
    
    public class Test {
        public static void main(String[] args) {
            Console console = System.getConsole();	
        }
    }
    
    1. Yes.
    2. No.
  15. Will the following code compile successfully? (1 correct answer)
    import java.io.Console;
    
    public class Test {
        public static void main(String[] args) {
            Console console = System.console();	
        }
    }
    
    1. Yes.
    2. No.
  16. Will the following code compile successfully? (1 correct answer)
    import java.io.Console;
    
    public class Test {
        public static void main(String[] args) {
            Console console = System.console();	
            console.println("Hello from your console!");
        }
    }
    
    1. Yes.
    2. No.
  17. Will the following code compile successfully? (1 correct answer)
    import java.io.Console;
    
    public class Test {
        public static void main(String[] args) {
            Console console = System.console();	
            console.format("Hello from your console!");
        }
    }
    
    1. Yes.
    2. No.
  18. For this question only, consider that the underlying system does NOT provide a console. What happens when the following code is executed? (1 correct answer)
    import java.io.Console;
    
    public class Test {
        public static void main(String[] args) {
            Console console = System.console(); // 1
            console.format("Hello from your console!"); // 2
        }
    }
    
    1. A runtime exception is thrown at line 1
    2. A runtime exception is thrown at line 2
    3. No exception is thrown at runtime.
  19. What happens when this code is compiled and executed? (1 correct answer)
    import java.io.Console;
    
    public class Test {
    public static void main(String[] args) {
        Console console = System.console();	
            console.readLine("Please enter your name: ");
            console.format(console.toString());
        }
    }
    }
    
    1. Compilation fails.
    2. An exception is thrown at runtime.
    3. The console prints exactly what the user typed before pressing ENTER.
    4. None of the above.
  20. What happens when this code is compiled and executed? (1 correct answer)
    import java.io.Console;
    
    public class Test {
    public static void main(String[] args) {
        Console console = System.console();	
        if (console != null) {
            console.writer().close();
            console.printf("Hello!");
        }
    }
    }
    
    1. Compilation fails.
    2. An exception is thrown at runtime.
    3. The console prints “Hello!”.
    4. None of the above.
  21. What happens when this code is compiled and executed? (1 correct answer)
    import java.io.Console;
    
    public class Test {
    public static void main(String[] args) {
        Console console = System.console();	
        if (console != null) {
        String name = console.
        readLine("Please enter your name: ");
        console.format("Hello %s!", name);
        }
    }
    }
    
    1. Compilation fails.
    2. An exception is thrown at runtime.
    3. If the user enters “Nikos”, the console prints “Hello Nikos!”
  22. What happens when this code is compiled and executed? (1 correct answer)
    import java.io.Console;
    
    public class Test {
    public static void main(String[] args) {
        Console console = System.console();	
        if (console != null) {
        String name = console.
        readLine("Please enter your name: ");
        console.format("Hello %z!", name);
        }
    }
    }
    
    1. Compilation fails.
    2. An exception is thrown at runtime.
    3. If the user enters “Nikos”, the console prints “Hello Nikos!”
  23. What happens when this code is compiled and executed? (1 correct answer)
    import java.io.Console;
    
    public class Test {
    public static void main(String[] args) {
        Console console = System.console();	
        if (console != null) {
        console.reader().close();
        String name = console.
        readLine("Please enter your name: ");
        console.format("Hello %s!", name);
        }
    }
    }
    
    1. Compilation fails.
    2. An exception is thrown at runtime.
    3. If the user enters “Nikos”, the console prints “Hello Nikos!”
  24. What happens when this code is compiled and executed? (1 correct answer)
    import java.io.Console;
    import java.io.IOException;
    
    public class Test {
    public static void main(String[] args) {
        Console console = System.console();	
        try {
            console.reader().close();
        } catch (IOException e) {
        }
        String name = console.
        readLine("Please enter your name: ");
        console.format("Hello %s!", name);
    }
    }
    
    1. Compilation fails.
    2. An exception is thrown at runtime.
    3. If the user enters “Nikos”, the console prints “Hello Nikos!”
  25. What happens when this code is compiled and executed? (1 correct answer)
    import java.io.Console;
    
    public class Test {
    public static void main(String[] args) {
        Console console = System.console();	
        console.println("Hello!");
    }
    }
    
    1. Compilation fails.
    2. An exception is thrown at runtime.
    3. The console prints “Hello!”.
  26. What happens when this code is compiled and executed? (1 correct answer)
    import java.io.Console;
    
    public class Test {
    public static void main(String[] args) {
        Console console = System.console();	
        console.writer().println("Hello!");
    }
    }
    
    1. Compilation fails.
    2. An exception is thrown at runtime.
    3. The console prints “Hello!”.
  27. What happens when this code is compiled and executed? (1 correct answer)
    import java.io.Console;
    
    public class Test {
    public static void main(String[] args) {
        Console console = System.console();	
        console.writer().append("Hello ")
        .append("from ").append("console!");
        console.flush();
    }
    }
    
    1. Compilation fails.
    2. An exception is thrown at runtime.
    3. The console prints “Hello from console!”.
  28. What happens when this code is compiled and executed? (1 correct answer)
    import java.io.Console;
    
    public class Test {
    public static void main(String[] args) {
        Console console = System.console();	
        console.format("Hello!", null);
    }
    }
    
    1. Compilation fails.
    2. An exception is thrown at runtime.
    3. The console prints “Hello!”.
  29. What happens when this code is compiled and executed? (1 correct answer)
    import java.io.Console;
    
    public class Test {
    public static void main(String[] args) {
        Console console = System.console();
        console.format(null);
    }
    }
    
    1. Compilation fails.
    2. An exception is thrown at runtime.
    3. The console prints “null”.
  30. What happens when this code is compiled and executed? (1 correct answer)
    import java.io.Console;
    
    public class Test {
    public static void main(String[] args) {
        Console console = System.console();	
        console.format("Hello ").printf("from ")
        .format("console!");
    }
    }
    
    1. Compilation fails.
    2. An exception is thrown at runtime.
    3. The console prints “Hello from console!”.
  31. NavigableSet is an interface. (1 correct answer)
    1. true
    2. false
  32. NavigableSet extends SortedSet. (1 correct answer)
    1. true
    2. false
  33. In Java 1.5 TreeSet implements SortedSet, whereas in Java 1.6 TreeSet implements NavigableSet. (1 correct answer)
    1. true
    2. false
  34. All these methods belong to NavigableSet. (1 correct answer)
        lower()
        higher()
        floor()
        ceiling()
        pollFirst()
        pollLast()

    1. true
    2. false
  35. How many of the following methods declare a checked exception? (1 correct answer)
        lower()
        higher()
        floor()
        ceiling()
        pollFirst()
        pollLast()

    1. None.
    2. Two.
    3. Four.
    4. All.
  36. How many of the following methods may throw an exception at runtime? (1 correct answer)
        lower()
        higher()
        floor()
        ceiling()
        pollFirst()
        pollLast()

    1. None.
    2. Two.
    3. Four.
    4. All.
  37. What’s the signature of the method lower()? (1 correct answer)
    1. E lower(E)
    2. boolean lower(E)
    3. E lower(NavigableSet<E>)
  38. What’s the signature of the method pollFirst()? (1 correct answer)
    1. E pollFirst()
    2. E pollFirst(E)
    3. E pollFirst(NavigableSet<E>)
  39. In the NavigableSet interface there are 2 overloaded methods with the name subSet. (1 correct answer)
    1. true
    2. false
  40. In the NavigableSet interface there are 2 overloaded methods with the name headSet. (1 correct answer)
    1. true
    2. false
  41. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableSet<Integer> set = new TreeSet<Integer>();
        set.add(-12);
        set.add(24);
        System.out.format("%d %d %d %d",
            set.lower(-12),
            set.lower(0),
            set.lower(24),
            set.lower(100)
        );
    }
    
    1. It prints “null -12 -12 24”.
    2. It prints “-12 -12 24 24”.
  42. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableSet<Integer> set = new TreeSet<Integer>();
        set.add(-12);
        set.add(24);
        System.out.format("%d %d %d %d",
            set.floor(-12),
            set.floor(0),
            set.floor(24),
            set.floor(100)
        );
    }
    
    1. It prints “null -12 -12 24”.
    2. It prints “-12 -12 24 24”.
  43. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableSet<Integer> set = new TreeSet<Integer>();
        set.add(-12);
        set.add(24);
        System.out.format("%d %d %d %d",
            set.higher(-12),
            set.higher(0),
            set.higher(24),
            set.higher(100)
        );
    }
    
    1. It prints “24 24 null null”.
    2. It prints “-12 24 24 null”.
  44. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableSet<Integer> set = new TreeSet<Integer>();
        set.add(-12);
        set.add(24);
        System.out.format("%d %d %d %d",
            set.ceiling(-12),
            set.ceiling(0),
            set.ceiling(24),
            set.ceiling(100)
        );
    }
    
    1. It prints “24 24 null null”.
    2. It prints “-12 24 24 null”.
  45. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableSet<Integer> set = new TreeSet<Integer>();
        set.add(-12);
        set.add(24);
        set.add(-28);
        set.add(-0);
        set.add(0);
        set.add(+0);
        set.add(11);
        set.add(145);
        System.out.format("%d %d %d %d",
            set.higher(-28),
            set.lower(24),
            set.floor(-0),
            set.ceiling(100)
        );
    }
    
    1. It prints “-12 11 0 100”.
    2. It prints “-12 11 0 145”.
    3. It prints “-28 24 0 100”.
    4. It prints “-28 24 0 145”.
  46. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableSet<Integer> set = new TreeSet<Integer>();
        set.pollFirst();
        System.out.println(set.size());
    }
    
    1. An exception is thrown at runtime.
    2. Compilation fails.
    3. It prints “0”.
  47. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableSet<Integer> set = new TreeSet<Integer>();
        set.first();
        System.out.println(set.size());
    }
    
    1. An exception is thrown at runtime.
    2. Compilation fails.
    3. It prints “0”.
  48. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableSet<Integer> set = new TreeSet<Integer>();
        set.add(1);
        set.add(2);
        set.add(4);
        NavigableSet<Integer> sub = set.headSet(4);
        System.out.println(sub.last());
    }
    
    1. An exception is thrown at runtime.
    2. Compilation fails.
    3. It prints “4”.
    4. It prints “2”.
  49. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableSet<Integer> set = new TreeSet<Integer>();
        set.add(1);
        set.add(2);
        set.add(4);
        NavigableSet<Integer> sub = set.headSet(4, true);
        System.out.println(sub.last());
    }
    
    1. An exception is thrown at runtime.
    2. Compilation fails.
    3. It prints “4”.
    4. It prints “2”.
  50. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableSet<Integer> set = new TreeSet<Integer>();
        set.add(1);
        set.add(2);
        set.add(4);
        for (Iterator iterator = set.descendingSet().iterator();
            iterator.hasNext();) {
            System.out.format("%d ", iterator.next());
        }
    }
    
    1. It prints “1 2 4 “.
    2. It prints “4 2 1 “.
    3. Compilation fails.
  51. NavigableMap IS-A Map. (1 correct answer)
    1. true
    2. false
  52. NavigableMap IS-A SortedMap. (1 correct answer)
    1. true
    2. false
  53. In Java 1.5 TreeMap implements SortedMap, whereas in Java 1.6 TreeMap implements NavigableMap. (1 correct answer)
    1. true
    2. false
  54. All these methods belong to NavigableMap. (1 correct answer)
        ⇒ lowerKey()
        ⇒ higherKey()
        ⇒ floorKey()
        ⇒ ceilingKey()

    1. true
    2. false
  55. All these methods belong to NavigableMap. (1 correct answer)
        ⇒ lowerEntry()
        ⇒ higherEntry()
        ⇒ floorEntry()
        ⇒ ceilingEntry()

    1. true
    2. false
  56. All these methods belong to NavigableMap. (1 correct answer)
        ⇒ pollFirstEntry()
        ⇒ pollLastEntry()
        ⇒ firstEntry()
        ⇒ lastEntry()

    1. true
    2. false
  57. All these methods belong to NavigableMap. (1 correct answer)
        ⇒ pollFirstKey()
        ⇒ pollLastKey()
        ⇒ firstKey()
        ⇒ lastKey()

    1. true
    2. false
  58. Assume NavigableMap<K,V>. What’s the signature of the method floorEntry()? (1 correct answer)
    1. K floorEntry(K)
    2. V floorEntry(K)
    3. Map.Entry<K,V> floorEntry(K)
  59. Assume NavigableMap<K,V>. What’s the signature of the method higherKey()? (1 correct answer)
    1. K higherKey(K)
    2. Map.Entry<K,V> higherKey(K)
    3. K higherKey(NavigableMap<K,V>)
  60. Assume NavigableMap<K,V>. What’s the signature of the method pollFirstEntry()? (1 correct answer)
    1. Map.Entry<K,V> pollFirstEntry()
    2. Map.Entry<K,V> pollFirstEntry(K)
    3. Map.Entry<K,V> pollFirstEntry(NavigableMap<K,V>)
  61. How many of these methods of NavigableMap may throw an exception at runtime? (1 correct answer)
        ⇒ pollFirstEntry()
        ⇒ pollLastEntry()
        ⇒ firstEntry()
        ⇒ lastEntry()
        ⇒ firstKey()
        ⇒ lastKey()

    1. None.
    2. Two.
    3. Four.
    4. All.
  62. How many of these methods of NavigableMap declare a checked exception? (1 correct answer)
        ⇒ pollFirstEntry()
        ⇒ pollLastEntry()
        ⇒ firstEntry()
        ⇒ lastEntry()
        ⇒ firstKey()
        ⇒ lastKey()

    1. None.
    2. Two.
    3. Four.
    4. All.
  63. In NavigableMap there are 2 overloaded methods with the name subMap. (1 correct answer)
    1. true
    2. false
  64. In NavigableMap there are 2 overloaded methods with the name headMap. (1 correct answer)
    1. true
    2. false
  65. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableMap<Integer, String> map = 
        new TreeMap<Integer, String>();
        map.put(5, "D");
        map.put(-1, "A");
        map.put(7, "O");
        System.out.format("%d %d %d %d",
            map.lowerKey(-100),
            map.lowerKey(5),
            map.lowerKey(6),
            map.lowerKey(100)
    	);
    }
    
    1. It prints “null -1 5 7”.
    2. It prints “null 5 5 7”.
  66. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableMap<Integer, String> map = 
        new TreeMap<Integer, String>();
        map.put(5, "D");
        map.put(-1, "A");
        map.put(7, "O");
        System.out.format("%d %d %d %d",
            map.floorKey(-100),
            map.floorKey(5),
            map.floorKey(6),
            map.floorKey(100)
    	);
    }
    
    1. It prints “null -1 5 7”.
    2. It prints “null 5 5 7”.
  67. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableMap<Integer, String> map = 
        new TreeMap<Integer, String>();
        map.put(5, "D");
        map.put(-1, "A");
        map.put(7, "O");
        System.out.format("%d %d %d %d",
            map.higherKey(-100),
            map.higherKey(5),
            map.higherKey(6),
            map.higherKey(100)
    	);
    }
    
    1. It prints “-1 7 7 null”.
    2. It prints “-1 5 7 null”.
  68. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableMap<Integer, String> map = 
        new TreeMap<Integer, String>();
        map.put(5, "D");
        map.put(-1, "A");
        map.put(7, "O");
        System.out.format("%d %d %d %d",
            map.ceilingKey(-100),
            map.ceilingKey(5),
            map.ceilingKey(6),
            map.ceilingKey(100)
    	);
    }
    
    1. It prints “-1 7 7 null”.
    2. It prints “-1 5 7 null”.
  69. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableMap<Integer, String> map = 
        new TreeMap<Integer, String>();
        map.put(5, "D");
        map.put(-1, "A");
        map.put(7, "O");
        System.out.format("%s %s %s %s",
            map.lowerEntry(-100),
            map.lowerEntry(5),
            map.lowerEntry(6),
            map.lowerEntry(100)
    	);
    }
    
    1. It prints “null -1=A 5=D 7=O”.
    2. It prints “null 5=D 5=D 7=O”.
  70. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableMap<Integer, String> map = 
        new TreeMap<Integer, String>();
        map.put(5, "D");
        map.put(-1, "A");
        map.put(7, "O");
        System.out.format("%s %s %s %s",
            map.floorEntry(-100),
            map.floorEntry(5),
            map.floorEntry(6),
            map.floorEntry(100)
    	);
    }
    
    1. It prints “null -1=A 5=D 7=O”.
    2. It prints “null 5=D 5=D 7=O”.
  71. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableMap<Integer, String> map = 
        new TreeMap<Integer, String>();
        map.put(5, "D");
        map.put(-1, "A");
        map.put(7, "O");
        System.out.format("%s %s %s %s",
            map.higherEntry(-100),
            map.higherEntry(5),
            map.higherEntry(6),
            map.higherEntry(100)
    	);
    }
    
    1. It prints “-1=A 7=O 7=O null”.
    2. It prints “-1=A 5=D 7=O null”.
  72. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableMap<Integer, String> map = 
        new TreeMap<Integer, String>();
        map.put(5, "D");
        map.put(-1, "A");
        map.put(7, "O");
        System.out.format("%s %s %s %s",
            map.ceilingEntry(-100),
            map.ceilingEntry(5),
            map.ceilingEntry(6),
            map.ceilingEntry(100)
    	);
    }
    
    1. It prints “-1=A 7=O 7=O null”.
    2. It prints “-1=A 5=D 7=O null”.
  73. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableMap<Integer, String> map = 
        new TreeMap<Integer, String>();
        map.put(34, "J");
        map.put(-1, "a");
        map.put(70, "v");
        map.put(5, "a");
        map.put(-1, "2");
        System.out.format("%s %s %s %s",
            map.ceilingEntry(-100),
            map.floorEntry(5),
            map.higherEntry(6),
            map.lowerKey(5)
        );
    }
    
    1. It prints “-1=2 5=a 34=J -1”.
    2. It prints “-1=a 5=a 34=J -1”.
    3. It prints “-1=2 5=a 34=J 5”.
    4. It prints “-1=a 5=a 34=J 5”.
  74. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableMap<Integer, String> map = 
        new TreeMap<Integer, String>();
        map.lastEntry();
        System.out.println(map.size());
    }
    
    1. An exception is thrown at runtime.
    2. Compilation fails.
    3. It prints “0”.
  75. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableMap<Integer, String> map = 
        new TreeMap<Integer, String>();
        map.pollFirstEntry();
        System.out.println(map.size());
    }
    
    1. An exception is thrown at runtime.
    2. Compilation fails.
    3. It prints “0”.
  76. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableMap<Integer, String> map = 
        new TreeMap<Integer, String>();
        map.firstKey();
        System.out.println(map.size());
    }
    
    1. An exception is thrown at runtime.
    2. Compilation fails.
    3. It prints “0”.
  77. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableMap<Integer, String> map = 
        new TreeMap<Integer, String>();
        map.put(1, "A");
        map.put(2, "B");
        map.put(3, "C");
        NavigableMap<Integer, String> sub =
        map.subMap(0, 3);
        System.out.println(sub.lastKey());
    }
    
    1. It prints “2”.
    2. It prints “3”.
    3. Compilation fails.
    4. An exception is thrown at runtime.
  78. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableMap<Integer, String> map = 
        new TreeMap<Integer, String>();
        map.put(1, "A");
        map.put(2, "B");
        map.put(3, "C");
        NavigableMap<Integer, String> sub =
        map.subMap(0, false, 3, false);
        System.out.println(sub.lastKey());
    }
    
    1. It prints “2”.
    2. It prints “3”.
    3. Compilation fails.
    4. An exception is thrown at runtime.
  79. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableMap<Integer, String> map = 
        new TreeMap<Integer, String>();
        map.put(1, "A");
        map.put(2, "B");
        map.put(3, "C");
        NavigableMap<Integer, String> sub =
        map.subMap(0, false, 3, false);
        map.put(4, "D");
        System.out.format("%d %d", map.size(), sub.size());
    }
    
    1. It prints “2 2”.
    2. It prints “3 2”.
    3. It prints “3 3”.
    4. It prints “4 2”.
    5. It prints “4 3”.
    6. Compilation fails.
    7. An exception is thrown at runtime.
  80. What is the output of this code? (1 correct answer)
    public static void main(String[] args) {
        NavigableMap<Integer, String> map = 
        new TreeMap<Integer, String>();
        map.put(1, "A");
        map.put(2, "B");
        map.put(3, "C");
        NavigableMap<Integer, String> sub =
        map.subMap(0, false, 3, false);
        sub.put(4, "D");
        System.out.format("%d %d", map.size(), sub.size());
    }
    
    1. It prints “2 2”.
    2. It prints “3 2”.
    3. It prints “3 3”.
    4. It prints “4 2”.
    5. It prints “4 3”.
    6. Compilation fails.
    7. An exception is thrown at runtime.

© 2008 Nikos Pougounias. This is a free contribution to the Java community. Please distribute it for free. https://nikojava.wordpress.com

Answers

  1. a
  2. a
  3. a
  4. d
  5. d
  6. a
  7. c
  8. a
  9. b
  10. a
  11. b
  12. b
  13. b
  14. b
  15. a
  16. b
  17. a
  18. a
  19. d
  20. c
  21. c
  22. b
  23. a
  24. c
  25. a
  26. c
  27. c
  28. c
  29. b
  30. c
  31. a
  32. a
  33. a
  34. a
  35. a
  36. c
  37. a
  38. a
  39. a
  40. a
  41. a
  42. b
  43. a
  44. b
  45. b
  46. c
  47. a
  48. b
  49. c
  50. b
  51. a
  52. a
  53. a
  54. a
  55. a
  56. a
  57. b
  58. c
  59. a
  60. a
  61. b
  62. a
  63. a
  64. a
  65. a
  66. b
  67. a
  68. b
  69. a
  70. b
  71. a
  72. b
  73. a
  74. c
  75. c
  76. a
  77. c
  78. a
  79. d
  80. g

References

A friendly community of people preparing for the Sun Certified Java Programmer certification can be found at the JavaRanch SCJP forum.

You may contact me for any suggestion.

9 Responses to SCJP Mock exam for new Java 6 features

  1. Nikos says:

    Thanks to Maggie Zhou for her corrections on questions 45 and 58!

  2. […] Free SCJP Mock exam for new Java 6 features […]

  3. MarcoC says:

    Question 18: for what i know if the JVM has no console System.console() returns null, so the exception is thrown at line 2 (answer b)

    Question 19: there’s an extra }, so compilation fails🙂

    Many thanks for the exams.

  4. lakshmi says:

    Hi,

    Good job Niko. Nice material has given to us.

    Have doubt in question no 26,27 and 28. I am using NetBeans 6.7 IDE tool. I ran it .All these 3 programs giving NullPointerException.

    And the 20 was compiled successfully but doent print anything.

    Last but not least, How should we give a name to question no 21 and 24?

    Please let me know if anyone known about them as soon as poaaible.

  5. Nikos says:

    Hi lakshmi, you should not use the NetBeans IDE to run the questions for java.io.Console. You should run them from the command prompt of your operating system.

  6. Vibha says:

    Hi, in que 9. I think answer is true as there are overloaded readPassword() method in console class. Plz explain if I am wrong.

  7. Raymond Antony says:

    Very useful

  8. Oana says:

    Nikos, thanks a lot! Your mock exams are great!

  9. Eric says:

    Thank you so much!!..These were very helpful in clearing my concepts!..:)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: