Originally posted by Tiffny Yang:
Congradulation Herb !!! Rock on.
Very helpful information.
Did you do all the 10 Tests in JQPlus?
Did you do the Whizlabs?
What about the the level of difficult of JQPlus compared with real exam?
12. Given the scenario: This class is intended to allow users to write a series of messages, so that each message is identified with a timestamp and the name of the thread that wrote the message:
public class Logger {
private StringBuilder contents = new StringBuilder();
public void log(String message) {
contents.append(System.currentTimeMillis());
contents.append(": ");
contents.append(Thread.currentThread().getName());
contents.append(message);
contents.append("\n");
}
public String getContents() { return contents.toString(); }
}
How can we ensure that instances of this class can be safely used by multiple threads?
A. This class is already thread-safe.
B. Replacing StringBuilder with StringBuffer will make this class thread-safe.
C. Synchronize the log() method only.
D. Synchronize the getContents() method only.
E. Synchronize both log() and getContents().
F. This class cannot be made thread-safe.
Originally posted by Peer Reynders:
Eh, hybrids are just an (unfortunately necessary) transitional technology.
...
Hydrogen still seems to be the ideal energy carrier.
2. Given two files:
1. class One {
2. public static void main(String[] args) {
3. int assert = 0;
4. }
5. }
Self Test Answers 399
1. class Two {
2. public static void main(String[] args) {
3. assert(false);
4. }
5. }
And the four command-line invocations:
javac -source 1.3 One.java
javac -source 1.4 One.java
javac -source 1.3 Two.java
javac -source 1.4 Two.java