Errata

Head First Design Patterns

Errata for Head First Design Patterns

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted By Date submitted Date corrected
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.

Note from the Author or Editor:
Fixed in updated files/

John B-R  Jan 19, 2009 
Printed
Page viii
2nd paragraph, line 7

... that encourage woman to ...
should be:
... that encourage women to ...

Anonymous    Aug 19, 2011
Printed
Page viii
4th paragraph

"trying to restoring"
should be:
"trying to restore"

Anonymous    Aug 19, 2011
Printed
Page ix
3rd paragraph

runing
should read:
running

Anonymous    Aug 19, 2011
Printed
Page xxxi
Fourth through ninth numbered Item

Items are numbered 1,2,3,5,..,10
instead of 1,2,3,4,5,..,10.

Anonymous    Aug 19, 2011
Printed
Page xxxv
2nd Paragraph

A space is missing between the word 'their' and the following opening parenthesis.
So this:
"...and the impact you've had on their(and our) lives is forever."
should be:
"...and the impact you've had on their (and our) lives is forever."

Anonymous    Aug 19, 2011
Printed
Page 5
Box for RubberDuck

The string ".//" should be "//"

Anonymous    Aug 19, 2011
Printed
Page 9
beneath the box containing the Design Principle

thruoghout
should be:
throughout

Anonymous    Aug 19, 2011
Printed
Page 9
1st paragraph

In the 10th anniversary edition, page 9 has a segment that says: "...except Java interfaces have no implementation code..."

This is not true. Since Java 8, you can add default or static methods into Java interfaces. More detail is in this link: https://docs.oracle.com/javase/tutorial/java/IandI/nogrow.html

Note from the Author or Editor:
Will be fixed in 2/ed which we're working on now.

Anonymous  Jan 02, 2020 
Printed
Page 12
last line

Should be a.makeSound();

Anonymous   
Printed
Page 13
Box for Quack class

quack)
should be
quack()

Anonymous    Aug 19, 2011
Printed
Page 13
Diagram - annotation below FlyNoWay box

"And here's the implementation of all ducks that can't fly."
should be
"And here's the implementation for all ducks that can't fly."

Anonymous    Aug 19, 2011
Printed
Page 14
Second sentence in the second answer iin the Q&A on page 14 should

be changed to read:
"As you'll see once we've got everything hooked together, we do benefit
by having Duck not be an interface, and having specific ducks, like
MallardDuck, inherit common properties and methods."

Anonymous    Aug 19, 2011
Printed
Page 19
description of step 3, 3rd line

... and Sqeak.java ...
should be:
... and Squeak.java ...

Anonymous    Aug 19, 2011
Printed
Page 21
Code

The code is improperly indented, starting with the fourth line.

Anonymous    Aug 19, 2011
Printed
Page 21
step 5, console, last line

I'm flying with a rocket
should be (in order to be consistent with the code at the bottom of the previous page):
I'm flying with a rocket!

Anonymous    Aug 19, 2011
Printed
Page 23
Master and Student dialogue

Master's second-to-last remark includes "maintaintability"
it should be:
maintainability

Anonymous    Aug 19, 2011
Printed
Page 32
Middle of page, "OO Principles" box, 2nd sentence

"Favor composition over inheritence"
should be
"Favor composition over inheritance"

Anonymous    Aug 19, 2011
Printed
Page 33
Crossword puzzle

There were several errors in the crossword puzzle. A corrected version can be found here -
http://examples.oreilly.com/9780596007126/chapter1crossword.pdf

Anonymous   
Printed
Page 34
1st paragraph

"... while Weapon is an interface that all weapons implement."
should be
"... while WeaponBehavior is an interface that all weapon behaviors implement."

Anonymous  Nov 25, 2009  Aug 19, 2011
Printed
Page 35
Sharpen Your Pencil Solution

There are two "C" boxes. The boxes should be A, B, C, D, E, F instead of A, B, C, C, D, E.

Anonymous    Aug 19, 2011
Printed
Page 41
Second bullet

The closing parenthesis is missing.

Anonymous    Aug 19, 2011
Printed
Page 52
Q&A section at bottom

Minor layout booboo: missing "There are no Dumb Questions" heading

Anonymous    Aug 19, 2011
Printed
Page 56
UML

"CurrentConditions" should be "CurrentConditionsDisplay" (as it is in the code on p. 60).
Also On page 56, the "subject" arrow from CurrentConditions (which should read
CurrentConditionsDisplay) should point to the Subject interface, rather than WeatherData.

Anonymous    Aug 19, 2011
Printed
Page 56
Diagram

