Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?
A -
java.util.HashSet
B -
java.util.LinkedHashSet
C -
java.util.List
D -
java.util.ArrayList
2-
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?
A -
java.util.Map
B -
java.util.Set
C -
java.util.List
D -
java.util.Collection
3-
Which interface does java.util.Hashtable implement?
A -
Java.util.Map
B -
Java.util.List
C -
Java.util.HashTable
D -
Java.util.Collection
4-
What will be the output of the program?
public class Test
{
public static void main (String[] args)
{
String foo = args[1];
String bar = args[2];
String baz = args[3];
System.out.println("baz = " + baz); /* Line 8 */
}
}
And the command line invocation:
> java Test red green blue
A -
baz =
B -
baz = null
C -
baz = blue
D -
Runtime Exception
5-
What will be the output of the program?
public class Test
{
public static void main (String args[])
{
String str = NULL;
System.out.println(str);
}
}
A -
NULL
B -
Compile Error
C -
Code runs but no output
D -
Runtime Exception
6-
What will be the output of the program?
package foo;
import java.util.Vector; /* Line 2 */
private class MyVector extends Vector
{
int i = 1; /* Line 5 */
public MyVector()
{
i = 2;
}
}
public class MyNewVector extends MyVector
{
public MyNewVector ()
{
i = 4; /* Line 15 */
}
public static void main (String args [])
{
MyVector v = new MyNewVector(); /* Line 19 */
}
}
A -
Compilation will succeed.
B -
Compilation will fail at line 3.
C -
Compilation will fail at line 5.
D -
Compilation will fail at line 15.
7-
Which interface provides the capability to store objects using a key-value pair?
A -
Java.util.Map
B -
Java.util.Set
C -
Java.util.List
D -
Java.util.Collection
8-
Which collection class allows you to associate its elements with key values, and allows you to retrieve objects in FIFO (first-in, first-out) sequence?
A -
java.util.ArrayList
B -
java.util.LinkedHashMap
C -
java.util.HashMap
D -
java.util.TreeMap
9-
>What will be the output of the program?
public class Test
{
private static int[] x;
public static void main(String[] args)
{
System.out.println(x[0]);
}
}
A -
0
B -
null
C -
Compile Error
D -
NullPointerException at runtime
10-
What will be the output of the program?
import java.util.*;
class I
{
public static void main (String[] args)
{
Object i = new ArrayList().iterator();
System.out.print((i instanceof List)+",");
System.out.print((i instanceof Iterator)+",");
System.out.print(i instanceof ListIterator);
}
}