Dan Chisholm's
Java Programmer Certification Mock Exam

Please Help Save a Tree!

The pages of this web site are not formatted to conserve paper, but my new book (ISBN: 0-9745862-0-X) is formatted to save paper, save your printer cartridge, save a loose-leaf binder, and save money. If you prefer to work my exams from printed pages, then give your printer a rest and buy my new book.

Today, you can find my book at amazon.com.

If you have any questions or comments concerning my mock exams or my book, then please send an e-mail to me at scjpexam2000@yahoo.com.


Question 1

Which implementation of the List interface produces the slowest access to an element in the middle of the list by means of an index?

a. Vector
b. ArrayList
c. LinkedList
d. None of the above

Question 2

import java.util.*;
class GFC100 {
  public static void main (String args[]) {
    Object a1 = new LinkedList(), b1 = new TreeSet();
    Object c1 = new TreeMap();
    System.out.print((a1 instanceof Collection)+",");
    System.out.print((b1 instanceof Collection)+",");
    System.out.print(c1 instanceof Collection);
}}

What is the result of attempting to compile and run the program?

a. Prints: false,false,false
b. Prints: false,false,true
c. Prints: false,true,false
d. Prints: false,true,true
e. Prints: true,false,false
f. Prints: true,false,true
g. Prints: true,true,false
h. Prints: true,true,true
i. None of the above

Question 3

 Each element must be unique.
 Contains no duplicate elements.
 Elements are not key/value pairs.
 Accessing an element can be almost as fast as performing a similar operation on an array.

Which of these classes provides the specified features?

a. LinkedList
b. TreeMap
c. TreeSet
d. HashMap
e. HashSet
f. LinkedHashMap
g. Hashtable
h. None of the above

Question 4

import java.util.*;
class GFC101 {
  public static void main (String args[]) {
    Object a1 = new HashMap(), b1 = new ArrayList();
    Object c1 = new HashSet();
    System.out.print((a1 instanceof Collection)+",");
    System.out.print((b1 instanceof Collection)+",");
    System.out.print(c1 instanceof Collection);
}}

What is the result of attempting to compile and run the program?

a. Prints: false,false,false
b. Prints: false,false,true
c. Prints: false,true,false
d. Prints: false,true,true
e. Prints: true,false,false
f. Prints: true,false,true
g. Prints: true,true,false
h. Prints: true,true,true
i. None of the above

Question 5

 Entries are organized as key/value pairs.
 Duplicate entries replace old entries.

Which interface of the java.util package offers the specified behavior?

a. List
b. Map
c. Set
d. None of the above

Question 6

import java.util.*;
class GFC102 {
  public static void main (String args[]) {
    Object a = new HashSet();
    System.out.print((a instanceof Set)+",");
    System.out.print(a instanceof SortedSet);
}}

What is the result of attempting to compile and run the program?

a. Prints: false,false
b. Prints: false,true
c. Prints: true,false
d. Prints: true,true
e. None of the above

Question 7

Which implementation of the List interface provides for the fastest insertion of a new element into the middle of the list?

a. Vector
b. ArrayList
c. LinkedList
d. None of the above

Question 8

import java.util.*;
class GFC103 {
  public static void main (String args[]) {
    Object a1 = new TreeSet();
    System.out.print((a1 instanceof Set)+",");
    System.out.print(a1 instanceof SortedSet);
}}

What is the result of attempting to compile and run the program?

a. Prints: false,false
b. Prints: false,true
c. Prints: true,false
d. Prints: true,true
e. None of the above

Question 9

 Stores key/value pairs.
 Duplicate entries replace old entries.
 Entries are sorted using a Comparator or the Comparable interface.

Which of these classes provides the specified features?

a. LinkedList
b. TreeMap
c. TreeSet
d. HashMap
e. HashSet
f. Hashtable
g. None of the above

Question 10

import java.util.*;
class GFC104 {
  public static void main (String args[]) {
    LinkedList a1 = new LinkedList();
    ArrayList b1 = new ArrayList();
    Vector c1 = new Vector();
    System.out.print((a1 instanceof List)+",");
    System.out.print((b1 instanceof List)+",");
    System.out.print(c1 instanceof List);
}}

What is the result of attempting to compile and run the program?

a. Prints: false,false,false
b. Prints: false,false,true
c. Prints: false,true,false
d. Prints: false,true,true
e. Prints: true,false,false
f. Prints: true,false,true
g. Prints: true,true,false
h. Prints: true,true,true
i. None of the above

Question 11

 Entries are not organized as key/value pairs.
 Duplicate entries are rejected.

Which interface of the java.util package offers the specified behavior?

a. List
b. Map
c. Set
d. None of the above

Question 12

import java.util.*;
class GFC105 {
  public static void main (String args[]) {
    Object a = new HashSet(), b = new HashMap();
    Object c = new Hashtable();
    System.out.print((a instanceof Collection)+",");
    System.out.print((b instanceof Collection)+",");
    System.out.print(c instanceof Collection);
}}

