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 cartridge, save a loose-leaf binder, and save money. If you prefer to work my exams from printed pages, then give your printer a rest and buy my new book.
Today, you can find my book at BookSurge.com.
Are you a university student studying Java programming? Do you agree that my book would serve as a helpful workbook and companion to be used along with the Java fundamentals textbook that is currently being used in your class? If so, then please ask your professor to consider using my book in future classes.
If you have any questions or comments concerning my mock exams or my book, then please send an e-mail to me at scjpexam2000@yahoo.com.
I would also like to read your response to the following questions.
| No. | Answer | Remark | |
|---|---|---|---|
| 1 | c | Adds 0.5 to the argument and takes the floor of the result. | |
| 2 | f | None of the above |
If the
|
| 3 | a | It is not overloaded. | The argument and returned value are both of type double. If the argument is negative, then the returned value is NaN. |
| 4 | a c | It is not overloaded. The argument is an angle measured in radians. | The argument is of type double and represents an angle measured in radians. The returned value is of type double. The method does not throw any exceptions. |
| 5 | e | None of the above | The random method is not overloaded, does not declare any parameters and does not throw any exceptions. The returned value is greater than or equal to zero and is less than but not equal to one. |
| 6 | e | Returns the largest whole number that is less than or equal to the argument value. | The floor method is not overloaded, and declares only one parameter of type double. The return value is always of type double. The floor method does not declare any exceptions. |
| 7 | f | Returns the smallest whole number that is greater than or equal to the argument value. | The ceil method is not overloaded, and declares only one parameter of type double. The return value is always of type double. The ceil method does not declare any exceptions. |
| 8 | a c f | Four overloaded versions of abs exist. The type of the return value depends on the argument type. If the argument is positive, then the argument is returned. |
The method name
abs
is overloaded.
There are versions that accept one argument of
type
int,
long,
float
or
double.
The type of the return value is the same as the
argument type.
No exceptions are declared.
If the argument is a negative integral value, then the returned
value is the two's complement of the argument.
The magnitude of
|
| 9 | b c e f h | Positive infinity NaN Integer.MIN_VALUE Long.MIN_VALUE Positive zero |
The method name
abs
is overloaded.
There are versions that accept one argument of
type
int,
long,
float
or
double.
The type of the return value is the same as the
argument type.
The result is positive infinity if the argument is negative infinity.
The result is positive zero if the argument is negative zero.
The result is NaN if the argument is NaN.
If the argument is a negative integral value, then the returned
value is the two's complement of the argument.
The magnitude of
|
| 10 | c | Prints: -4.0,-3.0,3.0,4.0 |
The
|
| 11 | h | None of the above |
The
|
| 12 | a | Prints: 0,0 |
The
|
| 13 | e | volatile | A field might be shared between two or more threads. Each thread is allowed to maintain a working copy of the field. If the threads do not reconcile the working copies then each might be working with a different value. The volatile modifier is used to force each thread to reconcile its working copy of the field with the master copy in main memory. |
| 14 | a c | The first number printed is greater than or equal to 0 The second number printed must always be greater than 5000 | The notify method is never invoked on thread a1; so it will sleep for at least five seconds. The invocation of the join method forces the main thread to wait for the completion of thread a1. The argument of 6000 will allow the main thread to wait for six seconds if necessary, but we know that thread a1 will complete in only five seconds. The first number printed will be greater than or equal to zero, and the second number will be greater than or equal to 5000. The synchronized block is necessary, because it is necessary to hold the lock of an object when the wait method is invoked. |
| 15 | d | Prints: ABC |
The block inside the
main
method is synchronized on the
String
array object
sa.
Inside the block, a new thread
t1
is started and will run at the discretion of the
thread scheduler. The
|
| 16 | d | Prints: ABC |
Inside the
main
method, thread
t1
is started and will
move into the Running state at the discretion of the thread
scheduler. The
|
| 17 | b c d e h | The |
The
|
| 18 | b d | By entering a synchronized instance method of the obj1 By entering the body of a block that is synchronized on obj1 |
Blocking on I/O or invoking the
|
| 19 | a b d f | Another thread invokes the notify method on the object, obj1, and T1 is selected to move out of the wait set Another thread invokes the notifyAll method on the object Another thread interrupts thread T1 A specified timeout period has elapsed | |
| 20 | e | None of the above | All of the class instance creation expressions are legal. The String instance A is the name of the Thread. Yes, the exam requires you to memorize the Thread constructor signatures. |
| 21 | c | 3 | The position of the arguments have been reversed in the constructor on line 3. The Runnable argument should appear before the thread name argument. Yes, the exam requires you to memorize the Thread constructor signatures. |
| 22 | a | The number printed is greater than or equal to 0 | The main thread invokes the start method on thread a1. There is no way to predict when the new thread will start to run. At some point in time, the main thread will proceed to the print statement where the value of the startTime variable is subtracted from the current time. The value printed will be greater than or equal to one. At some point in time, thread a1 will begin to run and it will invoke the wait method. Since no other thread invokes the notify method on a1, it will wait forever, and the program will never run to completion. |
| 23 | a | The number printed is greater than or equal to 0 | The a1 thread is a daemon thread; so the program can run to completion even if thread a1 is still running, waiting or sleeping. The notify method is never invoked on thread a1. If thread a1 were not a daemon thread, then the program would wait forever. However, the program will run to completion without waiting for a1. |
| 24 | b c | Some or all of the numbers 0 through 9 could be printed Nothing is printed |
All of the threads started in method
|
| 25 | e | Compile-time error |
Remember that the
|
| 26 | e | Compile-time error |
Remember that the
|
| 27 | d | Compile-time error |
Both the
sleep
and
join
methods declare an
InterruptedException
that must be caught or declared in the
throws
clause of
|
| 28 | a | The priority assigned to thread T2 is greater than the priority assigned to T1 | The Java Language Specification suggests that higher priority threads should be given preference over lower priority threads, but explicitly states that the preference is not a guarantee. It is very important to remember that no guarantee exists. |