Errata

Learning Java

Errata for Learning Java

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.

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.

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

Version Location Description Submitted by Date submitted
ePub Page examples
examples

As opposed to version 3, the link for the examples points to a git repository. The download does have the examples-eclipse.zip archive, but the instructions in the book don't work with eclipse. When I follow the instructions, a folder "LearningJava" is generated *inside* the previously created Learning Java project, and under that folder there are the bin and src folders. In Learning Java 3 the zip file structure did *not* include the Learning Java directory and it could be imported (following the Learning Java 4. ed instructions). So, I think you need to strip the LeaningJava folder from the zip archive. I've tried that but then the dot files parallel to bin and src don't work correctly, they form a hierarchy in Eclipse as follows:
src/ch02
...
src/ch14
src/ch15/web-annotations
...
JRE System Library
src
ch15
ch22


and while I can run the examples in e.g. ch02, there are errors in the ch15 and ch22 examples.

So, I think you may want to actually try to install your examples-eclipse.zip file *before* you upload it. It didn't work for me, while the 3. ed zip file worked.
Hope this helps, Erwin

Erwin J Prinz  Jun 28, 2013 
ePub Page epub
examples

I have tried to load the examples in Ubuntu 13.04 using the Eclipse Juno from eclipse.org, and also in Windows 7 using Eclipse Juno. The behavior is the same. From edition 3, the examples load and can be run and there are a few syntax errors (probably because I am running version 1.7 Java). From edition 4, the hierarchy gets screwed up because the zip file has more hierarchy (because it is probably the entire git project). If I follow the instructions, I can't run even the chapter 2 example without error, there is a message that there is no "main" method although there is one in the file, so the .classpath is probably wrong.
I also don't understand yet how to select the top level to import from the zip file (i.e. stripping higher levels) in Eclipse.
I edited the zip file to look more like version 3 (including the .classpath file) and then I can run the chapter 02 examples but some later examples have errors (I removed the entire bin directory, so this was probably to much).
So, it looks like the eclipse project zip file needs to be corrected to work with the instructions in the book. I guess fixing the zip file by itself teaches me something so I'll keep fixing once I am at that chapter :-)
I like the style of the book, and will just make up my own examples.

Erwin J Prinz  Jun 29, 2013 
ch06s04
Subclasses and Visibility

https://www.oreilly.com/library/view/learning-java-4th/9781449372477/ch06s04.html

