The pages of this web site are not formatted to conserve paper, but my new book (ISBN: 0-9745862-0-X) is formatted to save paper, save your printer toner, and save money. If you prefer to work my exams from printed pages, then you can save a tree, save your printer toner, and save money if you buy my new book instead of attempting to print the pages of my web site.
Today, you can find my book on the retail web site of the company that prints it and distributes it.
Which of the following methods are members of the Object class?
| a. | join |
| b. | notify |
| c. | notifyAll |
| d. | run |
| e. | sleep |
| f. | start |
| g. | yield |
| h. | wait |
Which of the following methods are static members of the Thread class?
| a. | join |
| b. | notify |
| c. | notifyAll |
| d. | run |
| e. | sleep |
| f. | start |
| g. | yield |
| h. | wait |
Which of the following methods are deprecated members of the Thread class?
| a. | join |
| b. | notify |
| c. | notifyAll |
| d. | resume |
| e. | run |
| f. | sleep |
| g. | start |
| h. | stop |
| i. | suspend |
| j. | yield |
| k. | wait |
Which of the following methods name the InterruptedException in its throws clause?
| a. | join |
| b. | notify |
| c. | notifyAll |
| d. | run |
| e. | sleep |
| f. | start |
| g. | yield |
| h. | wait |
A timeout argument can be passed to which of the following methods?
| a. | join |
| b. | notify |
| c. | notifyAll |
| d. | run |
| e. | sleep |
| f. | start |
| g. | yield |
| h. | wait |
Which of the following instance methods should only be called by a thread that holds the lock of the instance on which the method is invoked?
| a. | join |
| b. | notify |
| c. | notifyAll |
| d. | run |
| e. | start |
| f. | wait |
Which of the following is a checked exception?
| a. | IllegalMonitorStateException |
| b. | IllegalThreadStateException |
| c. | IllegalArgumentException |
| d. | InterruptedException |
| e. | None of the above |
Which kind of variable would you prefer to synchronize on?
| a. | A member variable of a primitive type |
| b. | A member variable that is an object reference |
| c. | A method local variable that is a reference to an instance that is created within the method |
| d. | None of the above |
synchronized (expression) block
The synchronized statement has the form shown above. Which of the following are true statements?
| a. | A compile-time error occurs if the expression produces a value of any reference type |
| b. | A compile-time error occurs if the expression produces a value of any primitive type |
| c. | A compile-time error does not occur if the expression is of type boolean |
| d. | The sychronized block may be processed normally if the expression is null |
| e. | If execution of the block completes normally, then the lock is released |
| f. | If execution of the block completes abruptly, then the lock is released |
| g. | A thread can hold more than one lock at a time |
| h. | Synchronized statements can be nested |
| i. | Synchronized statements with identical expressions can be nested |
Which of the following is a true statement?
| a. | The process of executing a synchronized method requires the thread to acquire a lock |
| b. | Any overriding method of a synchronized method is implicitly synchronized |
| c. | If any method in a class is synchronized, then the class itself must also be declared using the synchronized modifier |
| d. | If a thread invokes a static synchronized method on an instance of class A, then the thread must acquire the lock of that instance of class A |
| e. | None of the above |
Which of the following thread state transitions model the lifecycle of a thread?
| a. | The Dead state to the Ready state |
| b. | The Ready state to the Not-Runnable state |
| c. | The Ready state to the Running state |
| d. | The Running state to the Not-Runnable state |
| e. | The Running state to the Ready state |
| f. | The Not-Runnable state to the Ready state |
| g. | The Not-Runnable state to the Running state |
Which of the following are true statements?
| a. | The |
| b. | The |
| c. | The same thread might continue to run after calling the |
| d. | The |
| e. | The behavior of the |
| f. | The |
| g. | The |
Which of the following will not force a thread to move into the Not-Runnable state?
| a. |
|
| b. |
|
| c. |
|
| d. |
|
| e. | By blocking on I/O |
| f. | Unsuccessfully attempting to acquire the lock of an object |
| g. | None of the above |
Which of the following will cause a dead thread to restart?
| a. |
|
| b. |
|
| c. |
|
| d. |
|
| e. | None of the above |
When a thread is created and started, what is its initial state?
| a. | New |
| b. | Ready |
| c. | Not-Runnable |
| d. | Runnning |
| e. | Dead |
| f. | None of the above |
Which of the following are true statements?
| a. | The |
| b. | The |
| c. | The Runnable interface declares the start method |
| d. | The Runnable interface declares the run method |
| e. | The Thread class implements the Runnable interface |
| f. | If an |
| g. | No restriction is placed on the number of threads that can enter a synchronized method |
| h. | Some implementations of the |
Which of the following are true statements?
| a. |
|
| b. |
|
| c. |
|
| d. |
|
| e. |
|
| f. |
|
| g. |
|
| h. |
|
| i. |
|
Which of the following are true statements?
| a. | A program will terminate only when all daemon threads stop running |
| b. | A program will terminate only when all user threads stop running |
| c. | A daemon thread always runs at |
| d. | A thread inherits its daemon status from the thread that created it |
| e. | The daemon status of a thread can be changed at any time using the |
| f. | The |
class A extends Thread {
public A(Runnable r) {super(r);}
public void run() {System.out.print("A");}
}
class B implements Runnable {
public void run() {System.out.print("B");}
}
class C {
public static void main(String[] args) {
new A(new B()).start();
}}
What is the result of attempting to compile and run the program?
| a. | Prints: A |
| b. | Prints: B |
| c. | Prints: AB |
| d. | Prints: BA |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
class A implements Runnable {
public void run() {System.out.print(Thread.currentThread().getName());}
}
class B implements Runnable {
public void run() {
new A().run();
new Thread(new A(),"T2").run();
new Thread(new A(),"T3").start();
}}
class C {
public static void main (String[] args) {
new Thread(new B(),"T1").start();
}}
What is the result of attempting to compile and run the program?
| a. | Prints: T1T1T1 |
| b. | Prints: T1T1T2 |
| c. | Prints: T1T2T2 |
| d. | Prints: T1T2T3 |
| e. | Prints: T1T1T3 |
| f. | Prints: T1T3T3 |
| g. | Compile-time error |
| h. | Run-time error |
| i. | None of the above |
class AnException extends Exception {}
class A extends Thread {
public void run() throws AnException {
System.out.print("A"); throw new AnException();
}}
class B {
public static void main (String[] args) {
A a = new A(); a.start(); System.out.print("B");
}}
What is the result of attempting to compile and run the program?
| a. | Prints: A |
| b. | Prints: B |
| c. | Prints: AB |
| d. | Prints: BA |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
class A extends Thread {
public void run() {System.out.print("A");}
}
class B {
public static void main (String[] args) {
A a = new A();
a.start();
a.start(); // 1
}
}
What is the result of attempting to compile and run the program?
| a. | The program compiles and runs without error |
| b. | The second attempt to start thread t1 is successful |
| c. | The second attempt to start thread t1 is ignored |
| d. | Compile-time error at marker 1 |
| e. | An IllegalThreadStateException is thrown at run-time |
| f. | None of the above |