I've the 2014 2nd printing of this book. On an earlier page, 52, there is a diagram with a ConcreteObserver pointing to a ConcreteSubject. There is a comment associated with the ConcreteObserver in which it's stated "Each observer registers with a concrete subject to receive updates." This is valid given the diagram.

However, on page 56 you have the CurrentConditionsDisplay (a concrete observer class) with an arrow pointing to the interface 'Subject' (an interface, not the concrete class which implements the Subject interface). According to this diagram WeatherData is the concrete subject which implements the Subject interface, thus to be consistent with page 52, the CurrentConditionsDisplay element should point to the WeatherData class.

Note from the Author or Editor:
Fixing this in the next edition

Raymond Plante  Nov 15, 2016 
Other Digital Version
59
Sample source codes

In the book and sample code for CurrentConditionsDisplay, the weatherData is created as "Subject weatherData". But in all other parts of the code not written in the book, it's written as "WeatherData weatherData"
It doesn't seem to matter but surely one of them is the "more proper" way. And consistency would be nice.

Note from the Author or Editor:
Will get fixed in 2nd ed.

Anonymous  Apr 09, 2018 
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."

Note from the Author or Editor:
Fixed in Updated Files/ for next printing

B Hillebrecht  Jun 19, 2009 
Printed
Page 64
UML

On page 64, the "subject" arrow from GeneralDisplay should point to Observable rather
than WeatherData.

Anonymous    Aug 19, 2011
Printed, PDF, ePub, Mobi
Page 64
Class Diagram, concrete Observers

The GeneralDisplay observer should be CurrentConditionsDisplay

Elisabeth Robson
Elisabeth Robson
 
Aug 09, 2013 
Printed
Page 65
last paragraph

notifyObserver(arg)
should read:
notifyObservers(arg)

Anonymous    Aug 19, 2011
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

Note from the Author or Editor:
Fixed in Updated Files/ for next printing.

Anonymous   
Printed
Page 78
In the Code Magnets solution, the line -

Weatherdata weatherData = (WeatherData)observable;

should not appear in the ForecastDisplay constructor, as it does now, but rather
as the first line in the update() method.


Anonymous   
Printed
Page 87
3rd answer, near middle of paragraph

would probably be wastefu). Following
should be:
would probably be wasteful). Following

Anonymous    Aug 19, 2011
Printed
Page 87
last A, first sentence

remove extra "the" before "knowing the domain"

...in designing OOP systems and also a matter of the knowing the domain...
should be:
...in designing OOP systems and also a matter of knowing the domain...

Anonymous    Aug 19, 2011
Printed
Page 91
The two ConcreteDecorators

ConcereteDecoratorA and ConcereteDecoratorB
should be:
ConcreteDecoratorA and ConcreteDecoratorB

Anonymous    Aug 19, 2011
Printed
Page 91
bottom left bullet text

"The ConcreteDecorator has an instance variable for the thing it decorate..
should be:
"The ConcreteDecorator has an instance variable for the thing it decorates."

Anonymous    Aug 19, 2011
Printed
Page 94
in the first paragraph,

the word
"lotte"
should be:
"latte"

Anonymous    Aug 19, 2011
Printed
Page 96
Third annotation down on Espresso, second sentence

"Now that we don't need to worry about ..."
should read just
"We don't need to worry about ..."

Anonymous    Aug 19, 2011
Printed
Page 96
Annotation at the bottom of the page

"You can create the other three Beverage classes (DarkRoast, Decaf, Esperesso)
in exactly the same way.
should read:
"You can create the other two Beverage classes (DarkRoast and Decaf) in exactly the same way.

Anonymous    Aug 19, 2011
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 ...

Note from the Author or Editor:
change:
Here, we're going to to pass the beverage ...
to:
Here, we're going to pass the beverage ...

Anonymous    Aug 19, 2011
Printed
Page 97
Note under cost() function

Both the cost() and getDescription() function notes say "first we delegate", however there is inconsistent ordering of the return syntax of the code (local value + delegated value in cost() vs. delegated value + local value in getDescription())

Note from the Author or Editor:
fixed in updated files/ for next printing

Martin Rhodes  Nov 12, 2012 
Printed
Page 98
Starred annotation under the code

We're going to see a much better way of creating decorated objects when we cover the
Factory and Builder Design Patterns.
add to the existing annotation:
Please note that the Builder Pattern is covered in the Appendix.

Anonymous    Aug 19, 2011
Printed
Page 99
Question 1

"specfic"
should be:
"specific"

Anonymous    Aug 19, 2011
Printed
Page 99
second Q paragraph


