Head First Java by Kathy Sierra, Bert Bates This errata page lists errors outstanding in the most recent printing. If you have technical questions or error reports, you can send them to booktech@oreilly.com. Please specify the printing date of your copy. This page was updated August 9, 2006. Here's a key to the markup: [page-number]: serious technical mistake {page-number}: minor technical mistake : important language/formatting problem (page-number): language change or minor formatting problem ?page-number?: reader question or request for clarification Confirmed errors: (x) Chapter 6 first contents line; Line reads Analying the bug in the Simple Dot Com Game Should read Analyzing the bug in the Simple Dot Com Game (xx) Point 3 under "Who should probably back away from this book?"; Reads: "Do you believe than a technical book..." it should read: "Do you believe that a technical book..." (xxiv) 2nd paragraph; to increase the chance that the content gets coded coded into more should read to increase the chance that the content gets coded into more (xxvi): In the box SETTING UP JAVA, sentence at bottom of first bullet reads: "Note: there is no Java 2 pre-OS X Mac operating systems" should be: "Note: there is no Java 2 on pre-OS X Mac operating systems" (3) source code snippet missing semi-colon after the statement "Button c = new Button("Shoot me")" (8) 3rd; if ((x < 3) & (name.equals("Dirk")) { should be if ((x < 3) & (name.equals("Dirk"))) { (8) Syntax Fun -- Under 4th bullet (star); Reads: you'll learn about all the Java types in chapter 4 Should read: you'll learn about all the Java types in chapter 3 {10} Code at the upper right corner; System.out.println("Value of x is " + x); 2nd quotation mark " is pointing in the wrong direction. The line with x = x + 1; should be brought about 2 characters forward. (Indentation problem) (12) Code; Lines 9, 10 & 15 2nd quotation mark " is pointing in the wrong direction. (14) Code - Part 1 -- Inside of wordListTwo initialization; The third word in the wordListTwo array reads: "valued-added" should read: "value-added" {15} Far Right Column; The first few lines of the example reads as follows: "what we have here is a... should say (to be consistent with the code on page 14): "what we need is a..." [22] snippets on the leftmost side of the pool; System,out,print("an"); should be: System.out.print("an"); (22,24) Pool Puzzle and Solution; The Pool Puzzle snippets have System.out.print("a "); System.out.print("n "); I.e., there appear to be spaces after the letters. it should be: System.out.print("a"); System.out.print("n"); Also, the snippet System,out,print("an"); is not syntactically correct since it uses commas rather than periods between "System", "out" and "print" (28) image, center of the page; 1st amoeba: "Amoeba" is misspelled as "Ameoba" in "Ameoba rotation point..." 2nd amoeba "amoeba" is spelled as "ameba" (ameba is an acceptable spelling, just does not match the rest of the page) (28) Bottom second column; The sentence says: "...he added an attribute that all Ameboas would have". should be "Amoebas". (45) Who Am I answers; The 7th item in answers says "I have behavior" it should say "I have behaviors" The 8th item in answers says "Objects use me" The actual puzzle says "I am located in objects" (50) bottom of 2nd paragraph in right margin; "compiler always errors" Should be "compiler always errs" (54) There are no dumb questions, first answer, second sentence; theJVM's development team should be the JVM's development team (54) There are no dumb questions, first answer, last sentence; ... allocation issues, you're Big Concern should be ... allocation issues, your Big Concern (76) There are no dumb questions, last answer, last sentence; In Java, You don't... should be In Java, you don't... (83) 'there are no dumb questions' - last paragraph, the 5th sentence: So parameters are ALWAYS initialized, because they compiler... should be: So parameters are ALWAYS initialized, because the compiler... (84) under (To compare two primitives, use the == operator), 4th and 5th sentence.; "(although it doesn't care about the size of the variable, so all the extra zeroes on the left end don't matter." Should be : "(although it doesn't care about the size of the variable, so all the extra zeroes on the left end don't matter)." (84) Last sentence, last paragraph; "it will be same for two references to a single object." should be: "it will be the same for two references to a single object." (87-91) Exercise and Solution; The solution on page 91 used many "attendees" names that are not consistent with the Exercise on page 87. For example, the following words: instance variables args encapsulation should be changed to: instance variable argument encapsulate {94} 'Part of a game interaction'; Ouch! you sunk Go2.com should be: Ouch! you sunk AskMe.com (105) Sharpen your pencil; In the pseudocode for the method, the following statement: "COMPUTE a random number between 0 and 4..." should be changed to: "COMPUTE a random number between 0 and 5..." in order to be consistent with the statment on page 106. (106) Second paragraph; "COMPUTE a random number between 0 and 5 that will be the starting location cell position" should be changed to: "COMPUTE a random number between 0 and 4 that will be the starting location cell position" Since the array begins at 0 and ends at 6, if you fill a series of three cells, beginning in cell 5, your final cell will be in cell 7, which does not exist in the array. This also means that the errata for page 105 (included below), is in error. {111} interaction box in left column; On page 108, the code for the SimpleDotComGame says that if the dot com is killed, you should "System.out.println(numOfGuesses + " guesses")" On page 111, where there is an example of the code running, after printing "kill", the output is "You took 6 guesses". The code never prints "You took". (114): In the box Converting a String to an int, the line that reads: Sting num = "2"; should read String num = "2"; [129] Bottom of page (numeral 8); myList.remove(s); should be: myList.remove(0); (146) Third method (checkYourself()); "if (locationCells.isEmpty())" should read: "if (locationCells.isEmpty()) {" (173) 4th paragraph; The sentence: "Does it makes sense to say X IS-A type Y?" Should be: "Does it make sense to say X IS-A type Y?" the word "makes" should be changed to "make" {190} Right column; In the third line of the TestBoats class definition: Current: _____________ b1 - new Boat (); Should be: _____________ b1 = new Boat (); {200} 3rd paragraph; "so Canine, for example, could implement an abstract class from Animal" should be: "so Canine, for example, could implement an abstract METHOD from Animal" {203} Bottom of the page, in the outputbox; % java AnimalListUser should be % java AnimalTestDrive (204) middle of the page; This is just a simple formatting error. On page 204 in the second paragraph under "Every class in Java extends class Object" there is a large space. It seems that a new line was inserted before the 'rn' of 'return'. (204) 7th paragraph (2nd from bottom); simple typo: "That't OK." should be "That's OK." (205) The UML class diagram for the Object class; In the Object diagram: change method booleanequals() to: boolean equals() (207) note in margin; Simple typo: "(Object don't truly forget" should be "(Objects don't truly forget" {208} 1st hand-written note; The text "The Dog object in the array can't..." should read "The Dog object in the ArrayList can't..." (210) Middle of First Paragraph; -a Snowboard obect- should be -a Snowboard object- [212] Code at the very bottom of the page; if (d instanceof Dog) { Dog d = (Dog) o; } should read: if (o instanceof Dog) { Dog d = (Dog) o; } The instanceof comparison should use 'o' not 'd'. (230) Who Am I answer section; The answer on page 230 says "I can look different to different people" and the exercise question on 227 says "I can appear different to different people". (234) The paragraph above the the illustrated picture; The paragraph just above the illustrated drawing of the stack: "barf() declares and creates a new Duck reference variable 'b'..." That variable 'b' should be changed to 'd' (235) Fourth paragraph; "object's it holds references to?" should read: "objects it holds references to?" (239) 2nd paragraph; "whose" should be "who is" (244) Answer block bottom lhs third line up; Death-by-Dhocolate Brown ought to be Death-by-Chocolate Brown (245) right column, first answer in Q&A; "default accessn chapter 16 and appendx B" should be "default access in chapter 16 and appendix B" (249) last paragraph; in the sentence "And what do you think that supeclass constructor does?" should be "And what do you think that superclass constructor does?" (255) The Stack Figures; The text just below the Stack figures in item 2 and item 4: Item 2: "go() plops on top of the Stack. 'x' and 'y' are..." This is incorrect. 'x' and 'y' should be changed to 'x' and 'z' Item 4 also needs to change 'x' and 'y' to 'x' and 'z' (277) First paragraph; "trying to make an new instance of the class," should read: "trying to make a new instance of the class," (280) Thirteenth bullet point (assuming one-based indexing).; "Assign a value to a final instance variable must be either at the time it is declared, or in the contructor." Should read: "Assigning a value to a final instance variable must be done either at the time it is declared, or in the contructor." (297) four lines from bottom; You can't guarnatee should be: You can't guarantee (297) 3 lines from bottom; And we have to this now. should be: And we have to do this now. (299) Last line first paragraph; ".....send something to the another machine." Should be ".....send something to another machine". (299) Paragraph starting with "MIDI data says..."; "Jimmy Hendrix" should read "Jimi Hendrix" (303) Letters between Compiler and Geeky; In the letter from the compiler to Geeky he says "... be sure to catch any problems before all hell breaks lose." Lose should be loose. (306) 'handwritten' text next to diagram; They're knows as (big surprise here)... shoul be: They're known as (big surprise here)... (318) The Stack Figures; In the Stack figure, the laundry method should be changed to doLaundry method. (322) First Sentence on page; The first sentence reads: "Remember from page three, we looked at how MIDI data holds..." MIDI data is discussed on the third page of the chapter, not the third page of the book. Therefore, the sentence should be changed to: "Remember from page 299, we looked at how MIDI data holds..." [324] example; The MIDI sound examples' process never terminates, so after you run it, you don't get your command-line back. This is because the Sequencer starts a separate thread (we haven't gotten to the threads chapter yet, so don't worry about it at this point), and it keeps it running *even after your main method completes*. For now, think of it as almost like a separate program being launched -- so that even when your initial program (the one that starts with main()) returns, that *other* program, the one running the Sequencer, is still running. For now, we'll add two things at the end to close it down: Instead of: player.start(); } catch (Exception ex) { ... } Insert the following lines between player.start() and the catch block: Thread.sleep(1000 * 2); // inserts a pause to give the sound a chance to play player.close(); // closes the sequencer System.exit(0); // quits the Java application So... this is what it should look like now: player.start(); Thread.sleep(1000 * 2); // new player.close(); // new System.exit(0); // new } catch (Exception ex) { // everything else... ============= (340) Paragraph Beginning: An event source; second line; Most the code you write should be: Most of the code you write (340) 3rd paragraph; If you want MouseEvents, implement the MouseEvent interface. should be If you want MouseEvents, implement the MouseListener interface. (341) 1st sentence under "The Listener" section; "If your class wants to to know..." should be changed to "If your class wants to know..." (342) 1st Paragraph Item number 3 in the list; interrface should be spelled interface. (347) Section "Display a JPEG" ; Under the section "Display a JPEG", in the paragraph explained the drawImage method, the second sentence begins: "This says 3 pixels from the left edge of the panel and 2 pixels from the top edge of the panel.." should be changed to: "This says 3 pixels from the left edge of the panel and 4 pixels from the top edge of the panel.." because the parameter list of the drawImage is : (image,3,4,this) [348,350,379] misc.; all references to Graphics2d should be Graphics2D (capital D). Using Graphics2d will give you a 'cannot resolve symbol' error. (353) The bottom of the page; At the bottom of the page, in the paintComponent method, the comment refered to an incorrect page number. The second comment that said: //See page 13 for the code should be changed to //See page 349 for the code (358) 2nd column, 2nd paragraph; Change: "... and the server will have to be certain that all instances of that entity bean in sync ..." To: "... and the server will have to be certain that all instances of that entity bean are in sync ..." (370) Top of the page, right hand column; The bullet points are numbered incorrectly; They are: 1 1 1 1 They should be: 1 2 3 4 (374) Top right paragraph (Sharpen Your Pencil); "It builds directoy on Version Two." should read "It builds directly on Version Two." (374) Second method.; There appears to be an extra space between public and void in the method line: "public void setUpGui() {" should read: "public void setUpGui() {" (385) BorderLayout para line 4; "layed out" should be "laid out" (385) Dumb Question, 2nd sentence; Change: "... primary key type (, but I don't see ..." To: "... primary key type (), but I don't see ..." (394) Bullet Point 7; "FlowLayout places components lleft to right" should read: "FlowLayout places components left to right" [404] middle of the page; track.add(makeEvent(192,9,1,0,15)); should be 16 instead of 15. (407) after bullet point c; The bullet point after C should be D. In the book it is A; thus the sequence is : A B C A E [425] 1st Paragraph; The code on this page uses GameCharacter which is mentioned on page 413, however there isn't any code for this class. Additionally, the 2nd comment following the code on page 425 says, "// and then save the Dogs exactly as they are now", which is not the object type being used. {425} 2nd try block; System.out.println(one.getPower() + "," + one.getType() + "," + one.getWeapons()); System.out.println(two.getPower() + "," + two.getType() + "," + two.getWeapons()); System.out.println(three.getPower() + "," + three.getType() + "," + three.getWeapons()); should read: System.out.println(oneAgain.getPower() + "," + oneAgain.getType() + "," + oneAgain.getWeapons()); System.out.println(twoAgain.getPower() + "," + twoAgain.getType() + "," + twoAgain.getWeapons()); System.out.println(threeAgain.getPower() + "," + threeAgain.getType() + "," + threeAgain.getWeapons()); (429) 3rd 'side note'; "triggered when use chooses...." should be: "triggered when user chooses...." {434} try block in sample code on page; File myFile = new File("MyText.txt); Should read: File myFile = new File("MyText.txt"); {436} Title at top of page, and class definition.; "Quiz Card Reader code" should read: "Quiz Card Player code" and "public class QuizCardReader" should read: "public class QuizCardPlayer" to match paragraph 2, item 2, on page 428 ("2) QuizCardPlayer, a playback engine . .." and to match grapic with text on lower right-hand corner of page 428, and to match code outline on page 435. (437) first block of 'handwritten' text; in the first block of handwritten text, the word viewing is spelt incorrectly: ... See if they're currently veiwing a question or answer should be: ... See if they're currently viewing a question or answer (441) Bottom of first column, last sentence above the command window; that ships with you Java development kit. should read that ships with your Java development kit. (448) front card questionnaire; What's the first foreign country due south of Detroit Michigan? should be ....due north of Detroit Michigan {459} 2 Make a PrintWriter; Code fragment: Printwriter writer = new PrintWriter(chatSocket.getOutputStream); should be Printwriter writer = new PrintWriter(chatSocket.getOutputStream()); (459) Bullet item #2, notes.; "PrintWriter acts as it's own bridge" should read: "PrintWriter acts as its own bridge" (463) Bullet item #3; "The accept() method blocks (just sits there) while its waiting" should read: "The accept() method blocks (just sits there) while it's waiting" (469) 1st sentence of 1st paragraph; "We want something to run continusouly..." should be "We want something to run continuously..." (478) Code block, first bullet point #1; "myThread .start();" should read: "myThread.start();" It works either way, but to be consistent with the way you have used the dot notation throughout this book, the extra space is distracting. (482) 1st Paragraph; The second line of the very first paragraph refered to an incorrect page number: "...each time we ran it? Look back at page 28..." should be changed to: "...each time we ran it? Look back at page 478..." (482) Bottom of the page; class ThreadTester { should be: class ThreadTestDrive { and Runnable theJob = new HelloThread(); should be: Runnable theJob = new MyRunnable(); {487} Last line on page; Missing a closing "}" (490) 5th paragraph from the top; So, if you don't lock the back account should read So, if you don't lock the bank account (500) First line of Ready-bake Code; "mport java.io.*;" should read: "import java.io.*;" (502) Last Answer Block, next to the last paragraph (bottom right of page); before Ryan has a chance to wakes up should be before Ryan has a chance to wake up {518} 2nd paragraph, first example of javac -d .....; The side description of the first example says "Now you have to specify the PATH to get the actual class file". it should be "Now you have to specify the PATH to get the actual source (.java) file". (527) 1st sentence; To make a Java Web Start app, you to .jnlp should read To make a Java Web Start app, you the .jnlp (527) First paragraph; (518) Last set of notes, under "$java com.headfirstjava.PackageExercise".; "JVM will see that, and immediately look inside it's" should read: "JVM will see that, and immediately look inside its" (540) Note on right-hand side of page; "Your client object ge to" should read: "Your client object gets to" (546) first para line 12; "Remember, must be able to see......" should be: "Remember, rmic must be able to see..." (547) Last note on page.; "rmiregistery using the static" should read: "rmiregistry using the static" [554] 3rd and 5th paragraphs; The description for the step is the same for steps 3 and 5. The one for step 5 should be different. (555) 4th "scribble" note from the top on the right-hand side.; 'thing' is coming back from the server as a reuslt of should read 'thing' is coming back from the server as a result of (556) Bullet point 5 penultimate line; extra space between y and ou (556) "There Are No Dumb Questions", the Answer section, paragraph 3.; "response. Imagine a reasonably complext HTML page, and now" should read: "response. Imagine a reasonably complex HTML page, and now" (560) Para 5 last line ; "intereted" should be "interested" (560) 4th line from bottom of page; "do you have anything implements..." should be "do you have anything that implements..." (560) last line of page; "Here's the serialized object the Scientific Calculator service registered with me." Suggested improvement: "Here's the serialized object that the Scientific Calculator service registered with me." (567) Top two graphics on right-hand side of page; Instead of a diagram of the ServiceServer and ServiceServerImpl, there are two diagrams for ServiceServer. (572) definition of class DiceService; In the definition of the method getGuiPanel() two lines have been truncated: [1] JButton button = new JButton("Roll should read, JButton button = new JButton("Roll 'em!"); [2] The next line String[] choices = { "1", "2", "3", "4", should be: String[] choices = { "1", "2", "3", "4", "5"}; {592} Second line of Foo Class snippet; The line incorrectly ends with an opening square bracket [ -- it should be an opening brace { That is: public static void main(String [] args) [ should be: public static void main(String [] args) { {600} LinkedHashSet; Per the JDK_1.4.2/docs/api, LinkedHashSet does not implement iteration in order of most recently accessed;