Which collection class allows you to access its elements by associating a key with an element's value, and provides synchronization?
A -
java.util.SortedMap
B -
java.util.TreeMap
C -
java.util.TreeSet
D -
java.util.Hashtable
2-
Which is valid declaration of a float?
A -
float f = 1F;
B -
float f = 1.0;
C -
float f = "1";
D -
float f = 1.0d;
3-
/* 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");
}
}
What line of code should replace the missing statement to make this program compile?
A -
No statement required.
B -
import java.io.*;
C -
include java.io.*;
D -
import java.io.PrintWriter;
4-
What is the numerical range of char?
A -
0 to 32767
B -
0 to 65535
C -
-256 to 255
D -
-32768 to 32767
5-
Which of the following are Java reserved words?
run
import
default
implement
A -
1 and 2
B -
2 and 3
C -
3 and 4
D -
2 and 4
6-
What will be the output of the program?
public class Test
{
private static float[] f = new float[2];
public static void main (String[] args)
{
System.out.println("f[0] = " + f[0]);
}
}
A -
f[0] = 0
B -
f[0] = 0.0
C -
Compile Error
D -
Runtime Exception
7-
What will be the output of the program?
import java.util.*;
class H
{
public static void main (String[] args)
{
Object x = new Vector().elements();
System.out.print((x instanceof Enumeration)+",");
System.out.print((x instanceof Iterator)+",");
System.out.print(x instanceof ListIterator);
}
}
A -
Prints: false,false,false
B -
Prints: false,false,true
C -
Prints: false,true,false
D -
Prints: true,false,false
8-
What will be the output of the program?
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.print( it.next() + " " );
}
A -
one two three four
B -
four three two one
C -
four one three two
D -
one two three four one
9-
What will be the output of the program?
public static void main(String[] args)
{
Object obj = new Object()
{
public int hashCode()
{
return 42;
}
};
System.out.println(obj.hashCode());
}
A -
42
B -
Runtime Exception
C -
Compile Error at line 2
D -
Compile Error at line 5
10-
class Test1
{
public int value;
public int hashCode() { return 42; }
}
class Test2
{
public int value;
public int hashcode() { return (int)(value^5); }
}
which statement is true?
A -
class Test1 will not compile.
B -
The Test1 hashCode() method is more efficient than the Test2 hashCode() method.
C -
The Test1 hashCode() method is less efficient than the Test2 hashCode() method.