Agile Java Errata

Page 14

Technically, the Agile Java definition of encapsulation is that of information hiding. A more precise definition of encapsulation is “the inclusion of both the methods and the data within an object.” The Agile Java definition is still correct but is closer to the more generalized definition of encapsulation: “the inclusion of one thing within another so that the included thing is not apparent.”

Page 14

In the first paragraph, “I send you a message to you” should read “I send you a message.”

Page 45

The first sentence of the first paragraph is more accurately written as: “In the second statement, Java assigns the memory address of this returned String object to a String local variable, defined on the left hand of the statement as studentName.”

Page 45

The caret in the first compilation error listing should appear directly beneath the letter s in student.getName().

Page 17

The footnote reference should be [Fowler2003], not [Fowler2000].

Page 62

“Exercises appear at the end of lesson” should read “Exercises appear at the end of each lesson.”

Page 77

In the first paragraph, replace:
Each time the getNumberOfStudents message is sent
with:
Each time the getAllStudents message is sent

Page 77

In Figure 2.4, the variable names listed in the table to the right should read student1 and student2.

Page 80

Second to last sentence on the page, “CourseSesson” should be “CourseSession.”

Page 91

The header for the page should read “Deprecation Warnings,” not “Depreciation Warnings.”

Page 100

The reference to TestPawn in exercises 1 should be changed to PawnTest.

Page 101

The reference to TestPawn in exercises 7 should be changed to PawnTest.

Page 113

In the third bullet, replace:
testReport constructs its own CourseSession object
with:
testRosterReport constructs its own CourseSession object

Page 116

In the code for testCreateDate, replace:
Calendar calendar = new GregorianCalendar();
with:
GregorianCalendar calendar = new GregorianCalendar();
(I haven’t talked about assignments to the interface type yet.)

Page 120

replace:
If you haven’t already done so, remove the testReport method from CourseSessionTest
with:
If you haven’t already done so, remove the testRosterReport method from CourseSessionTest

Page 120

replace:
you can decompose the code in writeReport
with:
you can decompose the code in getReport

Page 121

At the start of the third paragraph, replace:
move the studentinfo package down a level so that it is in a package named sis.reportinfo.
with:
move the studentinfo package down a level so that it is in a package named sis.studentinfo.

Page 123

In the last paragraph, first sentence, replace:
from the code in the reports package
with:
from the code in the report package
Also make the same replacement in the second paragraph on the page.

Page 139

The first sentence of the 2nd paragraph should read “The CourseSessionTest method testCount…”

Page 141

The code should use the newer construct session = createCourseSession(); instead of CourseSession.create(...)

Page 144

In the third paragraph, “Supplies a a shortcut” should read “Supplies a shortcut.”

Page 169

The first sentence of the first paragraph should read “You can use interfaces to break dependencies…”

Page 170

In the sidebar “More on this,” replace:
In the Student compareTo method
with:
In the CourseSession compareTo method

Page 180

The Student class declaration should not include the clause implements Comparable<Student>

Page 187

The Student class declaration should not include the clause implements Comparable<Student>

Page 199

In the final paragraph in the Maps section, replace
Add a new class named ReportCardTest to the sis.reports package.
with:
Add a new class named ReportCardTest to the sis.report package.

Page 202

The last sentence in the first paragraph should read “As a subclass, each of RegularGradingStrategy and HonorsGradingStrategy obtain all of the behaviors of BasicGradingStrategy.”

Page 227-228

The text on p.228 says “Also important is that the return type for the create method in SummerCourseSession and CourseSession is the abstract supertype Session.” Technically this is the best idea, but not essential–Java allows for covariant return types. In any case: here are the relevant snippets for what the code on p227 looks like after making that change. (Thanks Luke!)

   // in CourseSession.java, create should declare a return type of Session, not CourseSession:
   public static Session create(
      String department,
      // ....

   // in SummerCourseSession.java, create should declare a return type of Session, not SummerCourseSession:
   public static Session create(
      String department,
      // ...

Unfortunately there’s a little bit of ripple effect. You will also get some errors in the report test/code. Just follow the compile errors, and wherever you use the result of a create method call, you’ll need to change the type of the variable to which it’s assigned (either a local or a parameter) to be Session.

If that’s confusing: Please take a look at the Github repo for end-of-chapter 6. I’ve made some corrections to the downloadable source (I’m not sure it was really “end of chapter” source), and also added support for loading the project via Gradle.

Page 228

In the proposed example code, replace:
Session session = createSession(new Date());
with:
Session session = createSession("", "", new Date());
Better yet would be to add a createSession helper method that takes no arguments.

Page 234

The while loop example uses a StringBuffer instead of a StringBuilder. This really isn’t a problem since we’ve already discussed StringBuffer, but under J2SE 5.0 you will probably want to prefer use of the new StringBuilder class.

Page 234

The tokenize method at the bottom of the page should be named split.

Page 235

Eliminate the line comment from the first code listing.

Page 238

In the for loop statement in isPalindrome, the code should read:
forward++, backward--)
i.e. with two hyphens (minus signs) after backward. (It actually does have two hyphens, but the typeface used makes them appear as one.)

Page 242

Fibonacci is a bad, bad example to use for recursion. Write a test that determines fib(100) and see how long it takes.

Page 246

The footnote should refer to BitSet, not “BitSit.”

Page 273

“CheckedExceptinos” should be “CheckedExceptions.”

Page 338

After adding testKeys, getMessages method should be changed to public.

Page 342

In Table 9.1, the entry for “range” is blank (and “range” should be in the sans serif font). The entry should read “Creates an enum set initially containing all of the elements in a from-to enum range.”

Page 372

The story icon should appear beside the following paragraph, the one that starts with “You must assign passwords to students…”

Page 374

In the last paragraph, replace java.util.SecureRandom with java.security.SecureRandom.

Page 441

In the first code listing on the page, the assertion should read: assertTrue(classes.contains("sis.testing.SuiteBuilderTest.class"));

Page 444

Add the following code to the listing:

public TestSuite suite() {
   TestSuite suite = new TestSuite();
   for (String className: gatherTestClassNames()) {
      Class klass = createClass(className);
      suite.addTestSuite(klass);
   }
   return suite;
}

Page 528

“You can quickly add some time safety” should be “You can quickly add some type safety”

Page 597

The bottom compartment in the diagram shown in Figure 6 should read “South.” Duh.

Page 690

In the second line of the static initializer, the string literal should end with \\n instead of \\.

Page 693

The method getErrorOutput should return errorOutput.toString(), not output.toString().

Page 705

With respect to the definition for encapsulation, see the errata entry above for page 14.

Page 733

[Bloch2001] should show Bloch, Joshua as the author of Effective Java Programming Language Guide