0

Computer Science

Description: Concept Based Questions
Number of Questions: 15
Created by:
Tags: Concept Based Questions Java Basics Computer Science & Information Technology - CS
Attempted 0/15 Correct 0 Score 0

Which of the following methods cannot be invoked with the object of ConcurrentHashMap class?

  1. putIfAbsent(K key, V value)

  2. replace(K key, V oldValue, V newValue)

  3. replace(K key, V value)

  4. containsValue(Object value)

  5. None of these


Correct Option: E
Explanation:

Option 5 is correct.

Which of the following methods cannot be invoked with the Object of TreeMap Constructor?

  1. descendingMap()

  2. firstEntry()

  3. floorEntry(K key)

  4. headMap(K toKey)

  5. fixedMap()


Correct Option: E
Explanation:

This is the correct answer. There is no method named FixedMap() in TreeMap class. So, this method cannot be invoked from Object of treemap class.

How many constructors of HashTable Class are there in java collections framework?

  1. 6

  2. 5

  3. 4

  4. 3

  5. 2


Correct Option: C
Explanation:

This is the correct answer, as there are 4 constructors of HashTable Class in java collections framework. These constructors are Hashtable, Hashtable(int initialCapacity, Hashtable(int initialCapacity, float loadFactor)Hashtable(Map t).

Which of the following methods can be invoked from the object of TreeMap Constructor?

  1. higherEntry(K key)

  2. pollLastEntry()

  3. descendingKeySet()

  4. Both (1) and (3)

  5. All of these


Correct Option: E
Explanation:

Yes, this is the correct answer.

Which of the following methods is present in the PriorityQueue class in Java?

  1. poll()

  2. offer(E e)

  3. contains(Object o)

  4. Both (1) and (2)

  5. All of these


Correct Option: E
Explanation:

Yes, this is the correct option.

How many constructors of TreeMap are there in java collections framework?

  1. 6

  2. 5

  3. 4

  4. 3

  5. 2


Correct Option: C
Explanation:

This is the correct answer. There are four constructors of TreeMap. These are :-TreeMap():- create an empty Map, TreeMap(Comparator comp):- The second form constructs an empty tree-based map that is sorted by using the Comparator comp, TreeMap(Map m):- The third form initialises a tree map with the entries from m, which is sorted by using the natural order of the keys, and TreeMap(SortedMap sm):- The fourth form initialises a tree map with the entries from sm, which is sorted in the same order as sm.

Which of the following methods is/are present in the Vector class?

  1. copyInto(array : Object[])

  2. removeFirst()

  3. lastIndexOf(element :e)

  4. addLast(object)

  5. Set(int index, element e)


Correct Option: A
Explanation:

This is the correct answer, as copyInto(array : Object[])Method is present in the Vector class and it copies the elements in this vector to an array.

Which of the following methods is not present in the map interface in java collections framework?

  1. containsKey(object)

  2. containsValue(object)

  3. Get(key : K)

  4. Put(key : K, Value : V)

  5. setValue(Value : V)


Correct Option: E
Explanation:

This is the correct option because setValue(Value : V) method is not present in the map interface, this method is present in the entry interface. This method replaces the value in this entry with a new specified value.

Which of the following methods are not present in Collection interface?

  1. retainAll(Collection c)

  2. containsAll(Collection c)

  3. toArray(T[] a)

  4. firstEntry()

  5. equals(Object o)


Correct Option: D
Explanation:

This is the correct choice because firstEntry() method is not present in Collection interface. It is used for map interface and its classes. This method returns a key-value mapping associated with the least key in this map, or null if the map is empty. So this is the correct choice.

Which of the following methods is present in map interface in java collections framework?

  1. getKey()

  2. getValue()

  3. setValue(Value : V)

  4. keyset()

  5. getKeys()


Correct Option: D
Explanation:

This is the correct answer, as Keyset() method is present in the map interface and it returns a set consisting of the keys in this map.

How many constructors of ConcurrentHashMap class are there in java collections framework?

  1. 8

  2. 7

  3. 6

  4. 5

  5. 4


Correct Option: D
Explanation:

This is the correct choice because there are 5 constructors of ConcurrentHashMap class. These are :- 1) ConcurrentHashMap():- Creates a new, empty map with a default initial capacity (16), load factor (0.75) and concurrencyLevel (16), 2) ConcurrentHashMap(int initialCapacity):- Creates a new, empty map with the specified initial capacity and with default load factor (0.75), and concurrencyLevel (16), 3) ConcurrentHashMap(int initialCapacity, float loadFactor):- Creates a new, empty map with the specified initial capacity and load factor and with the default concurrencyLevel (16), 4) ConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel):- Creates a new, empty map with the specified initial capacity, load factor and concurrency level, 5) ConcurrentHashMap(Map m):- Creates a new map with the same mappings as the given map.

How many constructors of LinkedHashMap class are there in java collections framework?

  1. 6

  2. 5

  3. 4

  4. 3

  5. 2


Correct Option: B
Explanation:

This is the correct answer, as there are 5 constructors of LinkedHashMap class. These are:- LinkedHashMap():- constructs an empty insertion-ordered LinkedHashMap instance with the default initial capacity (16) and load factor (0.75), LinkedHashMap(int initialCapacity):- constructs an empty insertion-ordered LinkedHashMap instance with the specified initial capacity and a default load factor (0.75), LinkedHashMap(int initialCapacity, float loadFactor):-  constructs an empty insertion-ordered LinkedHashMap instance with the specified initial capacity and load factor. LinkedHashMap(int initialCapacity, float loadFactor, boolean accessOrder):- constructs an empty LinkedHashMap instance with the specified initial capacity, load factor and ordering mode, and LinkedHashMap(Map<? extends K,? extends V> m):-  constructs an insertion-ordered LinkedHashMap instance with the same mappings as the specified map.

How many constructors of HashMap class are there in java collections framework?

  1. 6

  2. 5

  3. 4

  4. 3

  5. 2


Correct Option: C
Explanation:

This is correct, as there are 4 constructors of HashMap class. These are :-HashMap() :- Constructs an empty HashMap with the default initial capacity (16) and the default load factor (0.75). HashMap(int initialCapacity) :- Constructs an empty HashMap with the specified initial capacity and the default load factor (0.75). HashMap(int initialCapacity, float loadFactor) :- Constructs an empty HashMap with the specified initial capacity and load factor. HashMap(Map<? extends K,? extends V> m) :- Constructs a new HashMap with the same mappings as the specified Map.

Which of the following methods is present in map interface in java collections framework?

  1. boolean containsKey(object)

  2. containValue(object)

  3. getKey(object)

  4. KeysSet(object)

  5. removeKey(object)


Correct Option: A
Explanation:

This is the correct answer, as containsKey(object) method is present in the map interface in java collections framework. This method returns true if this map contains a mapping for the specified key. 

Which of the following methods are not present in Map interface?

  1. putAll(map : m)

  2. Get(key : K)

  3. isEmpty()

  4. removeLast()

  5. Put(key : K, Value : V)


Correct Option: D
Explanation:

This is incorrect, as removeLast()method is not present in the map interface, it is present in LinkedList class.This method removes the last element from the list.

- Hide questions