What is the result of attempting to compile and run the program?

a. Prints: false,false,false
b. Prints: false,false,true
c. Prints: false,true,false
d. Prints: false,true,true
e. Prints: true,false,false
f. Prints: true,false,true
g. Prints: true,true,false
h. Prints: true,true,true
i. None of the above

Question 13

 Elements are not key/value pairs.
 Contains no duplicate elements.
 The entries can be sorted using the Comparable interface.

Which of these classes provides the specified features?

a. LinkedList
b. TreeMap
c. TreeSet
d. HashMap
e. HashSet
f. Hashtable
g. None of the above

Question 14

import java.util.*;
class GFC106 {
  public static void main (String args[]) {
    Object a = new HashSet(), b = new HashMap();
    Object c = new Hashtable();
    System.out.print((a instanceof Map)+",");
    System.out.print((b instanceof Map)+",");
    System.out.print(c instanceof Map);
}}

What is the result of attempting to compile and run the program?

a. Prints: false,false,false
b. Prints: false,false,true
c. Prints: false,true,false
d. Prints: false,true,true
e. Prints: true,false,false
f. Prints: true,false,true
g. Prints: true,true,false
h. Prints: true,true,true
i. None of the above

Question 15

 Stores key/value pairs.
 Allows null elements, keys, and values.
 Duplicate entries replace old entries.
 Entries are not sorted.

Which of these classes provides the specified features?

a. LinkedList
b. TreeMap
c. TreeSet
d. HashMap
e. HashSet
f. Hashtable
g. None of the above

Question 16

import java.util.*;
class GFC107 {
  public static void main (String args[]) {
    Object a = new HashSet(), b = new HashMap();
    Object c = new Hashtable();
    System.out.print((a instanceof Cloneable)+",");
    System.out.print((b instanceof Cloneable)+",");
    System.out.print(c instanceof Cloneable);
}}

What is the result of attempting to compile and run the program?

a. Prints: false,false,false
b. Prints: false,false,true
c. Prints: false,true,false
d. Prints: false,true,true
e. Prints: true,false,false
f. Prints: true,false,true
g. Prints: true,true,false
h. Prints: true,true,true
i. None of the above

Question 17

 Entries are not organized as key/value pairs.
 Generally accepts duplicate elements.
 Entries may be accessed by means of an index.

Which interface of the java.util package offers the specified behavior?

a. List
b. Map
c. Set
d. None of the above

Question 18

import java.util.*;
import java.io.Serializable;
class GFC108 {
  public static void main (String args[]) {
    HashMap a = new HashMap();
    boolean b1, b2, b3;
    b1 = (a instanceof Cloneable) & (a instanceof Serializable);
    b2 = a instanceof Map;
    b3 = a instanceof Collection;
    System.out.print(b1 + "," + b2 + "," + b3);
}}

What is the result of attempting to compile and run the program?

a. Prints: false,false,false
b. Prints: false,false,true
c. Prints: false,true,false
d. Prints: false,true,true
e. Prints: true,false,false
f. Prints: true,false,true
g. Prints: true,true,false
h. Prints: true,true,true
i. None of the above

Question 19

Which of the following classes allow unsynchronized read operations by multiple threads?

a. Vector
b. Hashtable
c. TreeMap
d. TreeSet
e. HashMap
f. HashSet

Question 20

 Entries are organized as key/value pairs.
 Duplicate entries replace old entries.
 Entries are sorted using a Comparator or the Comparable interface.

Which interface of the java.util package offers the specified behavior?

a. List
b. Map
c. Set
d. SortedSet
e. SortedMap
f. None of the above

Question 21

import java.util.*;
class GFC110 {
  public static void main (String[] args) {
    Object m = new LinkedHashMap();
    System.out.print((m instanceof Collection)+",");
    System.out.print((m instanceof Map)+",");
    System.out.print(m instanceof List);
}}

What is the result of attempting to compile and run the program?

a. Prints: false,false,false
b. Prints: false,false,true
c. Prints: false,true,false
d. Prints: false,true,true
e. Prints: true,false,false
f. Prints: true,false,true
g. Prints: true,true,false
h. Prints: true,true,true
i. None of the above

Question 22

import java.util.*;
class GFC109 {
  public static void main (String[] args) {
    Object v = new Vector();
    System.out.print((v instanceof Collections)+",");
    System.out.print((v instanceof Arrays)+",");
    System.out.print(v instanceof List);
}}

What is the result of attempting to compile and run the program?

a. Prints: false,false,false
b. Prints: false,false,true
c. Prints: false,true,false
d. Prints: false,true,true
e. Prints: true,false,false
f. Prints: true,false,true
g. Prints: true,true,false
h. Prints: true,true,true
i. None of the above


Copyright © 2002-2004, Dan Chisholm
All rights reserved.