Computer Knowledge
Java Core Classes and Threads
1,473 Questions
Java core classes and threads form the foundation of object oriented programming and are crucial for IT officer and programming exams. This includes concepts like string mutability, collections, and multithreading. Solve these questions to test your practical coding and theoretical knowledge.
String and StringBuffer classesThread execution methodsJava collections frameworkCharacter streams input outputVariable serialization rules
Java Core Classes and Threads Questions
-
Min(c : collection)
-
Shuffle(list)
-
Frequency(c : collection, o : object)
-
Copy(destination, source)
-
Merge(c : collection, c1 : collection)
E
Correct answer
Explanation
This is the correct answer because there is no method named Merge(c : collection, c1 : collection) in Collections class.
-
nextIndex()
-
addAll()
-
IndexOf()
-
listIterator()
-
subList(startindex,endindex)
A
Correct answer
Explanation
This is the correct answer. nextIndex() method is present in the ListIterator interface in Java Collections. This method returns the index of the next element in the list to be traversed. So, this is the correct answer.
-
equals(String s)
-
compareToIgnoreCase(String s1)
-
compareTo(String s3)
-
Both (2) and (3)
-
All of the above
E
Correct answer
Explanation
As all of the functions are defined in the String class, so this is the correct answer.
-
removeAllElements()
-
element()
-
removeLast()
-
get(index : int)
-
set(index,element)
A
Correct answer
Explanation
This is the correct choice. removeAllElements() method is present in Vector class and is used to remove all the elements from the vector.
-
descendingMap()
-
firstEntry()
-
floorEntry(K key)
-
headMap(K toKey)
-
fixedMap()
E
Correct answer
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. So, this answer is correct.
-
containsKey(object)
-
containValue(object)
-
getKey(object)
-
keysSet(object)
-
removeKey(object)
A
Correct answer
Explanation
This is the correct answer.
containsKey(object) method is present in the Map interface in Java collections framework. This method returns true if this Map contains a mapping for a specified key. So, this is the correct answer.
-
putAll(map : m)
-
Get(key : K)
-
isEmpty()
-
removeLast()
-
put(Key : K, Value : V)
D
Correct answer
Explanation
This is the correct choice because removeLast() method is not present in the Map interface. It is present in LinkedList class. This method removes the last element from the list.
-
putIfAbsent(K key, V value)
-
replace(K key, V oldValue, V newValue)
-
replace(K key, V value)
-
containsValue(Object value)
-
None of these
E
Correct answer
Explanation
As explained, all the given methods can be invoked from the object of ConcurrentHashMap class. So, this is the correct choice.
-
poll()
-
offer(E e)
-
contains(object : o)
-
Both (1) and (2)
-
All of the above
E
Correct answer
Explanation
As explained, all the methods are present in the PriorityQueue class. So, this answer is correct.
-
containsKey(object)
-
containsValue(object)
-
Get(key : K)
-
Put(key : K, Value : V)
-
setValue(Value : V)
E
Correct answer
Explanation
This is the correct choice 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.
-
higherEntry(K key)
-
pollLastEntry()
-
descendingKeySet()
-
Both (1) and (3)
-
All of the above
E
Correct answer
Explanation
As explained, all the methods can be invoked from the TreeMap object. So, this answer is correct.
-
retainAll(Collection<!--?--> c)
-
containsAll(Collection<!--?--> c)
-
toArray(T[] a)
-
firstEntry()
-
equals(Object o)
D
Correct answer
Explanation
This is the correct choice because firstEntry() method is not present in the 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.
D
Correct answer
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 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 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 specified initial capacity, load factor and concurrencyLevel
5) ConcurrentHashMap(Map m): creates a new map with the same mappings as the given map
-
copyInto(array : Object[])
-
removeFirst()
-
lastIndexOf(element : e)
-
addLast(object)
-
Set(int index, element e)
A
Correct answer
Explanation
This is the correct answer.
copyInto(array : Object[]) method is present in the Vector class and it copies the elements in this vector to an array.
D
Correct answer
Explanation
This is the correct choice because there are 3 constructors of LinkedHashMap class. These are:LinkedHashMap(): creates a default Map with default initial capacity and loadfactor
LinkedHashMap(Map : m): creates a map with the existing map m
LinkedHashMap(int capacity, float loadfactor, Boolean accessorder): creates a map with specified initial capacity, load factor and access order of elements