Java Multithreading and Exception Handling
Java Multithreading and Exception Handling
Questions
Which of the following methods is/are correct for making a new thread?
A. Declare a class to be a subclass of Thread class.
B. Declare a class that implements the Runnable class.
- Only A
- Only B
- Both A and B
- Neither A nor B
The code we want to execute has to be placed in a method ________ of the class which extends class Thread.
- start()
- run()
- first()
- exec()
Which one of the following is the correct structure to create and run a thread?
- class MyClass extends Runnable
{
public void run()
{
}
} - class MyClass implements Thread
{
public void run()
{
}
} - class Thread MyClass
{
public void run()
{
}
} - class MyClass extends Thread
{
public void run()
{
}
}
Which one of the following is not a correct state for life cycle of a thread?
- Ready
- Blocked
- Return
- Dead
When an allocated time of a thread is over, JRE puts it back in the _____ state.
- new
- ready
- running
- dead
Which one of the following is not a valid thread priority constant?
- MAX_PRIORITY
- MIN_PRIORITY
- NORM_PRIORITY
- AVG_PRIORITY
FirstTh th=new FirstTh();
Thread sm=new Thread(th).start();
Which of the following statements is correct with respect to the above code?
- FirstTh is a simple class.
- FirstTh is a class that inherits from Thread class.
- FirstTh is a class that implements from Thread class.
- FirstTh is a class that implements Runnable interface.
Which of the following methods makes the current thread to wait until other specified thread terminates?
- wait()
- join()
- notify()
- delay()
The methods wait(), notify() and notifyAll() must be called only when they own the monitor of that object, otherwise they throw __________________.
- IllegalMonitorException
- IllegalStateException
- IllegalMonitorStateException
- IllegalMonitorOwnStateException
The class Timer and TimerTask are available in the package __________.
- java.awt
- java.swing
- java.math
- java.util
Which one of the following is not a valid constructor of Timer class?
- Timer()
- Timer(Boolean isDaemon)
- Timer(String name)
- Timer(char[] name)
What is the use of purge() method in Timer class?
- Terminate this Timer
- Schedule the specified task for execution at the specified time
- Remove all cancelled tasks from this timer’s task queue
- Remove all running tasks from this timer’s task queue
Which of the following statements is/are correct?
A. The sleep() method is used to permanently stop the execution of the thread.
B. The join() method is used to wait for this thread to die.
- Only A
- Only B
- Both A and B
- Neither A nor B
Suppose a thread wants some input data. It cannot continue unless it is made available by the OS. Such a state is called a _________ state.
- ready
- blocked
- running
- dead
What is the use of destroy() method of thread class?
- 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
Which of the following correctly represents the exception?
- Compile error
- Syntax error
- Runtime error
- Not an error
Which of the following packages defines a class Throwable?
- java.awt
- java.swing
- java.lang
- java.util
Throwable class has two sub-classes, ________ and __________.
- Errors and Exceptions
- Error and Exceptions
- Errors and Exception
- Error and Exception
Java has defined a _______________ class which is a super-class for all runtime error classes.
- RuntimeExceptions
- RuntimeException
- Exception
- Throwable
The code which is likely to produce exception is kept within the ___________ block.
- catch
- try
- throw
- main()
A block labelled as finally will _________.
- never execute
- always execute
- execute if catch block will execute
- execute if catch block will not execute
The throw statement is used to throw the _____ type exception.
- class
- data
- object
- methods
Which of the following exceptions occurs, if one is trying to access an element of array with an index that is larger than the range?
- ArrayIndexOutOfBoundsException
- ArrayIndexOutOfBoundsExceptions
- ArrayIndexOutOfBoundException
- ArrayOutOfBoundsException
Which of the following exceptions is not a sub-class of RuntimeException?
- ArithmeticException
- ArrayStoreException
- SecurityException
- ClassCastException
An instance of ThreadDeath is thrown in the victim thread when the stop method is called with ____ arguments.
- 0
- 1
- 2
- 3
Which of the following statements is/are correct?
A. A finally block is optional.
B. throw and throws are the same.
- Only A
- Only B
- Both A and B
- Neither A nor B
What is the return type of start() method of class Thread?
- int
- void
- char
- static void
In Java, the concept of synchronisation is based on the concept of ___________.
- thread
- explicit lock
- intrinsic lock
- deadlock