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.
| No. | Answer | Remark | |
|---|---|---|---|
| 1 | b c h | notify notifyAll wait | |
| 2 | e g | sleep yield | |
| 3 | d h i | resume stop suspend | For the purposes of the exam, you don't need to memorize the deprecated methods of the Thread class. Even though a question such as this will not be on the exam, every Java programmer should know that the deprecated methods should not be used in new programs. |
| 4 | a e h | join sleep wait | |
| 5 | a e h | join sleep wait | |
| 6 | b c f | notify notifyAll wait | |
| 7 | d | InterruptedException |
The methods
|
| 8 | b | A member variable that is an object reference | Primitives don't have locks; therefore, they can not be used to synchronize threads. A method local variable that is a reference to an instance that is created within the method should not be used to synchronize threads, because each thread has its own instance of the object and lock. Synchronization on an instance that is created locally makes about as much sense as placing on your doorstep a box full of keys to the door. Each person that comes to your door would have their own copy of the key; so the lock would provide no security. |
| 9 | b e f g h i | A compile-time error occurs if the expression produces a value of any primitive type If execution of the block completes normally, then the lock is released If execution of the block completes abruptly, then the lock is released A thread can hold more than one lock at a time Synchronized statements can be nested Synchronized statements with identical expressions can be nested | |
| 10 | a | The process of executing a synchronized method requires the thread to acquire a lock | The synchronized modifier can not be applied to a class. A method that overrides a synchronized method does not have to be synchronized. If a thread invokes a synchronized instance method on an instance of class A, then the thread must acquire the lock of that instance of class A. The same is not true for synchronized static methods. A synchronized static method is synchronized on the lock for the Class object that represents the class for which the method is a member. |
| 11 | c d e f | The Ready state to the Running state The Running state to the Not-Runnable state The Running state to the Ready state The Not-Runnable state to the Ready state | A dead thread can not be restarted. |
| 12 | b c d f | The |
The
|
| 13 | a |
|
The
|
| 14 | e | None of the above | A dead thread can not be restarted. |
| 15 | b | Ready | |
| 16 | b d e h | The |
The
|
| 17 | a c f |
| |
| 18 | b d | A program will terminate only when all user threads stop running A thread inherits its daemon status from the thread that created it | |
| 19 | a | Prints: A |
If a
Runnable
target object is passed to the constructor of the
Thread
class, then the
|
| 20 | e | Prints: T1T1T3 |
The |
| 21 | e | Compile-time error |
The
|
| 22 | e | An IllegalThreadStateException is thrown at run-time | For the purposes of the exam, invoking the start method on a thread that has already been started will generate an IllegalThreadStateException. The actual behavior of the method might be different. If the start method is invoked on a thread that is already running, then an IllegalThreadStateException will probably be thrown. However, if the thread is already dead then the second attempt to start the thread will probably be ignored, and no exception will be thrown. For the purposes of the exam, the exception is always thrown in response to the second invocation of the start method. This is a case where the exam tests your knowledge of the specification and ignores the actual behavior of the 1.4 version of the JVM. |