The errata list is a list of errors and their corrections that were found after the product was released.
The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.
| Version |
Location |
Description |
Submitted By |
| Printed |
Page xvii
left |
1) The graphic shows a UK (british) Wall Outlet, not a European one.
2) "Standard" probably refers to "US"? It ain't standard where I am.
|
John B-R |
| Printed |
Page 56
UML diagram representation : Subject to Observer |
In the Chapter 2: Observer pattern --> Designing the Weather Station UML diagram on page 56, the relation between the Subject and Observer should be aggregation (a hollow diamond) rather than a simple association.
|
Anonymous |
| Printed |
Page 59
weatherData.registerObserver(this) |
Registering a listener from its constructor allows the "this" reference to escape
potentially causing concurrency issues.
http://www-128.ibm.com/developerworks/java/library/j-jtp07265/index.html
|
Anonymous |
| Printed |
Page 63
3rd Paragraph (Observer) |
"There's so many different kinds of us Observers, there's no way you can anticipate everything we need."
Should be:
"There are so many different kinds of us Observers, there's no way you can anticipate everything we need."
|
B Hillebrecht |
| Printed |
Page 67
Number 3 |
Instead of:
so we've removed the code for register, add and notify
it should be:
so we've removed the code for register, remove and notify
|
Anonymous |
| Printed |
Page 95
bottom |
The implementation of the class CondimentDecorator does not conform to the UML diagram for
the Decorator pattern available on page 91.
In page 91, the UML diagram shows that Decorator *has a* Component, since there is a 'has a' arraw
from Decorator pointing to Component.
In page 92, there is another UML diagram of the Decorator pattern that is adapted to the Starbuzz
case, and it also shows a 'has a' relationship between CondimentDecorator and Beverage.
If the implementation of CondimentDecorator in page 95 were conforming to the Decorator pattern
diagrams in pages 91 and 92 it would be:
/**
* Implementation of CondimentDecorator conforming to pg 91 UML
* diagram of the Decorator pattern
*/
public abstract class CondimentDecorator extends Beverage {
Beverage beverage; // <-- It should have a Beverage instance
// variable to conform to the 'has a'
// relationship shown in the Diagram in pg 91.
/**
* And providing a constructor like this would be adequate:
*/
public CondimentDecorator(Beverage beverage) {
this.beverage = beverage;
}
public abstract String getDescription();
}
The current implementation of CondimentDecorator in page 95 does not conform to the
UML definitions presented in pages 91 and 92, what lets the reader with a confusing
sensation like: "Wasn't I supposed to implement what is shown in the UML diagram definition?",
or "i believe that 'has a' relationship show in the UML can be omitted if I want...".
For your convenince I'm pasting bellow the current implementation of the CondimentDecorator
class currently presented in the book:
public abstract class CondimentDecorator extends Beverage {
public abstract String getDescription();
}
Please fix that.
|
Anonymous |
| Printed |
Page 97
Number 2 at the right |
It is write "to to" instead of "to" : Here, we're going to to pass the beverage ...
|
Anonymous |
| Printed |
Page 100
2nd handwritten comment from top |
There is a period missing at the end of the first line.
"FileInputStream is the component that's being decorated The Java I/O..."
|
Anonymous |
| Printed |
Page 233
The answer |
Date: Thu, 26 Jun 2008 12:55:59 -0500
From: "Vinayak Badrinathan" <vinnybad@gmail.com>
To: "Oreilly Booktech" <booktech@oreilly.com>
Subject: Correction to Head First Design Patterns
Hello,
My name is Vinayak Badrinathan. As I was reading the Design Patterns book
(which I am a huge fan of), I noticed a subtle mistake. The mistake I am
talking about is with an exercise on page 227 (the command pattern
example). The answer that is provided on page 233 is slightly incorrect.
Undo is supposed to undo the last action. If MacroCommand is a list of
commands {1..n}, then undo should undo those commands in reverse order (like
a stack). So the example below illustrates what I am trying to say:
command[0] = (change fan speed from low to med)
command[1] = (change fan speed from med to high)
If the above MacroCommand was performed, then command 0, then 1 is
executed. If the undo button is pressed, your example calls undo on 0, then
undo on 1 when it should call undo on 1, then undo on 0.
The desired output: fan should be on low but the solution that you give will
set fan speed to med (see below):
after macro command is performed, fan state is at high.
* undo command 0 - set the fan speed to low
* undo command 1 - set the fan speed to med
All of this assumes that you are allowed to execute multiple commands for
the same Command object in a MacroCommand. This also assumes that the
Command class is programmed in such a way that the order in which a command
is called matters...you never know what programmers who extend the
functionality of your program will do...so it's always good to be safe!
So...the fix:
public class MacroCommand implements Command {
(...stuff...)
public void undo() {
for( int i = commands.length-1; i >= 0; i-- ) {
commands[i].undo();
}
}
}
I hope this helps. :). If you have any further questions or want me to
further clarify and give a more detailed example, please let me know! I'd
be more than happy.
-Vinayak Badrinathan
Phone: 630-606-5305
Email: vinnybad@gmail.com
Student at Illinois Institute of Technology
--
~ Play in your world. Live in mine. ~ Vinayak Badrinathan
|
Anonymous |
| Printed |
Page 236
Diagram or the test |
Diagram shows an US plug, and an British plug and a British wall socket. However the text refers to the British plug and socket as "European".
Not a technical problem, but if someone from the US buys an British travel adapter when visiting (mainland) Europe based on your book, they're going to have a problem :)
Also shows really sloppy research in what is otherwise a fantastic book (and series of books).
Nice overview of plugs can be found: http://users.telenet.be/worldstandards/electricity.htm
|
Ryan |
| Printed |
Page 273
1st paragraph |
Spelling mistake: 'Enumaration'.
|
Anonymous |
| Printed |
Page 302
3rd paragraph |
On the method compareTo you receive object as parameter and then you make an explicit cast
from object to Duck. But if it was not a Duck ? If it is another kind of object? I thought you
should first test if it is from a compatible type of Duck and then you make the cast.
|
Anonymous |
| Printed |
Page 368
method createIterator in class Menu |
The code is buggy. (That is why the desserts show up multiple times on p374.) The
reason is that your are creating a new CompositeIterator. When you combine that with
the stack.push statement in method next on p369, you wind up with multiple stacks,
which cause the incorrectly repeated items.
The other problem with your code is that the external iterator doesn't return the
top-level node of the composite. (I.e. your "all-menus" node doesn't get returned.)
These two problems are related. You aren't distinguishing between the iterator
method that the client calls externally, from the createIterator method that gets
called recursively inside the code.
|
Anonymous |
| Printed |
Page 368
Menu.createIterator() code segment |
Incorrect code:
iterator = new CompositeIterator(menuComponents.iterator());
It should read:
iterator = new CompositeIterator(this.iterator());
|
Anonymous |
| Printed |
Page 369
method next |
The test
if (component instanceof Menu)
is not necessary, and is in fact incongruous with your insistence on transparency.
Moreover, this test keeps your code from needing to use null iterators.
|
Anonymous |
| Printed |
Page 369
method hasNext |
You don't need recursion here. In fact, if you use a while loop the code is a lot
easier to understand.
|
Anonymous |
| Printed |
Page 374
CompositeIterator |
CompositeIterator bug, see also:
http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=9&t=003670
|
Anonymous |
| Printed |
Page 390
1st paragraph |
In the last sentence of the paragraph you're writing about having to implement an "empty gumball
condition" I think this should be an "empty gumballmachine condition"
|
Anonymous |
| Printed |
Page 397
textballoon |
The last sentence says "not to mention that CEO will drive us crazy."
I'm not sure since English is not my native language, but I think this should be something like "not to
mention that the CEO will drive us crazy."
|
Anonymous |
| Printed |
Page 398
Textballoon |
First sentence:
"Now we're going put all the behavior..."
should be:
"Now we're going to put all the behavior..."
|
Anonymous |
| Printed |
Page 403
GumballMachine member variable declaration |
State state is initialized with soldOutState. However, soldOutState is null at that point.
So, if GumballMachine is instantiated with numberGumballs==0, this.state will remain null
rather than an object of class SoldOutState. That's probably not what was intended.
|
Anonymous |
| Printed |
Page 452
Comment pointing to NoQuarterState class |
"Note that this can be slightly dangerous if you try to access this field once its been serialized and transferred."
Should be:
"Note that this can be slightly dangerous if you try to access this field once it's been serialized and transferred."
|
B Hillebrecht |
| Printed |
Page 465
paintIcon code |
The code is not thread safe for all the reasons you list in the singleton pattern pg 182 .
The ImageIcon reference should be volatile and use java 1.5 + or accessed via synchronized getters and
setters for all Java versions. The issue is its initialised by one thread, written two by another and
then read again by potentially more threads but certainly not the second that loads it.
If you don't in theory the 2nd thread can never see the loaded icon, or see the reference but only the
result of all or part of its construction i.e. you do not have correct memory barriers and therefore no
happens before ordering.
[You also want imageURL to be final post Java 1.4 for the same reasons]
|
Anonymous |
| Printed |
Page 471
middle column, top paragraph |
"If they were coupled the client would have to wait until each image is retrieved before it could paint
it entire interface."
should be:
"If they were coupled the client would have to wait until each image is retrieved before it could paint
its entire interface."
|
Anonymous |
| Printed |
Page 521
2nd line |
i found a typo in your book ( head first design patters ) that i wanted to let you know about. on page 521 it has "we're ready to observe. Let's update the simulator and give it try:" it should be "give it a try"
|
Anonymous |
| Printed |
Page 527
bottom of the page |
Update the link to the MVC song to: http://www.youtube.com/watch?v=YYvOGPMLVDo
|
 Elisabeth Robson
 |
| Printed |
Page 552
3rd |
the doGet() should be doPost(), for the JSP on the page 554 that require a doPost() method. the <form method="post" explicitly says so.
|
tisiphone |
| Printed |
Page 553
the code block |
the doGet() should also be doPost(), for the JSP on the page 554 that requires a doPost() method.
|
tisiphone |
| Printed |
Page 565
Code Method on() of the class BeatModel |
In order to have the MIDI sound output play continuously you should add the line sequencer.setLoopCount(sequencer.LOOP_CONTINUOUSLY); before starting the sequencer.
Sample program src/headfirst/combined/djview/BeatModel.java;
So
public void on() {
sequencer.start();
setBPM(90);
}
should be :
public void on() {
sequencer.setLoopCount(sequencer.LOOP_CONTINUOUSLY);
sequencer.start();
setBPM(90);
}
|
Anonymous |
| PDF |
Page 565
Code Method on() of the class BeatModel |
In order to have the MIDI sound output play continuously you should add the line sequencer.setLoopCount(sequencer.LOOP_CONTINUOUSLY); before starting the sequencer.
Sample program src/headfirst/combined/djview/BeatModel.java;
So
public void on() {
sequencer.start();
setBPM(90);
}
should be :
public void on() {
sequencer.setLoopCount(sequencer.LOOP_CONTINUOUSLY);
sequencer.start();
setBPM(90);
}
|
Anonymous |
| Printed |
Page 613
class "ConcreteRemote" in UML class diagram |
In the first edition (October 2004), class "ConcreteRemote" in UML class diagramm for the "Bridge" pattern on page 613 contains a method "setStation()". However, I would expect that the method shall be named "setChannel()".
|
Anonymous |
| Printed |
Page 613
class "ConcreteRemote" in UML class diagramm |
In the first edition (October 2004), class "ConcreteRemote" in UML class diagramm for the "Bridge" pattern on page 613 contains a method "setStation()". However, I would expect that the method shall be named "setChannel()".
|
Anonymous |