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
-
isDigit()
-
isLetter()
-
isLetterOrDigit()
-
All of the above
-
None of these
D
Correct answer
Explanation
All of the methods given are defined in the character class. So this is the correct choice.
-
-
11
-
6
-
Compiler error : method lastIndexOf() not declared
-
Compiler error : parameters to method not sufficient
A
Correct answer
Explanation
lastIndexOf(String s, index i) method return the last occurrence of string "s" before the index value i. it Return -1 if string not found. So here the string to find is “Java” before the index value 5 which means before the character "m". but string “java” is not present before the index 5 i.e character "m" .so it will return -1. So this is the correct answer.
-
valueOf()
-
toCharArray()
-
toIntArray()
-
Both (1) and (2)
-
Both (1) and (3)
D
Correct answer
Explanation
Both 1 & 2 options are valid functions in Java. So this is the correct answer.
-
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.
C
Correct answer
Explanation
This is correct choice because the constructor of the Font class takes Three parameters:- First:- first parameter is of String type which specifies the name of the Font. Second:- second parameter is of type int which specifies the style of the font like Font.BOLD. Third:- third parameter is of type int which specifies the size of the font. ExampleFont f1 = new Font(“Serif”, Font.BOLD, 32); So, this option is true.