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
-
getPercentComplete()
-
setBorderPainted(boolean)
-
setPaintedBorder(boolean)
-
isStringPainted(boolean)
-
setMinimum(int)
C
Correct answer
Explanation
This the correct choice because there is no method name setPaintedBorder() in JProgressBar class. The correct method is setBorderPainted which Set the progress bar with a border. So, this answer is true.
-
getComponentCount()
-
getTopLevelAncestor()
-
getPane()
-
Both 1 and 2
-
All of the above
D
Correct answer
Explanation
As I explained that both the options 1 and 2 are correct, so this answer is true.
-
replace(char , char)
-
replaceAll(String , String)
-
append(String)
-
Both 1 and 2
-
All of the above
C
Correct answer
Explanation
This is the correct answer. Because the String class objects are immutable i.e once the object of the String class is created its contents cannot be changed.
So, we cannot append new characters or string in the old string. So, this is the correct answer.
-
isWheelScrollingEnabled()
-
isScrollingWheelEnabled()
-
getScrollsOnExpand()
-
Both 1 and 2
-
Both 1 and 3
E
Correct answer
Explanation
As I explained both the methods of option 1 and 3 are valid in JScrollPane class. So, this answer is true.
-
isShowing()
-
getLocationOnScreen()
-
getInsets()
-
isOpaque()
-
isCircle()
E
Correct answer
Explanation
This is the correct choice. There is no method named isCircle() present in JComponenet class in java. So, this is the correct choice.
-
indexOfTabComponent(Component)
-
getTabComponentAt(int)
-
setTabComponentAt(int, Component)
-
Both 2 and 3
-
All of these
E
Correct answer
Explanation
As I explained all the methods are present in the JTabbedPane class. So, this answer is correct.
-
getAllowsInvalid()
-
getOverwriteMode()
-
setCommitsOnValidEdit(boolean)
-
Both 1 and 2
-
All of the above
E
Correct answer
Explanation
As I explained that all the methods given are present in JFormattedTextField class. So, this answer is true.
-
getComponentGraphics(Graphics g)
-
isLightweightComponent(Component c)
-
isPaintingTile()
-
isPaintingForPrint()
-
isPrinting()
E
Correct answer
Explanation
This is the correct answer, there is no method named isPrinting() in JComponent class in java. So, this answer is correct.
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.
-
setTextVerticalPosition(int textPosition)
-
setSelectedRolloverIcon(Icon rolloverSelectedIcon)
-
setTextHorizontalPosition(int textPosition)
-
setDisplayedMnemonicIndex(int index)
-
setTextGap(int iconTextGap)
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.
-
setRolloverEnabled(boolean)
-
setPressedIcon(Icon)
-
setDisabledIcon(Icon)
-
setSelectedIcon(Icon)
-
setSelectedRolloverIcon(Icon)
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.
-
putIfAbsent(K key, V value)
-
replace(K key, V oldValue, V newValue)
-
replace(K key, V value)
-
containsValue(Object value)
-
None of these
-
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.
-
higherEntry(K key)
-
pollLastEntry()
-
descendingKeySet()
-
Both (1) and (3)
-
All of these
E
Correct answer
Explanation
Yes, this is the correct answer.
-
poll()
-
offer(E e)
-
contains(Object o)
-
Both (1) and (2)
-
All of these
E
Correct answer
Explanation
Yes, this is the correct option.