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
-
Char
-
String
-
Int
-
Both (1) and (2)
-
All of the above
D
Correct answer
Explanation
Both char and string can be passed as the first parameter to the lastIndexOf() method. So this is the correct answer.
-
replace(char, char)
-
replaceAll(String, String)
-
append(String)
-
Both (1) and (2)
-
All of these
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.
A
Correct answer
Explanation
The correct answer is 16. When stringbuffer object is created the default capacity of the object is always 16. If the number of characters in the string increases, the capacity will increase with the following formula:-2 * (previous capacity + 1). In this case hello has 5 characters, so the default capacity will not change. Hence, this is correct.
-
equals(String s)
-
compareToIgnoreCase(String s1)
-
compareTo(String s3)
-
Both (2) and (3)
-
All of these
E
Correct answer
Explanation
All of the functions are defined in the String class. So this is correct answer.
-
Next()
-
nextLine()
-
nextInt()
-
nextChar()
-
nextLong()
D
Correct answer
Explanation
There is no function defined in Scanner class to take character input. So, there is no function named nextChar(). So, this is the correct answer.
-
IllegalArgumentException
-
NullPointerException
-
IOException
-
IndexOutOfBoundException
-
ArithmeticException
C
Correct answer
Explanation
IOException is not a subclass of RuntimeException class, this class is a Subclass of Exception class. This exception is thrown when invalid input/output are given. So, this is the correct answer as this is not a subclass of RuntimeException class.
-
FocusEvent
-
ComponentEvent
-
AdjustmentEvent
-
Both (2) and (3)
-
None of these
E
Correct answer
Explanation
As the reason explained all of the given event types are valid in java. So, this option is correct.
-
Wait()
-
Destroy()
-
Dead()
-
Both (1) and (3)
-
Both (1) and (2)
D
Correct answer
Explanation
As the reason is explained both methods in option 1 and 3 are not used by the web browser to control the applet. So, this option is correct.
-
setLocation(int, int)
-
setVisible(Boolean)
-
setSize(int, int)
-
setDefaultCloseOperation(int)
-
Pack()
D
Correct answer
Explanation
This function is not defined in the Frame class. This function is defined in JFrame class in Swings. So, this method cannot be invoked using the object of Frame class. But can be invoked using the Object of JFrame class. This method specifies the operation when the frame is closed. So, the following line would be false. Frame f1 = new frame(); f1.setDefaultCloseOperation(int); so, this is the correct answer.
-
windowMoved()
-
windowClosing()
-
windowIconified()
-
windowActivated()
-
windowDeiconified()
A
Correct answer
Explanation
If a class implements an interface then it is necessary for that class to define body to all the methods defined in the interface it is implementing. But, windowMoved() method is not present in windowListener interface. So, when a class will implement this interface this method need not to be define in the class. So, this option is correct.
-
fillRect()
-
fillCircle()
-
fillOval()
-
fillArc()
-
None of these
B
Correct answer
Explanation
This option is correct because there is no method defined fillCircle() in Graphics class. So, this option is correct.
-
JRadioButton
-
JCheckBox
-
JComboBox
-
JList
-
JTextField
D
Correct answer
Explanation
This is false choice because JList doesn’t generate an ActionEvent. When we click an item in JList ListSelectionEvent is generated. So, this is the true choice according to the question.
-
mouseEnetered()
-
keyReleased()
-
mouseDragged()
-
Both (1) and (2)
-
All of these
E
Correct answer
Explanation
This is correct answer because all of the given methods are valid in java event handling.
-
Robust
-
Interpreted
-
High Performance
-
Dynamic
-
None of the above
A
Correct answer
Explanation
This property in java ensures the compile time checking and runtime checking to reduce the chance of any error.
-
Synchronized
-
Volatile
-
Static
-
All of the above
-
Both (1) and (2)
E
Correct answer
Explanation
Both are used in threaded environment.