Font size
WorksheetsSec BCD 14-7-2023 Quiz-1
Total questions: 134
Worksheet time: 1hrs 7mins
-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.
Which of these classes provides the specified features?
LinkedList
TreeMap
HashSet
LinkedHashMap
HashMap
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
{null=null, a=null, b=JavaSE, c=PHP, d=Python}
{a=null, b=JavaSE, c=PHP, d=Python}
{b=JavaSE, c=PHP, d=Python}
Compilation Fails
4
5
6
12
-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
[Computer, Network, Networks, Programming, Security]
[Computer, Programming, Network, Networks, Programming, Security]
[Computer, Programming, Computer, Networks, Network, Security]
[Computer, Networks, Network, Programming, Security]
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
What is Collection in Java?
A group of objects
A group of classes
A group of interfaces
None of the mentioned
Which of these interface is not part of Java’s collection framework?
List
Sorted List
Set
Sorted Map
What will be the output of the Java program?
{0, 1, 3, 4}
{0, 1, 2, 4}
{0, 1, 2, 3, 4}
{0, 0, 0, 3, 4}
Which of these return type of hasNext() method of an iterator?
Integer
Double
Boolean
Collections Object
Which of these methods deletes all the elements from invoking collection?
clear();
reset();
delete();
remove();
Which of the following statements are true with respect to sets as objects of Hashset?
Set is always an ordered group of objects.
Set allows duplicate objects.
Set does not allow duplicate objects.
Set supports iterators.
Which of the following statements are correct in relation to collections in Java?
A collection can have objects of different types in it.
The Collection is a class.
A collection can have only one type of object in it.
A collection is same as a standard array.
Which of the following interfaces declares a core method that all collections will have?
EventListener
Comparator
Set
Collection
Which of the following statements are correct with respect to a Map in Java?
A map can have iterators for accessing its elements.
The elements of a map are accessed by the respective keys.
Maps are the same as a SortedSet.
None of these.
Which of the following interfaces are not a part of the Java's Collection Framework?
SortedList
Set
SortedMap
List
Which of the following statements are correct with respect to a List in Java?
A List is implemented in the "first-in, first-out" (FIFO) order.
A List is implemented in the "first-in, last-out" (FILO) order.
Lists support duplicate items.
None of these.
Which of the following interfaces must contain a unique element?
List
Set
Array
Collection
Which of the following method deletes all the elements from invoking (calling) collections?
reset()
clear()
delete()
refresh()
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 Collection in Java?
A group of objects
A group of classes
A group of interfaces
None of the mentioned
Which of these interface is not part of Java’s collection framework?
List
Sorted List
Set
Sorted Map
What will be the output of the Java program?
{0, 1, 3, 4}
{0, 1, 2, 4}
{0, 1, 2, 3, 4}
{0, 0, 0, 3, 4}
Which of these return type of hasNext() method of an iterator?
Integer
Double
Boolean
Collections Object
Which of these exceptions is thrown by remover() method?
IOException
SystemException
ObjectNotFoundExeception
IllegalStateException
Which of these methods deletes all the elements from invoking collection?
clear();
reset();
delete();
remove();
Which of these interface declares core method that all collections will have?
Collection
EventListner
Comparator
Set
List
Which of these is an incorrect form of using method max() to obtain maximum element?
max(Collection c)
max(Collection c, Comparator comp)
max(Comparator comp)
max(List c)
Which of these methods can convert an object into a List?
SetList()
ConvertList()
CopyList()
singletonList()
Which of these is true about unmodifiableCollection() method?
unmodifiableCollection() returns a collection that cannot be modified.
unmodifiableCollection() method is available only for List and Set.
unmodifiableCollection() is defined in Collection class.
None of the mentioned.
Which of these is static variable defined in Collections?
EMPTY_SET
EMPTY_LIST
EMPTY_MAP
All of the mentioned
What implementation of Iterator can traverse a collection in both directions?
Iterator
ListIterator
SetIterator
MapIterator
Which is faster and uses less memory?
ListEnumeration
Iterator
Enumeration
ListIterator
What will be output of given code
a followed by concurrentModification Exception
a b c
a b
a c
Which interface does java.util.Hashtable implement?
Java.util.Map
Java.util.List
Java.util.HashTable
Java.util.Collection
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?
java.util.Map
java.util.Set
java.util.List
java.util.Collection
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?
java.util.Map
java.util.Set
java.util.List
java.util.Collection
Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?
java.util.HashSet
java.util.LinkedHashSet
java.util.List
java.util.ArrayList
The default capacity of a Vector is:
10
12
8
0
The Comparable interface contains which called?
toCompare
compare
compareTo
compareWith
Find the output
public class TreeMapTest {
public static void main(String args[]) {
Map<Integer, String> m = new TreeMap<Integer, String>();
m.put(11, "audi");
m.put(null, null);
m.put(11, "bmw");
m.put(null, "ferrari");
System.out.println(m.size());
System.out.println(m);
}
Nullpointer exception
compiler error
2
Null value
public class MyClass {
public static void main(String args[]) {
Map<String, String> hashMap = new HashMap<String, String>();
hashMap.put(new String("a"), "audi");
hashMap.put(new String("a"), "ferrari");
System.out.println(hashMap);
}
}
a=audi
a=audi
a=ferrari
a=ferrari
Run time Error
Deque and Queue are derived from
Abstract class
Collection
Abstactcollection
List
What will be output of given code
1 2 3
1 followed by exception
Compile time error
run time error
Which is best suited to a multi-threaded environment?
WeakHashMap
Hashtable
HashMap
ConcurrentHashMap
TreeMap implements?
Dictionary
HashMap
AbstractMap
NavigableMap
Which of these is synchronized?
TreeMap
HashMap
Hashtable
All of the above
TreeMap
doesn't allow null key
allow many null values
Both
allow many null key
How can you sort given HashMap on basis of values
Implement Comparator interface and override its compare method
It is not possible
Implement Comparator interface and override its compareTo method
Implement Comparator interface and override its comparable method
What does Collections.sort internally uses when number of elements are less than 7?
Insertion sort
Merge sort
Quick sort
None
What does Collections.sort internally uses when number of elements are greater than 7?
Insertion sort
Merge sort
Quick sort
None
Which of these packages contain all the collection classes?
java.lang
java.util
java.net
java.awt
Which of these classes is not part of Java’s collection framework?
Maps
Array
Stack
Queue
Which of these methods deletes all the elements from invoking collection?
clear()
reset()
delete()
refresh()
What will be the output of the following Java program?
import java.util.*;
class Array {
public static void main(String args[]) {
int array[] = new int [5];
for (int i = 5; i > 0; i--)
array[5-i] = i;
Arrays.fill(array, 1, 4, 8);
for (int i = 0; i < 5 ; i++) System.out.print(array[i]);
} }
12885
12845
58881
54881
What will be the output of the following Java program?
import java.util.*;
class Bitset {
public static void main(String args[]) {
BitSet obj = new BitSet(5);
for (int i = 0; i < 5; ++i)
obj.set(i);
obj.clear(2);
System.out.print(obj);
} }
{0, 1, 3, 4}
{0, 1, 2, 4}
{0, 1, 2, 3, 4}
{0, 0, 0, 3, 4}
Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?
java.util.HashSet
java.util.LinkedHashSet
java.util.List
java.util.ArrayList
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?
java.util.Map
java.util.Set
java.util.List
java.util.Collection
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() + " " );
}
one two three four
four three two one
four one three two
one two three four one
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 */
}
}
Compilation will succeed.
Compilation will fail at line 3.
Compilation will fail at line 5.
Compilation will fail at line 15.
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);
}
}
Prints: false, false, false
Prints: false, false, true
Prints: false, true, false
Prints: false, true, true
-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.
Which of these classes provides the specified features?
LinkedList
TreeMap
HashSet
LinkedHashMap
HashMap
Which of the following statements are true with respect to sets as objects of Hashset?
Set is always an ordered group of objects.
Set allows duplicate objects.
Set does not allow duplicate objects.
Set supports iterators.
Which of the following interfaces declares a core method that all collections will have?
EventListener
Comparator
Set
Collection
Which of the following statements are correct with respect to a Map in Java?
A map can have iterators for accessing its elements.
The elements of a map are accessed by the respective keys.
Maps are the same as a SortedSet.
None of these.
Which of the following interfaces must contain a unique element?
List
Set
Array
Collection
Which of the following statements are correct with respect to a List in Java?
A List is implemented in the "first-in, first-out" (FIFO) order.
A List is implemented in the "first-in, last-out" (FILO) order.
Lists support duplicate items.
None of these.
We need to access elements frequently by using index...
Which one is better solution?
Set
List
Map
We want store data in form Key and Value... Whic one is better solution?
Set
List
Map
We want to create collection of unique elements without duplicates... Which one is better solution?
Set
List
Map
Contains no duplicate elements
Elements are not key-value pairs
Always unique elements
LinkedList
TreeMap
HashSet
HashMap
What does it mean for a list to be "dynamic" in ArrayList?
You can easily add and remove elements
It may contain multiple types of values
It has a set size once it has been created
You can access it from anywhere in the program
Collection Framework Comes under which package?
java.lang
java.io
java.util
java.applet
Which option is correct in the following collection interface hierarchy?
List,Set,Queue
List,Set,Map
List,Map
Map,Queue,Sey
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.
Collection Framework Comes under which package?
java.lang
java.io
java.util
java.applet
Which option is correct in the following collection interface hierarchy?
List,Set,Queue
List,Set,Map
List,Map
Map,Queue,Sey
When to use Linked List
To avoid Duplicates
Random access
For Fast Manipulation
None of the above
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, 6]
[5, 3, 1, 6]
[4, 3, 1, 6]
[4, 5, 3, 6]
Which statement below is the correct way to retrieve the first element in the nums ArrayList?
nums.get(0)
nums[0]
nums(0)
nums[1]
Each time you create a string literal, the JVM checks the ___ first
"String constant
pool"
"String contiguos
pool"
"Constant
pool"
"String reference
pool"
The ___ in Java is a framework that provides an architecture
to store and manipulate the group of objects
List
Collection
Array
Graph
String objects are ____ where as StringBuffer class is ____
immutable,
immutable
mutable,
immutable
immutable,
mutable
mutable,
mutable
The java string charAt() method returns
a char value at the 0th index
print charAt
print the index
a char value at the given
index number.
There are two ways to create String object:
String s = "welcome";
This is an example of creating an object
By string literal
By new keyword
By Welcome keyword
By Welcome keyword
String s1="Java";
String s2="Java";
• In the above example, how many object will be created.
1
2
3
4
What will be the output of the program ?
0, 19
10, 10
10, 0
19,19
There are three ways to compare string in java. They
1.equals() method
2. = = operator
3.compareTo() method
1. StrCompare
2. Equals
3. = operator
1. = operator
2. == orperator
3. Equals operator
1. = operator
2. comp operatoe
3. == operator
" = " operator and "==" operator is different. = operator is used to assign value where as == is used to___
compares values
compares references
save values
concatenate values
Wrong statement regarding contains() method is
Searches the sequence of
characters in this string.
It returns true if sequence of char values are found
Searches case sensitive char sequence
Not case sensitive char sequence
The java string charAt() method returns ___if given index number
is greater than or equal to this string length or a negative number
StringIndexOutOfBoundsException
OutOfBoundsException
No Exception
StringException
What will be the output after concatenation performed ?
Sachin
Tendulkar
Sachin Tendulkar
Tendulkar Sachin
Which is wrong ?????
1 • Java ArrayList class can't contain duplicate elements.
2 • Java ArrayList class maintains insertion order.
3 • Java ArrayList allows random access because array works at the index basis.
4 • In ArrayList, manipulation is little bit slower than the LinkedList in
Java because a lot of shifting needs to occur if any element is
removed from the array list.
1
2
3
4
The events can be broadly classified into two categories. They are
Foreground event
Background event
Topdown event
Bottum up event
Simple event
Complex event
Public event
Private event
The model defines the standard mechanism to generate and
handle the events is called ?
Delightful Event Model
Depletion Event Model
Delegation Event Model
Dedicated Event Model
A ____ program contains two or more parts that can run
concurrently and each part can handle a different task at the same
time making optimal use of the available resources specially when
your computer has multiple CPUs
multi-threaded
multi- programmed
multi-processing
multi-tasking
Threads are ___and ___processes within a process.
Dependent,
Havy wieght
Independent,
lightweight
Dependent,
Loosly weight
Independent,
Tightly weight
A thread can be in one of the five states..Which is not a state given below
1. New
2. Runnable
3. Running
4. Suspend
5. Terminated
2
3
4
5
What is the state of the Thread that waits to acquire the lock
of an object.
Sleeping
Blocked for I/O
Waiting for notification
Blocked for lock acquisition
The most two important methods in Java Multithreading concept are
Start()
run()
Start()
stop()
run()
resume()
run()
resolve()
The resume() method of thread class is only used with___method
The stop() method
The suspend() method
Run() Method
Synchronized method
Which method is used here to give new Names to the thread
run()
getName()
start()
setName()
Which of these packages contain all the collection classes?
java.lang
java.util
java.net
java.awt
Which of these classes is not part of Java’s collection framework?
Maps
Array
Stack
Queue
Which of this interface is not a part of Java’s collection framework?
List
Set
SortedMap
SortedList
Which of these methods deletes all the elements from invoking collection?
clear()
reset()
delete()
refresh()
What is Collection in Java?
A group of objects
A group of classes
A group of interfaces
None of the mentioned
What will be the output of the following Java program?
import java.util.*;class Array
{
public static void main(String args[])
{
int array[] = new int [5];
for (int i = 5; i > 0; i--)
array[5-i] = i;
Arrays.fill(array, 1, 4, 8);
for (int i = 0; i < 5 ; i++)
System.out.print(array[i]);
}
}
12885
12845
58881
54881
What will be the output of the following Java program?
import java.util.*;class Bitset
{
public static void main(String args[])
{
BitSet obj = new BitSet(5);
for (int i = 0; i < 5; ++i)
obj.set(i);
obj.clear(2);
System.out.print(obj);
}
}
{0, 1, 3, 4}
{0, 1, 2, 4}
{0, 1, 2, 3, 4}
{0, 0, 0, 3, 4}
Which of these return type of hasNext() method of an iterator?
Integer
Double
Boolean
Collections Object
Which of these methods is used to obtain an iterator to the start of collection?
start()
begin()
iteratorSet()
iterator()
Which of these methods can be used to move to next element in a collection?
next()
move()
shuffle()
hasNext()
Which of these iterators can be used only with List?
Setiterator
ListIterator
Literator
None of the mentioned
Which of these is a method of ListIterator used to obtain index of previous element?
previous()
previousIndex()
back()
goBack()
What will be the output of the following Java program?
import java.util.*;class Collection_iterators
{
public static void main(String args[])
{
LinkedList list = new LinkedList();
list.add(new Integer(2));
list.add(new Integer(8));
list.add(new Integer(5));
list.add(new Integer(1));
Iterator i = list.iterator();
Collections.reverse(list);
while(i.hasNext())
System.out.print(i.next() + " ");
}
}
2 8 5 1
1 5 8 2
2
2 1 8 5
What will be the output of the following Java program?
import java.util.*;class Collection_iterators
{
public static void main(String args[])
{
LinkedList list = new LinkedList();
list.add(new Integer(2));
list.add(new Integer(8));
list.add(new Integer(5));
list.add(new Integer(1));
Iterator i = list.iterator();
Collections.reverse(list);
Collections.sort(list);
while(i.hasNext())
System.out.print(i.next() + " ");
}
}
2 8 5 1
1 5 8 2
1 2 5 8
2 1 8 5
Which of these interfaces is not part of the collection framework in Java?
Collection
Set
Group
List
Which interface does not allow duplicates elements?
Set
List
Map
All the answers are true
Which of these collection classes has the ability to scale dynamically?
Array
Arrays
ArrayList
All the answers are true
HashMap allows _____________
null values
null key
All the answers are true
None
The Comparable interface contains which called?
toCompare
compare
compareTo
compareWith
Which is faster and uses less memory?
ListEnumeration
Iterator
Enumeration
ListIterator
Which does NOT implement the Collection interface?
List
Map
Set
None
The default capacity of a ArrayList is:
12
16
1
10
Which provides better performance for the insertion and removal from the middle of the list?
Vector
ArrayList
LinkedList
All
After resizing, size of ArrayList is increased by :
200%
50%
100%
Not Increase
After resizing, size of Vector is increased by:
200%
100%
50%
None
he default capacity of a ArrayList is:
12
16
1
10
Which is faster and uses less memory?
ListEnumeration
Iterator
Enumeration
ListIterator
