Computer Knowledge

Java Core Classes and Threads

1,935 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

Multiple choice
  1. retainAll(Collection<!--?--> c)

  2. containsAll(Collection<!--?--> c)

  3. toArray(T[] a)

  4. firstEntry()

  5. equals(Object o)

Reveal answer Fill a bubble to check yourself
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.

Multiple choice
  1. 8

  2. 7

  3. 6

  4. 5

  5. 4

Reveal answer Fill a bubble to check yourself
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

Multiple choice
  1. copyInto(array : Object[])

  2. removeFirst()

  3. lastIndexOf(element : e)

  4. addLast(object)

  5. Set(int index, element e)

Reveal answer Fill a bubble to check yourself
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. 

Multiple choice
  1. 6

  2. 5

  3. 4

  4. 3

  5. 2

Reveal answer Fill a bubble to check yourself
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