1.
Which statements are true about comparing two instances of the same class,given that the equals() and hashCode() methods have been properly overridden?
(choose all that apply)
A. 
If the equals()methood returns true,the hashCode() comparison==might return false.
B. 
If the equals()methood returns false,the hashCode() comparison==might return true.
C. 
If the hashCode() comparison==returns true,the equals() method must return true
D. 
If the hashCode() comparison==returns true,the equals() method might return true
E. 
If the hashCode() comparison!=returns true,the equals() method must return true
2.
Which of the following most closely describes a bitset collection?
A. 
A class that contains groups of unique sequences of bits.
B. 
A method for flipping individual bits in instance of a primitive type.
C. 
An array of boolean primitives that indicate zeros or ones.
D. 
A collection for storing bits as on-off information, like a vector of bits.
3.
Which most closely matches a java description of a java map
A. 
A vector of arrays for a 2D geographic representation.
B. 
A class for containing unique array elements.
C. 
A class for containing unique vector elements.
D. 
An interface that ensures that implementing classes cannot contain duplicate keys.
4.
Which collection class(es)allows you to grow or shrink its size and provides indexed access to its elements,but whose methods are not synchronised??(choose all that aaply)
A. 
B. 
C. 
D. 
E. 
F. 
5.
The Enumeration interface allows a program to iterate its way through the elements of a container such as a Vector.
6.
The hashCode method is used by the java.util.SortedSet collection class to order the
elements within that set.
7.
The hashCode method is used by the java.util.HashSet collection class to group the
elements within that set into hash buckets for swift retrieval.
8.
The hashCode method for a given class can be used to test for object inequality, but
NOT object equality, for that class.
9.
Public static Collection get()
{
Collection sorted = new LinkedList();
sorted.add("B");
sorted.add("C");
sorted.add("A");
return sorted;
}
public static void main(String[] args)
{
for (Object obj: get())
{
System.out.print(obj + ", ");
}
}
What is the result?
A. 
B. 
C. 
D. 
The code runs with no output
E. 
Exception is thrown at runtime
10.
Properties method getProperty locates the value associated with the specified key. If the key is not found in this Properties object,getProperty attempts to locate the key in the default Properties object (if there is one).
11.
Import java.util.*;
public class TryMe {
public static void main(String args[]) {
Queue<String> q = new PriorityQueue<String>();
q.add("3");
q.add("1");
q.add("2");
System.out.print(q.poll() + " ");
System.out.print(q.peek() + " ");
System.out.print(q.peek());
}
}
A. 
B. 
C. 
D. 
E. 
F. 
12.
Import java.util.*;
public class TestArrayList
{
public static void main(String args[])
{
List test =new ArrayList();
String s="hi";
testadd(s);
testadd(s+s);
System.out.println(test.size());
System.out.println(test.contains(42));
System.out.println(test.contains("hihi"));
test.remove("hi");
System.out.println(test.size());
}
}
What is the output of this program???
A. 
B. 
C. 
D. 
13.
Import java.util.*;
public class WrappedString
{
private String s;
public WrappedString(String s)
{
this.s = s;
}
public static void main(String[] args)
{
HashSeths = new HashSet();
WrappedString ws1 = new WrappedString("aardvark");
WrappedString ws2 = new WrappedString("aardvark");
String s1 = new String("aardvark");
String s2 = new String("aardvark");
hs.add(ws1); hs.add(ws2); hs.add(s1); hs.add(s2);
System.out.println(hs.size());
}
}
What is the result?
A. 
B. 
C. 
D. 
E. 
F. 
G. 
Exception is thrown at runtime
14.
Import java.util.*;
public class PQ
{
public static void main(String[] args)
{
PriorityQueue pq = new PriorityQueue();
pq.add("carrot");
pq.add("apple");
pq.add("banana");
System.out.println(pq.poll() + ":" + pq.peek());
}
}
What is the result?
A. 
B. 
C. 
D. 
E. 
F. 
15.
Import java.util.*;
public class Example
{
public static void main(String[] args) {
// insert code here
set.add(new Integer(2));
set.add(new Integer(1));
System.out.println(set);
}
}
Which code, inserted at line 4, guarantees that this program will output [1, 2]?
A. 
B. 
C. 
Set set = new SortedSet();
D. 
Set set = new LinkedHashSet();
E. 
Set set = new SortedList();
16.
If you do not specify a capacity increment, the system will automatically add 2 to the size of the Vector each time additional capacity is needed.
17.
How does the set collection deal with duplicate elements?
A. 
An exception is thrown if you attempt to add an element with a duplicate value.
B. 
The add method returns false if you attempt to add an element with a duplicate value.
C. 
A set may contain elements that return duplicate values from a call to the equals method.
D. 
Duplicate values will cause an error at compile time.
18.
Given:
TreeSet map=new TreeSet();
map.add("one");
map.add("two");
map.add("three");
map.add("four");
map.add("one");
Iterator it=map.iterator();
while(it.hasNext()) {
System.out.println(it.next()+" ");
}
what is the result ???
A. 
B. 
C. 
D. 
E. 
F. 
An exception is thrown at runtime
G. 
The print order is not guaranteed
19.
Given:
import java.util.*
class AlgaeDiesel{
public static void main(String[] args) {
String sa={"foo","bar","baz" };
//insert method invocations here
}
}
what java.util.Arrays and/or java.util.Collections methods could you use
to convert sa to a List and then search the List to find the index
of the element whose valueis "foo"??(choose three methods)
A. 
B. 
C. 
D. 
E. 
F. 
G. 
20.
Given:
public static void search(List list)
{
list.clear();
list.add("b");
list.add("a");
list.add("c");
System.out.println(Collections.binarySearch(list, "a"));
}
What is the result of calling search with a valid List implementation?
A. 
B. 
C. 
D. 
E. 
F. 
G. 
21.
Given:
ArrayList a = new ArrayList();
containing the values {“1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”}
Which code will return 2?
A. 
Collections. sort(a, a.reverse());
int result = Collections.binarySearch(a, “6”);
B. 
Comparator c = Collections.reverseOrder();
Collections.sort(a, c);
int result = Collections.binarySearch(a, “6”);
C. 
Comparator c = Collections.reverseOrder(a);
Collections.sort(a, c);
int result = Collections.binarySearch(a, “6”,c);
D. 
Comparator c = new InverseComparator(new Comparator());
Collections.sort(a);
int result = Collections.binarySearch(a, “6”,c);
22.
Given:
public class Key {
private long id1;
private long id2;
// class Key methods
}
A programmer is developing a class Key, that will be used as a key in a
standard java.util.HashMap.Which two methods should be overridden to assure
that Key works correctly as a key? (Choose two.)
A. 
B. 
Public boolean equals(Key k)
C. 
Public int compareTo(Object o)
D. 
Public boolean equals(Object o)
E. 
Public boolean compareTo(Key k)
23.
Given:
import java.util.*;
public class LetterASort
{
public static void main(String[] args)
{
ArrayList strings = new ArrayList();
strings.add("aAaA");
strings.add("AaA");
strings.add("aAa");
strings.add("AAaa");
Collections.sort(strings);
for (String s : strings) { System.out.print(s + " ");
}
}
}
What is the result?
A. 
B. 
C. 
D. 
E. 
F. 
An exception is thrown at runtime.
24.
Given:
import java.util.*;
class Flubber
{
public static void main(String[] args)
{
List x=new ArrayList();
x.add("x");
x.add("xx");
x.add("Xx");
//insert code here
for(String s:x)
System.out.println(s);
}}
the output is:
xx
Xx
x
which code, inserted will produce the preceding output??
(choose al that apply)
A. 
B. 
Comparable c=Collections.reverse();
Collections.sort(x,c);
C. 
D. 
Comparable c=Collections.reverseOrder();
Collections.sort(x,c);
E. 
Comparator c=Collections.reverseOrder();
Collections.sort(x,c);
25.
Given the code. What is the result?
public class TrickyNum<X extends Number> {
private X x;
public TrickyNum(X x) {
this.x = x;
}
private double getDouble() {
return x.doubleValue();
}
public static void main(String args[]) {
TrickyNum<Integer> a = new TrickyNum<Integer>(new Integer(1));
System.out.print(a.getDouble());
}
}
A. 
B. 
An exception is thrown at runtime.
C. 
D.