WorksheetsJava Practice Quiz
Total questions: 30
Worksheet time: 16mins
Which of these classes provides the specified features?
-Contains no duplicate elements.
-Can contain at most one Null value.
-Elements are not key-value pairs.
-Accessing an element can be almost as fast as performing a similar operation on an array.
LinkedList
TreeMap
HashSet
LinkedHashMap
HashMap
Which of these interface is not part of Java’s collection framework?
List
Sorted List
Set
Sorted Map
Which of these return type of hasNext() method of an iterator?
Integer
Double
Boolean
Collections Object
Which of the following statement about Set is true?
A HashSet cannot have a null value.
Set allows duplicate values.
Set allows null values but only single occurrence.
Set extends the Java.util.collection interface.
-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?
List
Map
Set
SortedSet
SortedMap
{1=C, 2=JavaEE, 4=Python, 3=PHP}
{1=C, 2=JavaSE, 3=Python, 4=PHP}
{1=C, 2=JavaEE, 3=Python, 4=PHP}
{1=C, 2=JavaSE,2=JavaEE, 3=Python, 4=PHP}
NullPointerException
-Entries are not organized as key/value pairs.
-Duplicate entries are rejected.
Which interface of the java.util package offers the specified behavior?
List
Map
Set
None of the above
Which of the following is/are correct statements?
HashSet class implements the Set interface
HashSet does not allow duplicate elements that means you can not store duplicate values in HashSet.
HashSet permits to have a single null value.
HashMap does not allow duplicate keys however it allows to have duplicate values.
HashMap and HashSet are threadsafe
{"Computer", "Programming","Networks","null"}
{"Computer", "Programming","Networks",null,"null"}
Line 11 : Genetates NullPointer Exception
Line12: Generates NullPointerException
Which of the following statement(s) is/are FALSE?
TreeSet does not preserve the insertion order of elements but elements are sorted by keys.
Objects in a TreeSet are stored in a sorted and ascending order.
TreeSet does not allow to insert Heterogeneous objects. It will throw classCastException at Runtime if trying to add hetrogeneous objects.
Comparator is note provided for TreeSet.
List listNames = new ArrayList();
listNames.add("Tom");
listNames.add("Mary");
listNames.add("Peter");
String name2 = (String) listNames.get(1);
System.out.println(name2);
What is the output of the above code
Tom
Mary
Peter
raises Exception
When do we use sets in java program?
To allow null and duplicate elements
You want to store elements distinctly without duplication, or unique elements.
to allow t contain duplicate keys and each key can map to at most one value
To perform lookups by keys
What will happen if an element already present in the Set is added again?
Run time error will be generated
No error, the element will be added once again to the set
Compile time error
A boolean value of false will be returned, and the value will not be added to the Set
Which of the following interfaces are not a part of the Java's Collection Framework?
SortedList
Set
SortedMap
List
Which of the following interfaces must contain a unique element?
List
Set
Array
Collection
Which of the following statements are true with respect to a stack?
A Stack is implemented in the "first-in, first-out" (FIFO) order.
A Stack is implemented in the "first-in, last-out" (FILO) order.
A Stack supports random access.
None of these.
Which of the following classes implement the Queue interface?
HashSet
TreeSet
LinkedList
None of these
What is the list nums if it is initially [5, 3, 1] and the following code is executed?
nums.add(6);
nums.add(0, 4);
nums.remove(1);
[4, 3, 1, 6]
[5, 3, 1, 6]
[4, 3, 6]
[4, 5, 3, 6]
What will print when the following code executes?
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(7);
list.add(8);
list.add(9);
System.out.println(list.remove(0));
7
8
9
0
What is the output of the following code:
Stack <String> r=new Stack<>();
r.push("GEC");
r.push("CSE");
System.out.println(r instanceof Collection)
False
0
True
1
Which of the following statement is correct
Collection is an interface and Collections is a Class
Collection is a class and Collections is an interface
Both Collection and Collections are classes
Both Collection and Collections are Interfaces
What is the output of the following code:
HashMap<Integer,String> r=new HashMap<Integer,String>();
r.put(1,"hello");
r.put(2,"hai");
System.out.println(r instanceof Collection);
false
0
true
1
How to display HashMap keys
using keys() method
using entrySet() method
using keySet() method
using values() method
Maps and Sets are Synchronized
True
False
We cant predict
which of the following is wrapper class in java
Float
Integer
Double
all of above
Which one of the following statement is not true about the collection interface?
all methods defined in set interface are also defined in collection interface
list interface extends collection interface
set interface extends collection interface
all methods defined in list interface are also defined in collection interface
which one of the following is a legal decelration of a two- dimensional array of integers
int[] a[] = new int[5][];
int[5][5] a = new int[][];
int a = new int[5,5];
int[][] a = new int[][5];
which interface needs to be implemented in order to make an object seralized
clonnable
remote
seralizable
none of the above
which one of the following have elements in insertion order
sorted map
hashmap
linkedhashmap
treemap
Cat class extends Predator class.
Which of the following must be true?
A Cat object has access to all Predator variables and methods.
A Predator object has access to all Cat variables and methods.
Cat c = new Predator();
causes an error.
Predator p = new Cat();
p has access to Cat methods and uses the Predator implementations.
