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
-
java.awt
-
java.swing
-
java.math
-
java.util
D
Correct answer
Explanation
The package java.util gives two very useful classes, i.e. Timer and TimerTask. These classes are used for conjunction.
-
Timer()
-
Timer(Boolean isDaemon)
-
Timer(String name)
-
Timer(char[] name)
D
Correct answer
Explanation
There are four constructors for a Timer class:
- Timer()
- Timer(Boolean isDaemon)
- Timer(String name)
- Timer(String name,Boolean isDaemon)
-
Only A
-
Only B
-
Both A and B
-
Neither A nor B
B
Correct answer
Explanation
A. The sleep() method is used to temporarily stop the execution of the thread.
B. The join() method is used to wait for this thread to die.
-
Destroy this thread, without any clean-up
-
Destroy this thread, with clean-up
-
Destroy all threads, without any clean-up
-
Destroy all threads, with clean-up
A
Correct answer
Explanation
The destroy() method of thread class destroys this thread, without any clean-up.
-
java.awt
-
java.swing
-
java.lang
-
java.util
C
Correct answer
Explanation
The package java.lang defines a class Throwable.
-
ArrayIndexOutOfBoundsException
-
ArrayIndexOutOfBoundsExceptions
-
ArrayIndexOutOfBoundException
-
ArrayOutOfBoundsException
A
Correct answer
Explanation
The ArrayIndexOutOfBoundsException occurs if one is trying to access an element of array with an index that is larger than the range.
For example:
int Num[]={0,2,3};
Num[5]=0; /This statement throws the exception/
-
ArithmeticException
-
ArrayStoreException
-
SecurityException
-
ClassCastException
D
Correct answer
Explanation
The exception ClassCastException is not a sub-class of RuntimeException.
A
Correct answer
Explanation
An instance of ThreadDeath is thrown in the victim thread when the stop method is called with zero arguments in class Thread.
-
int
-
void
-
char
-
static void
B
Correct answer
Explanation
The return type of start() method is void, i.e. void start().
-
A method is called on that object
-
A member variable is set for that object
-
A text string is assigned to the object.
A
Correct answer
Explanation
In object-oriented programming, sending a message to an object is the mechanism by which an operation is invoked. This results in the execution of a method defined within that object's class.
-
try.....catch()
-
try.....except()
-
if.....except()
-
if....else.....
B
Correct answer
Explanation
Python uses the try and except blocks to handle exceptions during program execution.
-
must be initialized
-
cannot be deleted
-
cannot be changed
-
None of the above
C
Correct answer
Explanation
Immutability in Java means that once a String object is created, its internal state (the sequence of characters) cannot be changed.
-
the Java Virtual Machine
-
code in a try block
-
calls from a try block to other methods
-
All of the above
D
Correct answer
Explanation
Exceptions can be thrown by the JVM (e.g., NullPointerException), by explicit throw statements in code, or by methods called within a try block.
-
throws IoException, WidgetException
-
catch IOException, WidgetException
-
throws Exception, WidgetException
-
throws WidgetException. IOException
-
addMouseListener
-
addListener
-
addObjectListener
-
addActionListener
D
Correct answer
Explanation
In Java Swing, the ActionListener interface is specifically designed to handle action events, such as clicking a button. The addActionListener method registers an object to receive these events.