Errata Page Sun Certified Programmer & Developer for Java 2 Study Guide (Exams 310-035 & 310-027) by Kathy Sierra & Bert Bates Last updated March 3, 2003 Our thanks to the following sharp-eyed readers: Jessica Sant, John Paverd, John Adair, Dan Culache, Mark Jackson, Leshec Claassens, Phillip Houston, Kenneth Thomas, Craig Baker, Johannes de Jong, Ellen Zhao, Christopher Thompson, Srinivasu Mandava, Clay Graham, Barry Gaunt, Bruce Graham, Selcuk Sonmezer, Bernard Nguyen, Rick Critchett, Erik Weibust, Joseph Yang, David 'Baldy' Truckenmiller, Sandeep Gopal, Jason Bolduc, Chia-chen Yang, Meghasyam Bokam, Garrett Smith, Jasper Vader, and Clover the dog. p.s. If we have forgotten any of our sharp-eyed readers, we apologize. Please send us an email and we will update the list! High Priority Corrections Page 11, Figure 1-1, bottom of legend 2/07/03 Change: 0 thru 127 -or- -32768 thru -1 To: 0 thru 32767 -or- -32768 thru -1 Page 22, Figure 1-4 1/27/03 Change: The arrow that points from element 2 of myArray to myArray[1] To: The arrow should point from element 1 of myArray to myArray[1] Page 25, Legend for Figure 1-5 1/27/03 Change: Four objects are created: 1 Dog object referenced by puppy 1 Dog [] array referenced by myDogs 2 Dog objects referenced by myDogs[0] and myDogs[1] To: Four objects are created: 1 Dog object referenced by puppy and by myDogs[0] 1 Dog [] array referenced by myDogs 2 Dog objects referenced by myDogs[1] and myDogs[2] Page 26, Second code block 1/27/03 Change: scores[0][1] // the int value 5 To: scores[0][1] // the int value 2 Page 41, First code block 1/27/03 Change: System.out.println("Usage: [name] [social security #] // [IQ] Try again when you have a clue"); To: System.out.println("Usage: [name] [social security #] [IQ] Try again when you have a clue"); Page 70, Last line of code 2/07/03 Change: .. invoke it on a Foo reference To: .. invoke it on a Zoo reference Page 80, Second paragraph 3/03/03 Change: .. code outside the subclass. So if class Neighbor .. To: .. code outside the subclass, with the exception of subclasses of the subclass. So if class Neighbor .. AND Change: .. only the subclass' own code can access it. To: .. only the subclass and its subclasses can access it. Page 82, First code block 2/07/03 Change: Parent sc = new Parent(); To: Child sc = new Child(); Page 92, Figure 2-5, Middle column 1/27/03 Change: Add volatile to the bottom of the 'Variables (non-local)' column Page 93, First code block 1/27/03 Change: public void doSomething(int i) { count = i; // Won't compile .. } To: public void doSomething(int i) { count = i; // Won't compile .. } } Page 103, First code block 1/27/03 Change: int frogs = f.getFrogCount; .. To: int frogs = f.getFrogCount(); .. Page 106, First and second code blocks (two occurrences) 1/27/03 Change: class Foo { } To: class Bob { } Editor note: change both occurances Page 121, After the Exam Watch 1/27/03 Change: 1. A class can extend more than one interface. To: 1. A class can implement more than one interface. Page 128, Last Bullet 3/03/03 Change the last bullet to, To: A protected member inherited by a subclass from another package is not accessible to any other class in the subclass package, except for the subclass's own subclasses. 1. Page 134, Question 2 1/27/03 Change: 2. Given a method in a protected class .. To: 2. Given a method in a public class .. Page 138, Question 11, c 3/03/03 Change: public static final int c; To: public final int c; Page 142, Answer 8 3/03/03 Change: E. .. protected (or final for that matter), so the To: E. .. protected, (or private for that matter), so the Page 142, Answer 11 3/03/03 Change: .. at the same time. D will compile .. To: .. at the same time. However, this makes it a 'blank final' which must then be initialized in the constructor. D will compile .. Page 173, Table 3-3 (last row was omitted) 1/27/03 Add: Add a row on the bottom with the values: 1 1 1 1 0 Page 174, Middle of the page code blocks 2/07/03 Change: System.out.println("1010 & 1001 = " + x); To: System.out.println("1010 | 1001 = " + x); AND Change: %java Bitwise 1010 & 1001 = 11 To: %java Bitwise 1010 | 1001 = 11 Page 187, Second line of code 2/07/03 Change: int size = 7; To: static int size = 7; Page 214, End of the second paragraph 1/27/03 Change: If the first test succeeds, we want .. To: If the first test fails, we want .. Page 214, Second code block 1/27/03 Change: } else if (price < 400) { To: } else { if (price < 400) { Page 215, Second code block 1/27/03 Change: } else { System.out.println("Java Master!"); // Which if .. } To: // Which if does this belong to? } else { System.out.println("Java Master!"); } } Page 218, Last paragraph 1/27/03 Change: ,so that means you can use only a literal or final variable. Also, the switch .. To: ,so that means you can use only a constant final variable that is assigned a literal value. It is not enough to be final, it must be a compile time constant. For example: final int a = 1; final int b; int x = 0; switch (x) { case a: // ok case b: // compiler error // thx to John Paverd ! Also, the switch .. Page 219, Last line of code 2/07/03 Change: case 129: To: case 128: Page 231, Second exam watch 1/27/03 Change: .. statements must be used inside either a loop or switch statement. The break statement causes the program .. To: .. statements must be used inside either a loop or switch statement. (Note: This does not apply to labeled break statements.) The break statement causes the program .. Page 258, End of the paragraph after the 'Simple' code block 2/07/03 Change: .. help while the simple version .. To: .. help while the really simple version .. Page 259, Table 4-3, second row, third column 1/27/03 Change: public int go() { return 1; : go(); To: public int go() { return 1; } : go(); Page 262, Second code block 2/07/03 Change: java -ea -da:com.geeksanonymous To: java -ea -da:com.geeksanonymous . . . Editor note: add three dots after anonymous Page 263, Table 4-4, rows 4 and 6 1/27/03 Change: java -ea:com.foo To: java -ea:com.foo . . . AND Change: java -ea -da:com.foo To: java -ea -da:com.foo . . . Editor note: add three dots after foo Page 267, End of the third paragraph 1/27/03 Change: .. the special cases where the try or catch code raises an uncaught exception or issues a System.exit(). To: .. the special cases where the try or catch code issues a System.exit(). Page 308, First code block 2/07/03 Change: Adder add = new Adder(); To: Adder a = new Adder(); Page 357, After first code block 2/07/03 Change: .. with the value "JAVA RULES!", but it was .. To: .. with the value "JAVA", but it was .. Page 357-358, End of 357, top of 358 1/27/03 Change: // still: x = Java Rules!x = x.toLowerCase(); // .. To: // still: x = Java Rules x = x.toLowerCase(); // .. Page 366, First code block 2/07/03 Change: StringBuffer sb = new StringBuffer("A man a plan a canal Panama"); System.out.println(sb) // output is "amanaP lanac a nalp a nam A" To: StringBuffer sb = new StringBuffer("A man a plan a canal Panama"); sb.reverse(); System.out.println(sb); // output is "amanaP lanac a nalp a nam A" Page 377, Table 6-2, fifth row, float 2/07/03 Change: float or String To: float, double, or String Page 388, Second bullet 1/27/03 Change: .. returns a float if it was passed an int, or it returns a double if it was passed a long. To: .. returns an int if it was passed a float, or it returns a long if it was passed a double. Page 433, Last paragraph 1/27/03 Change: sb in the third line. Although the rest of the code does not use the StringBuffer object, it is not yet eligible for garbage collection. To make it eligible, we set .. To: sb in the third line. To make this object eligible, we set .. Editor note: strike the sentence beginning: Although the rest of the code .. Page 464, Second bullet list - add a final bullet under 'static' 1/27/03 Add: strictfp Page 466, End of Page 1/27/03 Change: .. same time as with any other class or method.) To: .. same time as with any other class or method.) Special Note: Remember that a local class declared in a static method has access to only static members of the enclosing class, since there is no associated instance of the enclosing class. If you're in a static method there is no 'this', so an inner class in a static method is subject to the same restrictions as the static method. In other words no access to 'instance variables'. Page 505, Second paragraph 2/07/03 Change: .. method has finished, you can't say t.start(); you'll get a big fat runtime exception. To: .. method has finished, calling t.start() won't restart it. Page 515, Second bullet 3/03/03 Change: .. the thread it calls wait() on) To: .. the thread it calls join() on) Page 533, Bottom code block 2/07/03 Change: 20. calculator.start(); 21. new Reader(calculator).start(); 22. new Reader(calculator).start(); 23. new Reader(calculator).start(); To: 20. new Reader(calculator).start(); 21. new Reader(calculator).start(); 22. new Reader(calculator).start(); 23. calculator.start(); Page 546, Question 17 1/27/03 Change: G. wait() can throw a runtime exception. To: G. wait() does not throw a checked exception. ======================================================================== Low Priority Corrections Page XXiii, Acknowledgements, second bullet 2/07/03 Change: .. Oussama Azizi, and, of course, to the .. To: .. Oussama Azizi, Mohamed Mazahim, Shweta Mathur, James Chegwidden, Manish Hatwalne, Mike Gallihugh, Michael Taupitz, Emiko Hori, John Paverd,Joseph Bih, Skulrat Patanavanich, Sunil Palicha, Suddhasatwa Ghosh, R.Srinivasan, and, of course, to the .. Page XXiii, Acknowledgements, last bullet 3/03/03 Change: .. preparing for the exam. To: .. preparing for the exam. The 'rents', Ann and Jim for supporting this hare-brained scheme. Page XXiv, Add new bullet 2/07/03 Add: Our thanks to the following sharp-eyed readers: Jessica Sant, Johannes de Jong, Dan Culache, Mark Jackson, Leshec Claassens, Phillip Houston, Kenneth Thomas, John Adair, Craig Baker, Ellen Zhao, Christopher Thompson, Srinivasu Mandava, Clay Graham, Barry Gaunt, Bruce Graham, Selcuk Sonmezer, Bernard Nguyen, Rick Critchett, Erik Weibust, Joseph Yang, David 'Baldy' Truckenmiller, Sandeep Gopal, Jason Bolduc, Chia-chen Yang, Meghasyam Bokam, Garrett Smith, Jasper Vader, and Clover the dog. Page 13, Octal Literals 2/07/03 Change: int five = 06; // .. To: int six = 06; // .. Page 15, Third exam watch 2/07/03 Change: char a = 0x892; // octal literal To: char a = 0x892; // hexadecimal literal Page 17, Last line 3/03/03 Change: Chapter 6 To: Chapter 7 Page 55, Answer to question 8 2/07/03 Change: .. is really a 16-bit integer behind .. To: .. is really an unsigned 16-bit integer behind .. Page 71, Figure 2-1 - Sportscar 3/03/03 Change: goFast { } doStuff ( ) { .. To: goFast( ) { } doStuff( ) { .. Page 74, Second code block 2/07/03 Change: Balloon.java:5: No method .. To: Balloon.java:6: No method .. Page 76, Figure 2-2 - Sportscar 3/03/03 Change: goFast { } doStuff ( ) { .. To: goFast( ) { } doStuff( ) { .. Page 87, Figure 2-4 abstract SUV box 2/07/03 Change: enable4wd( ); To: enable4wd( ) Page 103, Bullets at the bottom of the page 2/07/03 Change: .. we'll explore this in Chapter 7) To: .. we'll explore this in Chapter 8) Page 124, Figure 2-9 abstract ball and Beachball boxes 2/07/03 Change: // no methods of Bounceable are Implemented In Ball To: /* no methods of Bounceable are Implemented In Ball */ AND Change: // beSpherical is not abstract so BeachBall is not required to implement it To: /* beSpherical is not abstract so BeachBall is not required to implement it */ Page 127, Second bullet 2/07/03 Change: .. protected, default, and .. To: Editor note: 'default' can't be in courier .. protected, default, and .. Page 128, Second bullet 2/07/03 Change: .. protected, default, private. To: Editor note: 'default' can't be in courier .. protected, default, private. Page 133, First bullet 3/03/03 Change: Interfaces are by default.. To: Interface methods are by default Page 156, Middle paragraph 2/07/03 Change: .. with any number, as the code shows (though it isn't .. To: .. with any number, (though it isn't .. Page 171, Second to last paragraph, and a deletion in the last paragraph 2/07/03 Change: ..>> is that the result of an unsigned .. To: .. >> is that, except for a few special cases that we'll discuss next, the result of an... AND Delete: (a long if the second operand is a long). Page 172, After int y = x >> 2; and before the exam watch, add: 2/07/03 Add: Note: When using any of the shift operators, if you shift an int by any multiple of 32, or a long by any multiple of 64, the original value will not change. Page 177, Second code block 3/03/03 Change: float a = 100.001; To: float a = 100.001f; Page 188, First code block - two occurences 3/03/03 Change: .. " + barNum); To: .. " + myBar.barNum); Editor note: two occurrences to change Page 189, End of first paragraph 2/07/03 Change: .. always a positive number. To: .. always a positive number, except that when using any of the shift operators, if you shift an int by any multiple of 32, or a long by any multiple of 64, the original value will not change. Page 191, Second to last bullet 2/07/03 Change: .. negative infinity. To: .. negative infinity, except when the dividend is also zero, in which case you get NaN. Page 192, Shift Operators, fourth bullet 2/07/03 Change: Bits are filled as follows: .. To: Except for the unusual cases of shifting an int by a multiple of 32 or a long by a multiple of 64 (these shifts result in no change to the original values), bits are filled as follows: .. Page 193, Casting, second bullet 2/07/03 Change: Explicit casting (you write the cast) happens when a narrowing conversion occurs. To: Explicit casting (you write the cast), is required when a narrowing conversion is desired. Page 214, Second to last code block 1/27/03 Change: else System.out.println("Java Master!"); // Which if .. To: // Which if does this belong to? else System.out.println("Java Master!"); Page 215, First code block 1/27/03 Change: else System.out.println("Java Master!"); // Which if .. To: // Which if does this belong to? else System.out.println("Java Master!"); Page 215, Last paragraph 1/27/03 Change: .. but some of the expressions can be complex, like the following, int y = 5; int x = 2; if ((((x > 3) && (y < 2)) | doStuff())) System.out.println("true"); } To: .. but some of the expressions can be complex. Assume doStuff() returns true, int y = 5; int x = 2; if (((x > 3) && (y < 2)) | doStuff()) { System.out.println("true"); } Page 216, First code block 1/27/03 Change: if (((x > 3) && (y < 2) | doStuff())) System.out.println("true"); } To: if ((x > 3) && (y < 2) | doStuff()) { System.out.println("true"); } Page 218, Legal Arguments to switch and case 2/07/03 Change: variables and valuables that can be .. To: variables and values that can be .. Page 240, First code block 2/07/03 Change: try { // doStuff } System.out.print .. // need a catch .. To: try { // doStuff } // need a catch or finally here System.out.println("out of try block"); Page 240, Second code block 2/07/03 Change: try { // doStuff } System.out.print .. // can't have code.. catch (Exception ex) { } To: try { // doStuff } // can't have code between try / catch System.out.println("out of try block"); catch (Exception ex) { } Page 240, First exam watch 2/07/03 Change: Editor note: change all occurances of 'catch' that are bold, courier to plain courier. Page 252, First and last code error messages (two occurrences) 3/03/03 Change: TestEx .. declared .. blah .. ^ .. To: unreported exception MyException; must be caught or declared to be thrown. Page 252, Code block under exam watch 3/03/03 Change: catch(MyException me) { throw me; } } To: catch(MyException me) { throw me; } } } Page 287, Answer 17 3/03/03 Change: Advisable to thrown an exception To: Advisable to throw an exception Page 290, First code block 3/03/03 Change: .. void checkWord(String s) { To: .. void checkFood(String s) { Page 314, Item 3 3/03/03 Change: Editor's note: Enire item should be in normal , non-code font Page 333, Third bullet 3/03/03 Change: .. super.overriddenMethodName to call To: .. super.overriddenMethodName() to call Page 361, Second code block 1/27/03 Change: public Boolean equalsIgnoreCase(String s) To: public boolean equalsIgnoreCase(String s) Page 368, abs( ) method 3/03/03 Change: ..value is non-negative. The signatures.. To: .. value is non-negative. (The abs() method can return a negative if the argument is the minimum int or long value equal to the value of Integer.MIN_VALUE or Long.MIN_VALUE, respectively. ) The signatures.. Page 380, Bottom of table 6-3 2/07/03 Change: - primitive xxxValue() - primitive parseXxx(String) - Wrapper valueOf(String) To: - primitive xxxValue() - to convert a Wrapper to a primitive - primitive parseXxx(String) - to convert a String to a primitive - Wrapper valueOf(String) - to convert a String to a Wrapper Page 381, First code block 3/03/03 Change: // result is "L2 value = 42" To: // result is "L3 value = 42" Page 383, Exam watch, point 1 2/07/03 Change: .. patterns are identical. To: .. patterns are identical. (Ok, we could get picky about IEEE 754 and floating point numbers, but it's not on the exam, so we won't.) Page 388, Bullet 1 3/03/03 Change: .. the random( ) does not .. To: .. the random() method does not.. Page 393, Answer 8 b 3/03/03 Change: .. than or equal to 0.0.. To: .. than or equal to 0.0. Page 427, LinkedHashSet - line 3 3/03/03 Change: .. you iterate though a HashSet.. To: .. you iterate through a HashSet.. Page 434, Last code block and last paragraph 3/03/03 Change: String now = d2.toString(); To: StringBuffer now = new StringBuffer(d2.toString()); AND Change: String To: StringBuffer Editor Note: two occurrences of String to change. Page 447, Question 1 2/07/03 Change: .. properly implemented, if the output .. To: .. properly implemented, and assuming that x1 - x8 are all of the same type, if the output .. Page 447, Question 2 3/03/03 Change: public int hashcode() .. To: public int hashCode() .. Page 482, Question 5 3/03/03 Change: .. inserted at line 5 .. To: .. inserted at line 7 .. Page 497, Last paragraph 1/27/03 Change: The complete list of constructors is To: The constructors we care about are: Page 500, Middle code block 2/07/03 Change: System.out.println("Run by " + Thread.current .. To: System.out.println("Run by " + Thread.currentThread().getName()); Page 501, Middle code block and bottom code block 2/07/03 Change: System.out.println("thread is " + Thread.current .. To: System.out.println("thread is " + Thread.currentThread().getName()); AND Change: System.out.println("Run by " + Thread.current .. To: System.out.println("Run by " + Thread.currentThread().getName()); Page 502, First code block 2/07/03 Change: NameRunnable nr = new NameRunnable(); // Make one runnable To: // Make one runnable NameRunnable nr = new NameRunnable(); Page 509, Bottom code block 2/07/03 Change: System.out.println("Run by " + Thread.current .. To: System.out.println("Run by " + Thread.currentThread().getName()); AND Change: NameRunnable nr = new NameRunnable(); // Make one runnable To: // Make one runnable NameRunnable nr = new NameRunnable(); Page 514, Figure 9-3 3/03/03 Swap: Two boxes on lower right of figure.. Swap doStuff() box with doOther() box. Page 552, Answer 15, last line 3/03/03 Change: .. so I would be equivalent .. To: .. so G would be equivalent ..