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

Multiple choice
  1. 6

  2. 5

  3. 4

  4. 3

  5. 2

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

This is the correct answer, there are four constructors of WeakHashMap in java. These are: 1) WeakHashMap(): Constructs a new, empty WeakHashMap with the default initial capacity (16) and load factor (0.75). 2) WeakHashMap(int initialCapacity):-Constructs a new, empty WeakHashMap with the given initial capacity and the default load factor (0.75). 3) WeakHashMap(int initialCapacity, float loadFactor):-Constructs a new, empty WeakHashMap with the given initial capacity and the given load factor. 4) WeakHashMap(Map m): Constructs a new WeakHashMap with the same mappings as the specified map. So, this is the correct answer.

Multiple choice
  1. setTextVerticalPosition(int textPosition)

  2. setSelectedRolloverIcon(Icon rolloverSelectedIcon)

  3. setTextHorizontalPosition(int textPosition)

  4. setDisplayedMnemonicIndex(int index)

  5. setTextGap(int iconTextGap)

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

This is the correct choice because setDisplayedMnemonicIndex(int index)Method Provides a hint to the look and feel as to which character in the text should be decorated to represent the mnemonic and this method is present in AbstractButton class. So, this answer is correct.

Multiple choice
  1. setRolloverEnabled(boolean)

  2. setPressedIcon(Icon)

  3. setDisabledIcon(Icon)

  4. setSelectedIcon(Icon)

  5. setSelectedRolloverIcon(Icon)

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

This is the correct answer because there is no method named setSelectedRolloverIcon(Icon). The correct method name is setRolloverSelectedIcon(Icon), this method lets you specify the rollover icon when the button is selected. This is useful for two-state buttons such as toggle buttons. So, this is a correct choice.

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, as copyInto(array : Object[])Method is present in the Vector class and it copies the elements in this vector to an array.

Multiple choice
  1. containsKey(object)

  2. containsValue(object)

  3. Get(key : K)

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

  5. setValue(Value : V)

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

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 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.