At the end of the second Question paragraph, it says "which means it would not
including Whip in the order."

That should be "include" instead of "including."

Anonymous    Aug 19, 2011
Printed
Page 99
Last Question

The second sentence says "Say, I wanted my getDecription..."
it should say: "Say, I wanted my getDescription..."

Anonymous    Aug 19, 2011
Printed
Page 99
Last Answer

The last sentence says "Note that getDecription..."
it should say: "Note that getDescription..."

Anonymous    Aug 19, 2011
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..."

Note from the Author or Editor:
change:
"FileInputStream is the component that's being decorated The Java I/O..."
To:
"FileInputStream is the component that's being decorated. The Java I/O..."

Anonymous    Aug 19, 2011
Printed
Page 100
second handwritten comment

"BufferedInputSream .... augments the interface with a new method called readLine() ..."


There is no such method in java docs.

Note from the Author or Editor:
Fixed in Updated Files/ for next printing

ntls  Jul 26, 2013 
Printed
Page 100
Last Paragraph

FilterInputStream is not an abstract class, taking as reference JDK 12.0.2, so it cannot be an abstract decorator class. Page 101 talks about concrete decorators (i.e BufferedInputStream) that are not.

...
public
class FilterInputStream extends InputStream {
...

Note from the Author or Editor:
This is getting fixed in the new edition.

Alberto Pomella  Jul 28, 2019 
Printed
Page 106
1st box

public float cost(){
should be:
public double cost(){

Anonymous    Aug 19, 2011
Printed
Page 106
in the bottom solution box at the very top

"double mocha soy lotte with whip"
should be:
"double mocha soy latte with whip"

Anonymous    Aug 19, 2011
Printed
Page 107
getSize method of Soy class

public getSize() {
SHOULD BE:
public int getSize() {

Anonymous    Aug 19, 2011
Printed
Page 107
"handwritten" note in middle of page on the right hand side

The note suggests that the getSize method should be moved to the abstract class CondimentDecorator since it is used by all the condiment decorators. I get a null pointer exception if I do that. However you should put an abstract getSize method in the abstract class to ensure that each condiment decorator implements it.

Note from the Author or Editor:
Fixed in Update Files/ for reprint

Donald Cook  Aug 21, 2013 
Printed
Page 107
"handwritten" note in middle of page on the right hand side

Here's how to fix the problem pointed out by my post dated Aug 21, 2013.

Move the getSize() method to the abstract class CondimentDecorator as suggested.

Move the declaration for the instance variable beverage to the abstract class CondimentDecorator.

Remove the instance variable beverage from each of the other concrete condiment classes.

Note from the Author or Editor:
Fixed in Updated Files/ for next printing

Donald Cook  Aug 22, 2013 
Printed
Page 109
last line

embarrasing -> embarrassing

Anonymous    Aug 19, 2011
Printed
Page 113
last line in highlighted block of code.

pizza = new eggiePizza();
should be:
pizza = new VeggiePizza();

Anonymous    Aug 19, 2011
Printed
Page 114
last 3rd line in last paragraph

a client of that object. Any time it needs a pizzam it asks
should be:
a client of that object. Any time it needs a pizza it asks

Anonymous    Aug 19, 2011
Printed
Page 115
bottom right, answer to last question

"But remember it also has the disadvanage..."
should be:
"But remember it also has the disadvantage..."

Anonymous    Aug 19, 2011
Printed
Page 117
Bottom "Just another reminder:.." Second line;

"write a class the implements ...
should be
"write a class that implements ...

Anonymous    Aug 19, 2011
Printed
Page 119
third line in the two listings

line 3: There should be "nyStore.orderPizza" instead of "nyStore.order"

line 6: There should be "chicagoStore.orderPizza" instead of "chicagoStore.order"

Anonymous    Aug 19, 2011
Printed
Page 120
last line in code example

abstract createPizza(String type);
should be:
abstract Pizza createPizza(String type);

Anonymous    Aug 19, 2011
Printed
Page 121
Second paragraph

Erroneous space after first "thick".

Anonymous    Aug 19, 2011
Printed
Page 130
black output window at the bottom

"Grated Regiano cheese"
should be:
"Grated Reggiano Cheese"
[in order to match the code shown on page 129]

Anonymous    Aug 19, 2011
Printed
Page 134
Last paragraph

The last sentence should start with
'They say "decide"'

Anonymous    Aug 19, 2011
Printed
Page 135
Last Answer (A)

framework that let's >> framework that lets

Thomas Kennedy  Nov 03, 2010  Aug 19, 2011
Printed
Page 144
Last paragraph

"different set that needs to shipped..."
should be
"different set that needs to be shipped..."

Anonymous    Aug 19, 2011
Printed
Page 145
in the California group;

the seafood should be "Calamari", not "Camari"

Anonymous    Aug 19, 2011
Printed
Page 148
UML drawing of classes at the bottom of the page

"Mozzarella" class name should be "MozzarellaCheese" (to match p. 145)

Anonymous    Aug 19, 2011
Printed
Page 150 & 151
last method

Wrong way double-quotes

Anonymous    Aug 19, 2011
Printed
Page 159
2nd paragraph, right column (Abstract Factory)

"...because I am used to create entire families..."
should read:
"...because I am used to creating entire families..."

Anonymous    Aug 19, 2011
Printed
Page 159
4th paragraph

Factory Method phrase "... and override a factory method." should, I think, be " ... and implement a factory method."
Prior to this statement no use of 'overriding' had been mentioned in the description of the Factory Method Pattern. I presume that this statement would, for example, refer to the creation of a method like 'createPizza()' in a subclass like NYPizzaStore.

Note from the Author or Editor:
Cleaned up the language a bit to clarify on pages 159 and 121 in Updated Files/

Anonymous  Apr 01, 2010 
Printed
Page 160
text floating in bottom-middle of diagram

"Subclasses are instaniated
by the Factory Methods."

It should be

"Subclasses are instantiated
by the Factory Methods."

Anonymous    Aug 19, 2011
Printed
Page 162
Abstract Factory Card

depedent
should be:
dependent

Anonymous    Aug 19, 2011
Printed
Page 173
floating "a" inside "Watch it" box on the top right of the page

"you'll see a
it has a few issues
later in the chapter".

It should be

"you'll see
it has a few issues
later in the chapter"

Anonymous    Aug 19, 2011
Printed
Page 173
bottom of page

On the "Code Up Close" section:
uniqueInstance = new MyClass();
this should be
uniqueInstance = new Singleton();

Note from the Author or Editor:
Fixed in Updated Files/ for next printing

Martin  Dec 21, 2010 
Printed
Page 175
fill method

"fill" is rendered improperly (with a hard-to-read font)

Anonymous   
Printed
Page 179, 204
"Bet the JVM" code example

code example;
ChocolateBoiler boiler =
ChocolateBoiler.getInstance();
fill();
boil();
drain();
should be:
ChocolateBoiler boiler =
ChocolateBoiler.getInstance();
boiler.fill();
boiler.boil();
boiler.drain();

(204, Text above the black box on the bottom-right of the page:

"Here, create a command and pass it to the receiver."
it should be :
"Here, create a command and pass the receiver to it."

Anonymous    Aug 19, 2011
Printed
Page 189
Use eager instantiation answer

statically inializing >> statically initializing

Thomas Kennedy  Nov 04, 2010  Aug 19, 2011
Printed
Page 194
UML diagram: method section of "Hottub" box

"setTemperaturet()" should read "setTemperature()"

Note from the Author or Editor:
Fixed in Updated Files/

xehpuk  May 12, 2010 
Printed
Page 195
Last paragraph by Mary

"slot1 = Hottub" should read "slot1 == Hottub"

Note from the Author or Editor:
Fixed in updated files/

xehpuk  May 12, 2010 
Printed
Page 207
in the text pointing to the Command interface,

the word should be "perform", not "preform"

Anonymous    Aug 19, 2011
Printed
Page 208
Second paragraph, Sue's statement

Sue's last sentence ends with a colon, but no example follows it.

After the colon at the end of Sue's statement, add:

"onCommands[0] = onCommand;
offCommands[0] = offCommand;

and so on for each of the seven command slots."

Anonymous    Aug 19, 2011
Printed
Page 209
swapped letters "ie" in "reciever", bottom right of the page

"(3) In the execute() method actions
are invoked on the reciever."

It should be:

"(3) In the execute() method actions
are invoked on the receiver."

Anonymous    Aug 19, 2011
Printed
Page 212
first paragraph

"Home Automation of Bust" should be "Home Automation or Bust"

Anonymous    Aug 19, 2011
Printed
Page 216
In the thought bubble

Printed:

Note from the Author or Editor:
Should replace "!!!!" with "?!"

B Hillebrecht  Jun 26, 2009  Aug 19, 2011
Printed
Page 223
RemoteLoader output window

The output in the window on page 223 does not match the code on page 222.

Code has
remoteControl.setCommand(0, ceilingFanMedium, ceilingFanOff);
remoteControl.setCommand(1, ceilingFanHigh, ceilingFanOff);

The output window has:
[slot 0] headfirst.command.undo.NoCommand headfirst.command.undo.NoCommand
[slot 1] headfirst.command.undo.CeilingFanMediumCommand headfirst.command.undo.CeilingFanOffCommand
[slot 2] headfirst.command.undo.CeilingFanHighCommand headfirst.command.undo.CeilingFanOffCommand

but should be:
[slot 0] headfirst.command.undo.CeilingFanMediumCommand headfirst.command.undo.CeilingFanOffCommand
[slot 1] headfirst.command.undo.CeilingFanHighCommand headfirst.command.undo.CeilingFanOffCommand
[slot 2] headfirst.command.undo.NoCommand headfirst.command.undo.NoCommand

Anonymous    Aug 19, 2011
Printed
Page 230
1st bullet point

"The Command Pattern decouples an object, making
a request from the one that knows how to perform it."

remove comma

Anonymous    Aug 19, 2011
Printed
Page 230
5th bullet point

"excute()" should be "execute()"

Anonymous    Aug 19, 2011
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

Note from the Author or Editor:
Fixed in updated files/

Anonymous  Jun 26, 2008 
Printed
Page 233
undo() definition of top exercise

The boxed text reads:
"for (int i = 0; i < commands.length; i++) {
commands[i].undo();
}"
The commands need to be undone in *reverse* order, like so:
"for (int i = commands.length - 1; i >= 0; i--) {
commands[i].undo();
}"

Anonymous    Aug 19, 2011
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

Note from the Author or Editor:
Fixed in Updated Files/

Ryan  Sep 18, 2009 
Printed
Page 240
Test run at the bottom

Replace RemoteControlTest with DuckTestDrive and remove newlines that are not in the
code:

%java DuckTestDrive
The Turkey says...
Gobble gobble
I'm flying a short distance

The Duck says...
Quack
I'm flying

The TurkeyAdapter says...
Gobble gobble
I'm flying a short distance
I'm flying a short distance
I'm flying a short distance
I'm flying a short distance
I'm flying a short distance

Anonymous    Aug 19, 2011
Printed
Page 245
first paragraph

")." should be ".)"

Anonymous    Aug 19, 2011
Printed
Page 273
1st paragraph

Spelling mistake: 'Enumaration'.

Note from the Author or Editor:
Enumaration -> Enumeration

Anonymous  Aug 29, 2008  Aug 19, 2011
Printed
Page 278
Top of page, annotation next to prepareRecipe(), 2nd sentence

"the second and forth steps are different, ..."
should be
"the second and fourth steps are different, ..."

Anonymous    Aug 19, 2011
PDF
Page 283
in the right-down area, annotation to the "Tea" class

"Tea needs to define brew() and addCondiments() ? the two abstract methods from Beverage."

Should it be "from CaffeineBeverage"?

Note from the Author or Editor:
Yes, it should! Fixed in Updated Files/

Anonymous  Sep 20, 2011 
Printed
Page 292
first "handwritten" comment

"a condiments" should be "condiments"

Anonymous    Aug 19, 2011
PDF
Page 292
The code

Should the prepareRecipe() method be "final"?

Note from the Author or Editor:
Yes, it should! Fixed in Updated Files/

Anonymous  Sep 20, 2011 
Printed
Page 295
bottom right of page, last paragraph

"so you can implement these as hooks rather than abstract classes,"

It should be:

"so you can implement these as hooks rather than abstract methods,"

Anonymous    Aug 19, 2011
Printed
Page 298
third description in Who Does What? box

"Subclasses decide which concrete classes to create."

It should be:

"Subclasses decide which concrete classes to instantiate."

Anonymous    Aug 19, 2011
Printed
Page 300
first "handwritten" comment

"paired" should be "pared"

Anonymous    Aug 19, 2011
Printed
Page 305
Last Answer (A)

is used by the tempate -> is used by the template

Thomas Kennedy  Nov 09, 2010  Aug 19, 2011
Printed
Page 308
first "Template Method" paragraph

Missing terminating period

Anonymous    Aug 19, 2011
PDF
Page 309
the second-to-last block of Strategy

"But you have to depend on methods implemented in your superclass,"

should it be "in your subclass"?

Note from the Author or Editor:
Yes, it should! Fixed in Updated Files/.

Anonymous  Sep 21, 2011 
Printed
Page 321
bullet item #1

"...you'll need to call the getMenuItem() method ..."
should be:
"...you'll need to call the getMenuItems() method ..."

Anonymous    Aug 19, 2011
Printed
Page 321
second code excerpt

Improper facing closing double-quotes

Anonymous    Aug 19, 2011
Printed
Page 322, 328, 330
Sharpen your pencil box

Items are lettered A, B, C, C, D, E. Should be A, B, C, D, E, F.

[328 + 330] 1st paragraph, 2nd sentence;
The "getIterator()" text on pages 328 and 330 (first paragraph, both pages)
should be replaced with "createIterator()"

Anonymous    Aug 19, 2011
Printed
Page 332
last line, first column

you'llwant
should read:
you'll want

Anonymous    Aug 19, 2011
Printed
Page 338
3rd Question

"Could I implement an Iterator that can go backwards as well as backwards?"
should be:
"... backwards as well as forwards?"

Anonymous    Aug 19, 2011
Printed
Page 342
bottom of page, shaded code block - remove() implementation

I believe the remove() implementation of the DinerMenuIterator should be subtracting 1 from the position field when it succeeds in removing an item. This is because the loop is shifting all items in the array backwards and setting the last item to null. If the position remains unchanged, the next() call will skip the item that came after the removed item.

As it is implemented right now:
[*A, B, C, D] position (*) = 0
[A, *B, C, D] next() called, position = 1, A returned
[B, *C, D, null] remove() called, position =1, next() will now return C instead of B

Note from the Author or Editor:
We'll be updating this chapter quite a bit in 2nd ed (working on that now) and will deal with this issue. Thx.

Sebastian Murgu  Nov 15, 2019 
Printed
Page 350, 382
6th magnet

The code
position = rightNow.DAY_OF_WEEK % 2;
should be:
position = rightNow.get(Calendar.DAY_OF_WEEK) % 2;

Anonymous    Aug 19, 2011
Printed
Page 354
1st paragrah

second to the last line of paragraph:
"... chefs that the time as come for us..."
should be
"... chefs that the time has come for us..."

Anonymous    Aug 19, 2011
Printed
Page 359
UML diagram: methods for MenuComponent and Menu

"add(Component)" and "remove(Component)" should read
"add(MenuComponent)" and "remove(MenuComponent)"

Note from the Author or Editor:
Yes they should! Fixed in Updated Files/

xehpuk  May 10, 2010 
Printed
Page 365
Description for Apple Pie on the desertMenu definition

"icecream" should be "ice cream"

Anonymous    Aug 19, 2011
Printed
Page 365
Second hand-written comment from the top

Text states:
"We also need two top level menu now that we'll name allMenus."

Corrected Version:
"We also need a top level menu that we'll name all Menus."

Anonymous    Aug 19, 2011
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.

Note from the Author or Editor:
fixed in Updated Files/

Anonymous   
Printed
Page 368,373,374
the method Menu.createIterator() on p368 & the method of Waitress.printVegetarianMenu() on p373

The menuItems(like Apple Pie, Cheesecake and Sorbet) show up multiple times on p374 because of the buggy code on p368 and p373.

on p368 the following code

public Iterator createIterator() {
if (iterator == null) {
iterator = new CompositeIterator(menuComponents.iterator());
}
return iterator;
}

should be replaced by

public Iterator createIterator() {
return menuComponents.iterator();
}

on p373 the following code

public void printVegetarianMenu() {
Iterator iterator = allMenus.createIterator();

should be replaced by

public void printVegetarianMenu() {
Iterator compositeIterator = new CompositeIterator(allMenus.createIterator());

then, we will have the internal iterator (menuComponents.iterator()) and the external one(compositeIterator) departed and have the result on p374 corrected with the definitely only one stack.

Note from the Author or Editor:
See previous note. this is fixed in Updated Files/

chendong  Dec 08, 2012 
Printed
Page 368,373,374
the method Menu.createIterator() on p368 & the method of Waitress.printVegetarianMenu() on p373

The menuItems(like Apple Pie, Cheesecake and Sorbet) show up multiple times on p374 because of the buggy code on p368 and p373.

on p368 the following code

public Iterator createIterator() {
if (iterator == null) {
iterator = new CompositeIterator(menuComponents.iterator());
}
return iterator;
}

should be replaced by

public Iterator createIterator() {
return menuComponents.iterator();
}

on p373 the following code

public void printVegetarianMenu() {
Iterator iterator = allMenus.createIterator();

should be replaced by

public void printVegetarianMenu() {
Iterator compositeIterator = new CompositeIterator(allMenus.createIterator());

then, we will have the internal iterator (menuComponents.iterator()) and the external one(compositeIterator) departed and have the result on p374 corrected with the definitely only one stack to store iterators.

Note from the Author or Editor:
This has been fixed (Updated Files/). We actually only need the first check for the iterator (page 368).

chendong  Dec 08, 2012 
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.

Note from the Author or Editor:
Yup! fixed in Updated Files/

Anonymous   
Printed
Page 374
Description for Apple Pie on the menu printout (in two places)

"icecream" should be "ice cream"

Anonymous    Aug 19, 2011
Printed
Page 378
11 down:

Hashtable and ArrayList both implement this interface.
Should be:
ArrayList implements this interface.

Anonymous   
Printed
Page 379
Who Does What?

Replace the text "State Pattern" at the top left of the diagram with "Strategy Pattern",
and replace the description on the bottom right of the page, "Allows an object to
change its behavior when some state changes" with "Encapsulates
interchangeable behaviors and uses delegation to decide which one to use."

Anonymous    Aug 19, 2011
Printed
Page 381
Sharpen your pencil solution box

Items are lettered A, B, C, C, D, E. Should be A, B, C, D, E, F.

Anonymous    Aug 19, 2011
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"

Note from the Author or Editor:
fixed in Updated Files/

Anonymous   
Printed
Page 392
first sentence

A comma is missing after "methodology".

Anonymous    Aug 19, 2011
Printed
Page 396
Sharpen your pencil box

Items are lettered A, B, C, C, D, E. Should be A, B, C, D, E, F.

Anonymous    Aug 19, 2011
Printed
Page 397
repeated "this" in second to last sentence by Joe

"I wonder if this will this make it easier to add new states?"
It should be:
"I wonder if this will make it easier to add new states?"

Anonymous    Aug 19, 2011
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."

Note from the Author or Editor:
changed to "the CEO" in Updated Files/

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    Aug 19, 2011
403
Code Segment

Line: 'State state = soldOutState', but 'soldOutState' at that point is null.

Note from the Author or Editor:
Indeed! Fixed in Updated Files/

Anonymous  Feb 22, 2013 
Printed
Page 412
left hand side, bottom

Currently: The only requirement is that your state objects do not keep their own internal state; ...

I think the last this should be:
Currently: The only requirement is that your state objects do not keep their own internal context; ...

Note from the Author or Editor:
fixed in updated files/

Anonymous  Apr 15, 2010 
Printed
Page 413
Code snippet

Always printing "YOU'RE A WINNER!..." would be a mistake especially when the count of the number of gumballs = 1 and the WinnerState dispense() method is invoked. Under this scenario the winning message for two gumballs would be printed; however, only one gumball would be released. It seems wiser to place the println for the winning message within the else statement (first line after the else) before releasing the second ball.

Note from the Author or Editor:
Agreed! I updated the code (Updated Files/)

Corey Cotton  Jun 26, 2010 
Printed
Page 425
Sharpen your pencil box

Items are lettered A, B, C, C, D, E. Should be A, B, C, D, E, F.

Anonymous    Aug 19, 2011
Printed
Page 428
Top (Who does What)

The solutions for Template Method and Strategy are wrong;
Template Method should point to the solution that Strategy is pointing to
(i.e., the solution beginning, "Subclasses decide...")
and Strategy should point to the solution that Template Method is pointing to
(i.e., the solution beginning, "Encapsulate interchangeable behaviors...").
The solution for State is correct.

Anonymous    Aug 19, 2011
428
Solution to "Sharpen your pencil"

The solution for dealing with the refill() transition is counter to the entire chapter.

This is a transition which means that it is a method for each of the State Classes not a method for the GumballMachine.

If the state == QuarterInserted when refill() is called,
then the following code would result in the Consumer losing his/her quarter since the state machine is forced to noQuarterState.

Additionally, the count of gumballs will get skewed in any state EXCEPT for SoldOutState:

/* This code will yield suspect results */
void refill(int count) {
this.count = count;
state = noQuarterState;
}

Note from the Author or Editor:
I agree. I've fixed this in Updated Files/

Anonymous  Dec 11, 2012 
Printed
Page 431
code

Improper facing double-quotes

Anonymous    Aug 19, 2011
Printed
Page 445
Last "hand-written" note on bottom of page

The word "rmiregistery" should be "rmiregistry".

Anonymous    Aug 19, 2011
Printed
Page 446
Code Up Close, 1st "callout"

Book says:
"The client always uses the remote implementation as the type of the service."
Should say:
"The client always uses the remote interface as the type of the service."

Anonymous    Aug 19, 2011
Printed
Page 448
Geek bits, first paragraph

>hand-deliver the these

Note from the Author or Editor:
change:
hand-deliver the these
to:
hand-deliver these

Thomas Kennedy  Nov 10, 2010  Aug 19, 2011
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  Jun 24, 2009  Aug 19, 2011
Printed
Page 455
GumballMonitorTestDrive code

As written, the GumballMonitorTestDrive will fail with a NullPointerException if a GumballMachineRemote fails to initialize.

If Naming.lookup() throws a RemoteException for the the second location, the second index in the GumballMonitor[] will remain null.

Later, you loop over all the elements in GumballMonitor[] and call report() -- which will throw a NullPointerException on the second index.

Your example should have (at the very least) done a null check on the array elements. Or (even better) used a Collection<GumballMonitor> and iterated over elements added only if the Naming.lookup() was successful.

Note from the Author or Editor:
Yes, we should check for a null pointer. But in this example, we can assume that the remote will always start correctly.

Anonymous  Jun 24, 2009 
Printed
Page 456
Code execution windows at the bottom of the page

java GumballMachine santafe.mightgumball.com 100
should be:
java GumballMachineTestDrive santafe.mightgumball.com 100

Anonymous    Aug 19, 2011
Printed
Page 457
Code execution window

java GumballMonitor
should be:
java GumballMonitorTestDrive

Anonymous    Aug 19, 2011
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]

Note from the Author or Editor:
Agreed! Thanks. Fixed in Updated Files/

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    Aug 19, 2011
Printed
Page 480
interface diagram

The text says "Look at the InvocationHandler interface:" but the diagram that follows is of OwnerInvocationHandler which is a class. The diagram should say ' <<interface>> InvocationHandler'.

Note from the Author or Editor:
Yes. Thanks!

Thomas Kennedy  Nov 15, 2010 
Printed
Page 507
System.out.println() line in code

The message text in the System.out.println() statement does not match the output in the window below.
Code has "The ducks quacked <n> times".
The output window has "<n> quacks were counted".

This error also occurs in several other downstream pages, 510 and 514 at least.

Anonymous   
Printed
Page 521
Step 18

Second sentence should read "Let's update the simulator and give it a try:" not "...give it try:"

Anonymous    Aug 19, 2011
Printed
Page 526
bottom paragraph, first column

"applications" should be "application's"

Anonymous    Aug 19, 2011
Printed
Page 527
second to last stanza in left column

"repititious" should be "repetitious"

Anonymous    Aug 19, 2011
Printed
Page 527
bottom of the page

Update the link to the MVC song to: http://www.youtube.com/watch?v=YYvOGPMLVDo

Elisabeth Robson
Elisabeth Robson
 
Jun 01, 2009  Aug 19, 2011
Printed
Page 545
Brain Power

interface of the HeatModel should be interface of the HeartModel.

Note from the Author or Editor:
Fixed in Updated Files/

Thomas Kennedy  Nov 17, 2010 
Printed
Page 553
the code block

the doGet() should also be doPost(), for the JSP on the page 554 that requires a doPost() method.

Note from the Author or Editor:
Fixed in Updated Files/

tisiphone  May 30, 2009 
Printed
Page 557
1st paragraph, 2nd to last sentence

minor typo:
"and displayed in a seb browser."
should be
"and displayed in a web browser."

Anonymous    Aug 19, 2011
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);
}


Note from the Author or Editor:
Yes! Thanks

Anonymous  May 20, 2008 
PDF
Page 584
3rd paragraph from the bottom (Jim:)

"...I understand each classes? role."

Should be:

"....I understand each class's role."

Note from the Author or Editor:
Fixed for next printing (UpdatedFiles/)

Anonymous  Nov 27, 2013 
PDF
Page 588
2nd column, 4th description

"Ensures one and only object is created."

Was probably meant to read:

"Ensures one and only one object is created."

This is repeated in the exercise's solution on page 610.

Note from the Author or Editor:
Fixed in Updated Files/ for next printing

Anonymous  Nov 27, 2013 
Printed
Page 591
bottom right answer on the page

remove the sentence:
"It's a subtle distinction, especially when you consider the structural
similarities between Decorator (a structural pattern) and Proxy (a
behavioral pattern)."

Anonymous    Aug 19, 2011
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()".

Note from the Author or Editor:
Fixed in Updated Files/

Anonymous  May 21, 2008 
Printed
Page 620
repetition production

Improper facing single quote to the right of the left parenthesis.

Anonymous    Aug 19, 2011
Printed
Page 620
repetition

repetition ::= ... <expresion> should be <expression>

Thomas Kennedy  Nov 18, 2010  Aug 19, 2011