I don`t see the page number

There is a phrase on the page "While it is possible to take a private method and override it with a public method in a subclass", but private method could not be override, may be should be “protected” instead of “private”?

Ihar Vaitovich  Nov 19, 2019 
Other Digital Version 1
Table of Contents on the web site listing

Hi! The Table of Contents listing for this book has 3-4 places where it looks like an editing comment in either a chapter header or ToC entry. Look for things like this:

Chapter 15 author="pat" timestamp="20121205T145416-0600" comment="The text here is a little jumpy... probably should have started from scatch instead of trying to edit it so much..."Web Applications and Web Services

Chris Spruck  Jun 24, 2013 
2
3rd paragraph

but we’ll need this when we have to explicitly pass a reference to our object to a method in another class. We often do this so that methods in other classes can invoke our public methods or use our public variables.

>>> Error: public methods or use our public variables => why it just has "public" because when we use "this" variable, we can refer to "private", "protected" variable and method

Anonymous  Jul 25, 2017 
Printed Page 24
top

The link to http://oreil.ly/Java_4E is broken.

(Also/FYI, page 28 (para. 2) refers to "a ZIP file containing all of the examples from this book ... at [the broken link].")

Dave Slomer  Aug 24, 2013 
PDF Page 28
instructions for importing examples-eclipse.zip

when examples-eclipse.zip is imported per the instructions in the book attempts to run any of the code in eclipse result in the following error message;

"Editor does not contain a main type".

A new subfolder is created as a result of the import as opposed to the imported files being incorporated into the "Learning Java" java project initially created per instructions on page 26

Anonymous  Jul 30, 2013 
PDF Page 28
Singapore

On page 28 you declare:

"Let?s load the examples from this book. You can find a ZIP file containing all of the examples from this book nicely packaged as an Eclipse project at http://oreil.ly/ Java_4E. The Eclipse version of the examples is called examples-eclipse.zip. (The file examples.zip holds the same examples but packaged slightly differently and without the Eclipse project files.)"

There link redirects to http://shop.oreilly.com/product/0636920023463.do which has a link saying "Download Example Code" which takes you to https://github.com/patniemeyer/learningjava

There is a zip file named "learningjava-master.zip" but no archive named "examples-eclipse.zip".

Furthermore, it does not import as an source directory.

And finally, once you change it to a source directory, it does not run.

28 pages into the book and the examples do not work. Pathetic.

And nobody seems to be reviewing the errata and confirming if they are accurate.

I bought a book to learn, not to waste my time.

John Berns  Sep 14, 2013 
PDF Page 28
Singapore

Eclipse setup, importing of sample code are completely broken; files referenced are not available on the sample code download site. Other similarly named files import but won't run due to errors.

Using OS X and Latest Eclipse version (Kepler).

Book is useless without being able to run samples.

John Berns  Sep 14, 2013 
PDF Page 28
Singapore

Instructions to load example code into Eclipse is incorrect. Following book results in errors and code does not run.

See detailed description of SOLUTION I posted at:

http://support.oreilly.com/oreilly/topics/where_is_the_examples_eclipse_zip_file

John Berns  Sep 15, 2013 
PDF Page 28
First paragraph

The book indicates that one should find the file examples-eclipse.zip at the provided link. However the link leads to the product page. I followed the examples link to the GitHub repo. I cloned the repo and assumed that would work. However the code there works on the command line but creates errors re: there being no main when imported into Eclipse. I then found the compressed archive on the Git page, so I downloaded and imported that. Same errors. It was only after searching through the archive that I found the Eclipse folder and imported the archive therein.

Bryan Dobberstein  Sep 25, 2013 
PDF Page 28
2

Others have already commented on it, but your examples simply do not work well when imported into the Eclipse editor.

You are led to a Github repo. Oddly when you download the zip file, there is a bunch of .svn directories that will not be handled correctly. (Why have svn directories if you are using Git?)

When I import, there are 308 errors and 263 warnings.

This gives me no confidence to proceed with the book at all mainly because I have no idea if this is just some oddity with how choices were made in terms of deploying the examples or if the examples are just crap to begin with.

I usually have very good luck with O'Reilly books so I'm guessing it's just a case that these particular authors did a particularly poor job. Incidentally, at least acknowledging these problems would probably be warranted at this point; you know, just so people think you actually care about the consumer experience.

Jeff Nyman  Dec 08, 2013 
PDF Page 35
HelloComponent code

The following import is missing from the code:

import javax.swing.*;

Calvin D  Dec 05, 2013 
Printed Page 38
Figure 2-6

The class hierarchy used to illustrate inheritance shows HelloJava1 as a subclass of JComponent. There is no mention of HelloJava1 previously (only HelloJava and HelloJava2) and this should actually be HelloComponent which extends JComponent in the previous example.

Also, the title bar in the figure 2-5 does not match the code.

Benjamin Petersen  Jul 11, 2013 
Printed Page 38
Figure 2-6

The class hierarchy used to illustrate inheritance shows HelloJava1 as a subclass of JComponent. There is no mention of HelloJava1 previously (only HelloJava and HelloJava2) and this should actually be HelloComponent which extends JComponent in the previous example.

Also, the title bar in the figure 2-5 does not match the code.

Benjamin Petersen  Jul 11, 2013 
60
United States

The 1st examples HelloJava1.java-HelloJava4.java do not contain a main() so they are unable to compile.

Matt M  Jul 05, 2013 
ePub Page 84% in book (epub)
First paragraph of Appendix A, epub edition

"develoment tools"
should be spelled
"development tools".

Erwin J Prinz  Jun 23, 2013 
Printed Page 90
code in 2nd 3rd paragraph

the declaration of pi does not compile. "F" is missing at the end of the number. Without "F" the literal is assumed to be double and can not be implicitly converted to float. Another alternative is to declare pi as double.

Yahya Almubarak  Apr 16, 2015 
Printed, PDF, ePub Page 100
programmatic loop atop page

The loop does not contain a break or a continue statement to illustrate the optional label that control can be forced to branch to.

I.e., surely the authors intended to include, in this code "outline", something such as either or both of the following:

break LabelOne;

continue LabelTwo;

Dave Slomer  Aug 25, 2013 
Printed Page 112
3rd paragraph under heading "Throwing Exceptions"

The sentence reading "...the Exception object's getMessage() method" should read "...the Throwable object's getMessage() method" -- the getMessage() method is a member of the Throwable class, rather than the Exception class (which inherits from Throwable).

Scott Wright  Jan 12, 2016 
Printed Page 114
3rd code fragment

"catch ( IOException cause )" should be "catch ( IOException e )". The subsequent code references the variable "e", not the variable "cause".

Eric K  Jul 24, 2013 
Printed Page 114
middle of page

At the page 114, code sample:
try {
// ...
}
catch ( IOException cause ) {
log( e ); // Log it
throw e; // rethrow it
}
It seems that the authors meant to write log(cause) and throw (cause)
but just copied the part of the previous code example.

Anonymous  Aug 12, 2014 
Printed Page 120
3rd command

There is a missing blank space after the "...". The command line should read "% java -ea:com.oreilly.examples... MyApplication". In other words, "MyApplication" should be a separate word.

Eric K  Jul 24, 2013 
Printed Page 120
code in the 2nd paragraph

Semicolon is missed t the end of the last statements.

Yahya Almubarak  Apr 16, 2015 
Printed Page 123
last paragraph, second sentence

The element's index is 0 or 19, not the element itself.

Yahya Almubarak  Apr 16, 2015 
Printed Page 126
5th paragraph

"ArrayscopyOf" should be "Arrays.copyOf" in the sentence "An easier way is to use the java.util.Arrays.copyOf() and copyOfRange() methods."

Eric K  Jul 24, 2013 
Printed, PDF, ePub Page 126
Just before last code segment

Missing period in " ArraysCopyOf " (no such method), which SHOULD read as shown:

Arrays.CopyOf

Dave Slomer  Aug 25, 2013 
Printed Page 126
4th paragraph, 1st sentence

A period between the class name and the method is missing. It should read java.util.Arrays.copyOf

Yahya Almubarak  Apr 16, 2015 
PDF Page 140
example

// instance var = local vra
should be:
// instance var = local var

Brian Tkatch  May 15, 2015 
PDF Page 176
beginning of bottom paragraph

"Abstract classes provide a framework for classes that is to be “filled in” by the implementer." should be "that are". The classes are filled in, not the framework.

Brian Tkatch  May 18, 2015 
PDF Page 177
2nd paragraph in Interfaces

"Similarly, an interface is a list of methods that define "

"that defines" The list defines.

"some set of behavior for an object. Any class that implements each method listed in the interface"

"all the methods" "each" might work, "every" is better. But "all" states most clearly that all the methods must be defined.

Brian Tkatch  May 18, 2015 
PDF Page 192
3rd paragraph, 3rd line

"To do this requires that "

Probably should read, "Doing this requires".

Otherwise, "To do this, the inner class must be"

In either case, "that" is redundant.

Brian Tkatch  May 18, 2015 
Printed Page 196
1st code example

The static class "MigrationPattern" needs the public access modifier added to it, otherwise the code example immediately following it doesn't work.

Jason Gero  Jan 30, 2016 
PDF Page 227
first line

List<String> listOfStrings = new ArrayList<String>

should be:

List<String> listOfStrings = new ArrayList<String>();

missing parentheses and semi-colon at end of line.

Brian Tkatch  May 19, 2015 
Printed Page 230
1st example

When I try the example I get this:

Compiled from "List.java"
public interface java.util.List<E> extends java.util.Collection<E> {
.........
public abstract boolean add(E);
public abstract E get(int);

This doesn't look like the raw type suggested.

Andrew Chapman  Feb 11, 2014 
PDF Page 235
3rd paragraph under Casts

"The cast is plausible here because a Collection<Date> is assignable from and could actually be a List<Date>."

Should probably be:

"The cast is plausible here because a Collection<Date> is assignable from--and could actually be--a List<Date>."

Brian Tkatch  May 20, 2015 
PDF Page 249
United States

In this code:

class GenericClass< T > {
// method using generic class parameter type
public void T cache( T entry ) { ... }
}

is "void" there erroneously? I entered the code (replacing "..." with "return entry;" in the method body) into eclipse and it generated an error. Removing void corrected the issue. Is this just some syntactic sugar I'm not aware of?

Chap Huskison  Jul 20, 2014 
PDF Page 262
example above figure 9-1

extraneous "n" above example.

Brian Tkatch  May 20, 2015 
PDF Page 265
footnote 1

"interrupt() has not worked consistently in all Java implementations historically."

At the very least, there should be a comma before "historically." Though, the word itself is redundant.

Also, the word "all" is confusing, instead, "every."

Even better, say what you mean:

Java implementations have not implemented interrupt() consistently, as discussed later in the chapter.

Brian Tkatch  May 20, 2015 
PDF Page 276
2nd paragraph, 3rd sentence

"waiter wakes up and rejoins related in vying for the MyThing lock."

In this example, we "assume that a thread named waiter gets through the gate first," waiter never waited. If so, it's just joining, not rejoining.

Brian Tkatch  May 21, 2015 
Printed Page 282
footnote 3

Footnote 3 references the web page https://rtsj.dev.java.net/, which appears gone/defunct.

Scott Wright  Jan 25, 2016 
Printed Page 285
Code snippet in the middle of page 285

Dear authors,

The code on page 285 creates two threads (foo and bar), but only bar gets started. Shouldn't foo.start() be invoked before the bar thread gets created?

Current code :

class Thready {
public static void main( String args [] ) {
Thread foo = new ShowThread("Foo");
foo.setPriority( Thread.MIN_PRIORITY );

Thread bar = new ShowThread("bar");
bar.setPriority( Thread.MAX_PRIORITY);
bar.start();
}
}

Suggested code :

class Thready {
public static void main( String args [] ) {
Thread foo = new ShowThread("Foo");
foo.setPriority( Thread.MIN_PRIORITY );
foo.start(); // Suggested new line.

Thread bar = new ShowThread("bar");
bar.setPriority( Thread.MAX_PRIORITY);
bar.start();
}
}

Many thanks,

David

David Robillard  Apr 28, 2015 
Printed Page 286
Code at the bottom of the page

The code at the bottom of page 286 is taking three lines. As in :

TheadGroup

myTaskGroup = new ThreadGroup("My Task Group");

Could we not write this in a single line instead? As in :

TheadGroup myTaskGroup = new ThreadGroup("My Task Group");

Thanks,

David

David Robillard  Apr 28, 2015 
Printed Page 296
last paragraph

The final paragraph on the page mentions a class ThreadPoolExecutorSevice. The API documentation does not include this class. Was the class ThreadPoolExecutor (as in the section title) intended?

Scott Wright  Jan 27, 2016 
Printed Page 303
3rd paragraph

The mentioned ThreadgetName() method is missing the period between the class name and the method name: it should be "Thread.getName()".

Scott Wright  Jan 26, 2016 
Printed Page 311
3rd paragraph

The list of atomic classes appears to have inadvertently included the ".java" file name extension on each item.

Scott Wright  Jan 27, 2016 
Printed Page 334
paragraph immediately preceding "String Conversions" heading

The reference to the constant width formatted "argument index" (of the preceding format string) is missing the underscore: it should be "argument_index".

Scott Wright  Jan 28, 2016 
Printed Page 336
Table 10-3

The 'c' conversion character also has a 'C' version.

Scott Wright  Jan 29, 2016 
PDF Page 347
Under the heading "Grouping"

The regular expression is incorrect.

The text reads:

To handle this properly, we can use an expression like this one:

\w+@\w+(\.\w)+ // Match an email address

This expression matches a word, followed by an @ symbol, followed by another word and then one or more literal dot-separated words?e.g., pat@pat.net, friend@foo.bar.com, or mate@foo.bar.co.uk.


The correct regular expression is:

\w+@\w+(\.\w+)+ // Match an email address

Michael Davoli  Aug 14, 2014 
PDF Page 348
United States

The second pattern matching example is incorrect.

The text reads:

For example, a slightly naive approach to parsing dates might be
the following:

\w+, \w+ \d+ \d+|\d\d/\d\d/\d\d // pattern 1 or pattern 2

In this expression, the left matches patterns such as Fri, Oct 12, 2001, and the right matches 10/12/2001.


It should read:

"...and the right matches 10/12/01."

Michael Davoli  Aug 14, 2014 
PDF Page 349
Top of page, bottom of previous page

From the text:

The following regex might be used to match email addresses with one of three domains (net, edu, and gov):

\w+@[\w\.]*\.(net|edu|gov) // email address ending in .net, .edu, or .gov

However, that matches the following possibilities:

a@.net
a@b..edu
a@b.c..gov


Perhaps better would be:

\w+@[\w+\.]*(net|edu|gov)

which will match, for example:

a@net
a@b.edu
a@bc.gov
a@b.c.net

Michael Davoli  Aug 14, 2014 
PDF Page 350
Middle of page

The text reads:

The content of an HTML tag cannot actually include anything; for example, it cannot include a closing bracket (>). So we could rewrite our expression as:
</?\w*> // match <, optional /, any number of word characters, then >

But an HTML tag must include something. (i.e. <> is not a tag). Maybe a better example would be:

</?\w+> // match <, optional /, one or more word characters, then >


Of course, this, in turn, would change the next example:

We can invert our logic from the previous example and specify that anything except a closing bracket is allowed inside the brackets:

</?[^>]*>

to

</?[^>]+>

Michael Davoli  Aug 15, 2014 
PDF Page 351
Middle of page

Appears to be a typo:

(?=\w\W)X // Find X at the end of a word

Here the regex engine requires the \W\w pattern to match but not consume the characters, leaving them for the next part of the pattern.


I think it should read:

"Here the regex engine requires the \w\W pattern..."

Michael Davoli  Aug 18, 2014 
PDF, Mobi Page 354
1st paragraph and first example

The example loop for Matcher.group on p.354 is probably not what authors intended. The loop end condition
i < matcher.groupCount();
means that the last capture group won't be printed.
i <= matcher.groupCount();
makes more sense here.

Bruce Wisentaner  Jul 13, 2013 
PDF Page 355
Under the heading "Replacing Text"

There is a typo in the pattern:

String text = "Richard Nixon's social security number is: 567-68-0515.";
Matcher matcher =
Pattern.compile("\\d\\d\\d-\\d\\d\-\\d\\d\\d\\d").matcher( text );
String output = matcher.replaceAll("XXX-XX-XXXX");

You accidentally escaped the second dash.

It should be:

"\\d\\d\\d-\\d\\d-\\d\\d\\d\\d"

Michael Davoli  Aug 18, 2014 
Printed Page 355
After heading "Using captured text in a replacement."

An extra period crept in following the heading, preceding the start of the next sentence.

Scott Wright  Feb 01, 2016 
PDF Page 356
Bottom of page

There is a typo in this statement:

XML-style comments start with <!? and can contain anything up to a closing ?>.

It looks like your text editor substituted the two adjacent dashes for an "em dash", \u2014.

It should be: <!-- and -->

Michael Davoli  Aug 18, 2014 
PDF Page 357
Bottom of page

It looks like your text editor substituted the two adjacent dashes for an "em dash", \u2014.

It should be: <!-- and -->

Next, there is the literal <!? followed by any amount of whitespace (\s) and the TEMPLATE: identifier. After the colon, we have a capture group (\w+), which reads our name identifier and saves it for us to retrieve later. We allow anything (.*) up to the ?>,

Michael Davoli  Aug 18, 2014 
Printed Page 366
code sample above last paragraph

The first line of the sample code was split across two lines.

Scott Wright  Feb 03, 2016 
Printed Page 367
Figure 11-1 caption

The figure caption reads "...localized data and time" but the word "data" was probably meant to be "date".

Scott Wright  Feb 03, 2016 
PDF Page 369
Top of page, third example

The comment is wrong:

// Wednesday, April 12, 2006 9:18:27 o'clock AM EDT
DateFormat dtf =
DateFormat.getDateTimeInstance( DateFormat.FULL, DateFormat.FULL );

The output does not include the "o'clock" string literal.

When I run the example, I get:

Monday, August 18, 2014 10:40:17 PM EDT

Michael Davoli  Aug 18, 2014 
PDF Page 369
Bottom of page

The string literal is wrong:

d = df.parse("Wednesday, April 12, 2006 2:22:22 o'clock PM EDT");

When I run it, I get:
java.text.ParseException: Unparseable date: "Wednesday, April 12, 2006 2:22:22 o'clock PM EDT"

remove the "o'clock" string literal and the string parses.

Michael Davoli  Aug 18, 2014 
PDF Page 377
Bottom of page

In the code example, there is a typo in the variable name:

Enumeration myEnumeartion = ...;
List list = Collections.list( myEnumeration );


Looks like it should be:

Enumeration myEnumeration = ...;

Michael Davoli  Aug 19, 2014 
Printed Page 379
fisrt line on page

The signature for set() should be "public E set(..." (type E should replace the Object type).

Scott Wright  Feb 03, 2016 
Printed Page 385
Table 11-7

For the Set interface, the implementation CopyOnWriteArraySet appears twice in the list of implementations.

Scott Wright  Feb 04, 2016 
PDF Page 394
Under the heading "Loading and Storing"

In the code example:

Continuing with the previous example, output the property information using the System.out stream as follows:

props.save( System.out, "Application Parameters" );

According to the javadocs, the save() method is deprecated...

http://docs.oracle.com/javase/7/docs/api/java/util/Properties.html#save(java.io.OutputStream,%20java.lang.String)

The preferred way to save a properties list is via the store() method.

Michael Davoli  Aug 19, 2014 
Printed Page 400
last paragraph

The static field Logger.global is deprecated. The API documentation recommends calling Logger.getGlobal() [or Logger.getLogger(Logger.GLOBAL_LOGGER_NAME) or Logger.getLogger("global") if Logger.getGlobal() is unavailable {pre-1.7}].

Scott Wright  Feb 06, 2016 
PDF Page 409
4th paragraph, 5th sentence

Sentence begins:

'One difference betwen the two'

This should be corrected to:

'One difference between the two'

Paul Waring  Dec 28, 2015 
PDF Page 415
3rd paragraph

in the code example:

try {
InputStream in = System.in;
InputStreamReader charsIn = new InputStreamReader( in );
BufferedReader bufferedCharsIn = new BufferedReader( inReader );
String line = bufferedCharsIn.readLine();
int i = NumberFormat.getInstance().parse( line ).intValue();
} catch ( IOException e ) {
} catch ( ParseException pe ) { }

An undefined parameter is passed to BufferedReader() in the line:
BufferedReader bufferedCharsIn = new BufferedReader( inReader );
it should be:
BufferedReader bufferedCharsIn = new BufferedReader( charsIn );

the BufferedReader charsIn variable was defined but never used.
Instead, the undefined inReader is used.

Anonymous  Dec 29, 2013 
Printed Page 418
Section entitled "Buffered streams"

Is there a reason/story/explanation why BufferedOutputStream and BufferedInputStream derive from their respective Filter*Stream classes whereas BufferedReader and BufferedWriter *do not* derive from FilterWriter and FilterReader? This asymmetry disorients me.

Scott Wright  Feb 10, 2016 
Printed Page 425
First paragraph after heading "File I/O"

The end of the second line reads "... the core java.io File I/O facility..." with "File" curiously capitalized. was "... the core java.io.File I/O facility..." (a fully-specified class name) intended?

Scott Wright  Feb 09, 2016 
PDF Page 427
Bottom of page

The path is incorrect, you have a double backslash after c:

An absolute path is a system-dependent notion that means that the path doesn’t depend on the application’s working directory or any concept of a working root or drive (e.g., in Windows, it is a full path including the drive letter: c:\\Users\pat\foo.txt).

It should be:

c:\Users\pat\foo.txt

Michael Davoli  Aug 28, 2014 
Printed Page 430
Table 12-1

The listRoots() method is static, although is not highlighted as such in the table (like createTempFile).

Scott Wright  Feb 11, 2016 
Printed Page 430
Table 12-1

The final method in the table, toURL(), is deprecated. The latest API docs recommend using toURI() instead.

Scott Wright  Feb 11, 2016 
PDF Page 431
Bottom of page, code example

In the code example, the variable "file" is defined twice:

class ListIt {
public static void main(String args[]) throws Exception {
File file = new File(args[0]); <-------HERE
if (!file.exists() || !file.canRead()) {
System.out.println("Can't read " + file);
return;
}
if (file.isDirectory()) {
String[] files = file.list();
for (String file : files) <---------HERE
System.out.println(file);
....

This code will not compile.

Change the foreach loop to something like this:

for (String f: files)
System.out.println(f);

Michael Davoli  Aug 29, 2014 
Printed Page 434
3rd paragraph

In the second sentence, the second occurrence of the string "URL" looks like it should be in the fixed width font as the class providing the openStream() method.

In the last sentence of the same paragraph, reference is made to a getResourceAsStream() method, but no target class is given -- I found this method available from the classes Class and ClassLoader (was one or both of these intended?).

Scott Wright  Feb 11, 2016 
Printed Page 436
first paragraph

In the first sentence: "...new, NIO, File API introduced with Java 7." -- NIO was introduced with Java 1.4.

Scott Wright  Feb 11, 2016 
PDF Page 437
Bottom of page

Typo, missing space between words:

"In this snippet, we’ve shown the Pathresolve() and resolveSibling() methods..."

should be:

"...Path resolve()..."

Michael Davoli  Aug 31, 2014 
PDF Page 438
Table 12.2, description of copy() method

Typo, "files" should be possessive, not plural:

"Copying a symbolic link copies the linked files data (producing a regular file copy)."

This should read:

"...copies the linked file's data..."

Michael Davoli  Sep 02, 2014 
Printed Page 438
paragraph following "Path to classic file and back" heading

In the last sentence of the paragraph, the word "File" should probably be in the "constant width" font as this seems to be a reference to the java.io.File class.

Scott Wright  Feb 10, 2016 
PDF Page 440
Table 12.2, description of newByteChannel() method

Typo. Missing ".":

"Consider using FileChannelopen() as an alternative."

Should be:

"... FileChannel.open() ..."

Michael Davoli  Sep 02, 2014 
PDF Page 440
Table 12.2, description of newOutputStream() method

Typo:

"Optionally, specify file truncation for the output stream; the default is to create a truncate on write."

Should be:

"...to create and truncate..."

Michael Davoli  Sep 02, 2014 
Printed Page 440
entry for newByteChannel()

In the description: "...using FileChannelopen() as an..." -- looks like a period is missing from the method reference [i.e. "FileChannel.open()"].

Scott Wright  Feb 11, 2016 
PDF Page 441
Top of page, second sentence.

Typo, misspelled "directories":

"We can also create paths as files and dirctories and iterate through file hierarchies."

Should be:

"...directories..."


C'mon guys, a misspelled word in the main text? Surely someone used a spellchecker before publishing?

Michael Davoli  Sep 02, 2014 
PDF Page 441
Third paragraph

Typo, "read all" should be "readAll" or "readAll()":

"For quickly reading and writing the contents of files without streaming, we can use the read all and write methods that move byte arrays or strings in and out of files in a single operation."

Should be at least:

"...we can use the readAll and write methods..."

But really, if you want to follow the convention, should be:

"...we can use the readAll() and write() methods..."


An example is shown in the previous paragraph:

"As a reminder, the resolve() and resolveSibling() methods of Path..."

Michael Davoli  Sep 02, 2014 
PDF Page 442
Bottom of page

Typo, missing ".":

"The FileswalkFileTree() method takes a starting path and performs a depth-first traversal of the file hierarchy, giving the provided FileVisitor a chance to “visit” each path element in the tree."

Should be:

"The Files.walkFileTree() method..."

Michael Davoli  Sep 02, 2014 
PDF Page 443
First paragraph

Typo, missing period "."

then indicate whether or not the traversal should continue by returning one of a set of enumerated result types: FileVisitResultCONTINUE or TERMINATE.

Should be:

"...a set of enumerated result types: FileVisitResult.CONTINUE..."

Michael Davoli  Sep 03, 2014 
Printed Page 450
code sample at top of page

The code segment won't quite compile as given -- the "entry" variable is declared twice.

Scott Wright  Feb 11, 2016 
PDF Page 452
Bottom of page

Missing period:

"In this snippet, we constructed a URI for our ZIP archive using the URIcreate() method..."

Should be:

"...the URI.create() method..."

Michael Davoli  Sep 04, 2014 
Printed Page 452
first paragraph following heading "Zip Archive as a File System"

In the first sentence, "introduce" should be in past tense: "introduced".

Scott Wright  Feb 12, 2016 
PDF Page 454
1st paragraph, 7th sentence

7th sentence begins:

'We’ll discuss this in detail in Chapter 13when we discuss networking'

There should be a space between 'Chapter 13' and 'when'.

Paul Waring  Dec 29, 2015 
PDF Page 461
Under the heading "FileChannel"

Missing period:

"A FileChannel can be created for a Path using the static FileChannelopen() method."

Should be:

"... FileChannel.open() method."

Michael Davoli  Sep 04, 2014 
PDF Page 465
Under the heading "Direct Transfer"

Missing period:

"The following example should be the fastest way to implement a file copy in Java short of using the built-in Filescopy() method:"

Should be:

"...Files.copy() method:"

Michael Davoli  Sep 04, 2014 
PDF Page 466
First paragraph, fourth sentence

Strange word "boh" in middle of sentence. Needs to be removed:

"In general, read operations may return fewer bytes than requested and write operations may boh write fewer bytes and also may buffer data in memory unless we use the SYNC or DSYNC open options."

Looks like you meant to write "both" but then changed the sentence structure. Maybe just remove the "boh"?

Again, spellchecker guys...

Michael Davoli  Sep 04, 2014 
PDF Page 483
Top of Page, Under SO_TIMEOUT

Both the description and the code example use the wrong exception, it should be a "SocketTimeoutException".


"If the timer expires before the operation would complete, an InterruptedIOException is thrown."

...
try{
Socket client = serverSocket.accept();
handleClient( client );
} catch ( InterruptedIOException e ) {
// ignore the exception
}
...


According to the javadocs: http://docs.oracle.com/javase/7/docs/api/java/net/ServerSocket.html#accept()

...
Throws:
...
SocketTimeoutException - if a timeout was previously set with setSoTimeout and the timeout has been reached.
...

Michael Davoli  Sep 08, 2014 
Printed Page 501
2nd to last paragraph

The second sentence is missing a space after the terminating period before the next sentence: "...server.main()..." -> "..server. main()..."

Scott Wright  Feb 18, 2016 
Printed Page 503
first line (sample code)

A space is missing between the class name and the argument.

Scott Wright  Feb 18, 2016 
Printed Page 505
command-line example at top of page

The final word, "MyServer" probably is not meant to be in italic font.

Scott Wright  Feb 18, 2016 
Printed Page 512
paragraph preceding section heading "LargerHttpd"

In the first sentence, Chapter 1 is referenced for the Iterator class -- whas Chapter 11 intended?

Scott Wright  Feb 19, 2016 
PDF Page 567
Toward the top of the page

Misnamed the @ServletSecurity annotation, you called it SecurityServlet:

"We can do the equivalent configuration for a given servlet using the SecurityServlet annotation with an HttpConstraint annotation element as follows:"

Michael Davoli  Sep 13, 2014 
PDF Page 573
Top of page.

The paragraph states:
"In our init() method, we use the FilterConfig object to look for an initialization parameter named “limit” and turn it into an integer. Users can set this value in the section of the web.xml file where the instance of our filter is declared or in the annotation as shown."

The annotation is not shown anywhere.

Michael Davoli  Sep 14, 2014 
Printed Page 599
first line

The description of getParent() is missing..

Scott Wright  Feb 22, 2016 
Printed Page 602
last paragraph

The text mis-states that JFrame is a subclass of JWindow -- JFrame and JWindow are both subclasses of (AWT) Window, but JFrame is not a subclass of JWindow.

Scott Wright  Mar 03, 2016 
Printed Page 608
first paragraph

"AWTEvent is a subclass of java.awt.EventObject;" should be "... is a subclass of java.util.EventObject;" (i.e. replace "awt" with "util")

Scott Wright  Feb 23, 2016 
Printed Page 615
second to last paragraph

The constant width text in the third sentence "FocusEventgetOppositeComponent()" has lost the space between the class and method names -- it should be "FocusEvent<space>getOppositeComponent()"

Scott Wright  Feb 24, 2016 
Printed Page 635
code sample

The Java 1.7 compiler whines about the JComboBox and JList declarations being raw types and also about the JList.getSelectedValues() method in the ActionListener being deprecated.
(The code does all work as expected/intended, regardless.)

How about these revisions:

1) Change JComboBox comboBox = new JComboBox(items);
to JComboBox<String> comboBox = new JComboBox<>(items);

2) Change final JList list = new JList(comboBox.getModel());
to final JList<String> list = new JList<>(comboBox.getModel());

3) Change Object[] selection = list.getSelectedValues();
to List<String> selection = list.getSelectedValuesList();

4) Change for (Object s : selection)
to for (String s : selection)

Scott Wright  Mar 04, 2016 
Printed Page 635
code sample

When the GUI starts up, no item is selected from the JList, so pressing "Per favore" produces a (slightly) disconcerting "null response".

How about adding:
list.setSelectedIndex(0);
after the line
final JList ...
to set the initially selected item?

Scott Wright  Mar 04, 2016 
Printed Page 639
first paragraph

The first sentence on the page references a "SpinnerCalendarModel" -- was "SpinnerDateModel" intended?

Scott Wright  Mar 05, 2016 
Printed Page 658
code sample

The JScrollBar only displays values from 0 to 207, despite its "max" being set to 255 -- apparently effective maximum is actually max - extent. So in this example, to have the JScrollBar and JSlider display equivalent ranges, the JScrollBar ought to be initialized as:

int width = 48;
final JScrollBar scrollBar = new JScrollBar(JScrollBar.HORIZONTAL, 0, width, 0, width + 255);

Scott Wright  Mar 07, 2016 
Printed Page 894
line 12 from top to page 895, line 13 from top

The source code published is not the file referred to by the text. The text refers to an XSL stylesheet. However, the printed source code is an XML schema.

Martin Fluch  Aug 12, 2014