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
-
void printStackTrace( )
-
String getMessage( )
-
String toString( )
-
void printStackTrace(PrintWriter stream)
-
String getLocalizedMessage( )
B
Correct answer
Explanation
Yes, this method returns a description of the exception.
-
There should be a catch block to execute finally clause.
-
Finally block is executed only when there is an exception in a program.
-
JVM always executes finally block before terminating the program.
-
Finally block can be put before catch block.
-
Finally block can handle the exception in the code.
C
Correct answer
Explanation
JVM executes finally block just before terminating the program to close the connection and resources.
-
charAt()
-
toCharArray()
-
getChars()
-
getBytes()
-
Both (1) and (2)
B
Correct answer
Explanation
This method converts all the characters in a String object into a character array.
-
start() method starts a thread by calling its run method.
-
run() is an entry point for the thread.
-
sleep() method temporarily suspends a currently executing thread.
-
isAlive() method determines if a thread is still running.
-
join() method waits for a thread to terminate.
C
Correct answer
Explanation
This is a false statement because sleep() method causes the currently executing thread to sleep for the specified number of milliseconds.
-
IllegalArgumentException
-
InterruptedException
-
IllegalMonitorStateException
-
IllegalStateException
-
UnsupportedOperationException
B
Correct answer
Explanation
sleep() method throws this exception.
-
insert()
-
delete()
-
replace()
-
trim()
-
charAt()
D
Correct answer
Explanation
trim() method is used to remove the blank spaces from both the ends of the invoking string.
-
Hashtable is synchronised.
-
A list can contain duplicate elements but a set cannot.
-
HashMap is used for non-threaded applications.
-
ArrayList dynamically increases or decreases in size.
-
ArrayList is synchronised.
E
Correct answer
Explanation
ArrayList is not synchronised.
-
void finalize( )
-
int hashCode( )
-
Object clone( )
-
int compareTo(Integer i)
-
void notify( )
D
Correct answer
Explanation
It is the method of Integer class.
-
It is not a method in Java.
-
By using this method, our program can obtain runtime type information about an object.
-
It is used for generalised routines samples.
-
Both (2) and (3)
-
None of the above
D
Correct answer
Explanation
Both are the properties of instanceOf method.
-
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.
-
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.
-
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.
-
ClassCastException
-
NullPointerException
-
ArrayIndexOutOfBoundsException
-
IllegalArgumentException
-
None of the above
D
Correct answer
Explanation
This is not a JVM exception. It is a programmatic exception.