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.
Version |
Location |
Description |
Submitted By |
Date submitted |
Date corrected |
Printed |
Page xxi
4th paragraph |
At the bottom of the page it says "You can download the source code from
http://metalab.unc.edu/javafaq/books/jnp2e and
http://www.reilly.com/catalog/9781565928701/."
http://www.reilly.com/catalog/9781565928701/.
SHOULD SAY
http://www.oreilly.com/catalog/9781565928701/.
|
Anonymous |
|
|
Printed |
Page xvii
In Figure P-1, the box between Chapter 15 and Chapter 17 now |
reads: Chapter 16, Protocol Handlers
|
Anonymous |
|
Dec 01, 2000 |
Printed |
Page xxi
At the very bottom of the page the URL for the O'Reilly web site is |
has been changed to:
http://www.oreilly.com/catalog/9781565928701/
The "o" was missing in oreilly.
|
Anonymous |
|
Dec 01, 2000 |
Printed |
Page 7
first paragraph |
"content handers" should read "content handlers"
|
Anonymous |
|
|
Printed |
Page 20
In the contents box at the top of page 20 |
"The Layers of a Netowrk"
now reads:
"The Layers of a Network."
|
Anonymous |
|
Dec 01, 2000 |
Printed |
Page 42
Table 2-2 (Last Selection on that Page; RFC 792) |
Page 42 in "Table 2-2. Selected Internet RFCs" on the last RFC of that page:
RFC 792 Internet Control Message Protocol (ICMF)
It should be "ICMP" not ICMF :-)
p. 60: In the first line of the first text paragraph, "HTT 1.0"
should be "HTTP 1.0"
p. 88: In the first sentence of the second paragraph, "servers as a
buffer" should be "serves as a buffer".
|
Anonymous |
|
|
Printed |
Page 51
The last sentence on the page now reads, "Although there's some |
hierarchy to the newsgroup names indicated by the . between netscape and
netscape.devs-java, it's not visible as part of the URI." That is,
the period after "between netscape" has been removed.
|
Anonymous |
|
Dec 01, 2000 |
Printed |
Page 60
In the first line of the first paragraph, |
"(HTT 1.0)"
now reads
"(HTTP 1.0)".
|
Anonymous |
|
Dec 01, 2000 |
Printed |
Page 69
The last sentence in the first paragraph |
now reads, "Furthermore, the client side interface to servlets is almost exactly like the client
side interface to CGI programs, so what we say about talking to CGI
programs will apply equally to talking to servlets."
|
Anonymous |
|
Dec 01, 2000 |
Printed |
Page 69
First full sentence |
The sentence used to read:
Furthermore, the client-side interface to servlets is almost exactly like
the client-side interface to servlets, so what I say about talking to CGI
programs will apply equally to talking to servlets.
The sentence now reads:
Furthermore, the client-side interface to CGI is almost exactly like the
client-side interface to servlets, so what I say about talking to CGI
programs will apply equally to talking to servlets.
The second line:
"connection is open"
Now reads:
"URLConnection is connected"
|
Anonymous |
|
Aug 01, 2001 |
Printed |
Page 99
last code |
The CipherOutputStream() signature is wrong ,
it reads :
public CipherOutputStream(InputStream in, Cipher c);
should be
public CipherOutputStream(OutputStream out,Cipher c);
|
Anonymous |
|
|
Printed |
Page 99
The first complete sentence on this page |
now reads, "The sender can calculate the digest as it sends data, while the receiver calculates
the digest as it receives data."
|
Anonymous |
|
Dec 01, 2000 |
Printed |
Page 99
In line 7 |
In line 7, "Alternativly" now reads "Alternatively".
|
Anonymous |
|
Dec 01, 2000 |
Printed |
Page 101
The first sentence of the Readers and Writers section |
The first sentence of the Readers and Writers section now reads:
"Most programmers have a bad habit of writing code as if all text were
ASCII, or at the least in the native encoding of the platform."
|
Anonymous |
|
Dec 01, 2000 |
Printed |
Page 121
Last paragraph |
A period was missing between the third and fourth sentences of the last paragraph. It now reads:
Most of the time, however, you'll want to pass the information to other
parts of the program. You can store the result of the calculation in a
field and provide a getter method to return the value of that field.
|
Anonymous |
|
Dec 01, 2000 |
Printed |
Page 133
In the first paragraph: |
"Notice the addition of a <code>start()</code> method"
now reads:
"Notice the addition of the <code>calculateDigest()</code>
method to start the thread."
|
Anonymous |
|
Mar 01, 2001 |
Printed |
Page 134
Code segment |
one definate error is that the method declaration is out of order for
"public void synchronized sendDigest (byte[] digest) {"
it should read:
"public synchronized void sendDigest (byte[] digest) {"
AUTHOR: This is correct.
p. 161: If there are directories, already gzipped files, or other
incompressible files, the thread is likely not to exit when it
should. To fix this, move the call to incrementFilesCompressed() from
the fifth line on p. 162 to right after the line that removes a file
from the pool on p. 161. Then the run() method should read as follows:
public void run() {
while (filesCompressed != GZipAllFiles.getNumberOfFilesToBeCompressed()) {
File input = null;
synchronized (pool) {
while (pool.isEmpty()) {
if (filesCompressed ==
GZipAllFiles.getNumberOfFilesToBeCompressed()) {
System.out.println("Thread ending");
return;
}
try {
pool.wait();
}
catch (InterruptedException ex) {
}
}
input = (File) pool.remove(pool.size()-1);
incrementFilesCompressed();
}
// don't compress an already compressed file
if (!input.getName().endsWith(".gz")) {
try {
InputStream in = new FileInputStream(input);
in = new BufferedInputStream(in);
File output = new File(input.getParent(), input.getName() + ".gz");
if (!output.exists()) { // Don't overwrite an existing file
OutputStream out = new FileOutputStream(output);
out = new GZIPOutputStream(out);
out = new BufferedOutputStream(out);
int b;
while ((b = in.read()) != -1) out.write(b);
out.flush();
out.close();
in.close();
}
}
catch (IOException e) {
System.err.println(e);
}
} // end if
} // end while
} // end run
p. 163: The example is not always adding files at the begining of the
queue like it should. In the synchronized block change
pool.add(files[j]);
to
pool.add(0, files[j]);
|
Anonymous |
|
|
Printed |
Page 151
|
All three versions of the join() method including the noargs variant can throw an InterruptedException. Thus the first method signature
on the page now reads:
public final void join() throws InterruptedException
|
Anonymous |
|
Dec 01, 2000 |
Printed |
Page 159
Thread Pools |
In line 6 of the first paragraph of the Thread Pools section, "for a even a low-" now reads "for even a low".
|
Anonymous |
|
Dec 01, 2000 |
Printed |
Page 163
Towards the bottom of the main method. |
This code may enter an infinite wait state.
When the main method finishes adding all the files to the pool it calls
for (int i = 0; i < threads.length; i++)
threads[i].interrupt();
}
If a thread picks up the last file and is still processing it when this
loop is called, all the threads will wake up, notice that the pool is
empty, but the condition (filesCompressed ==
GZipAllFiles.getNumberOfFilesToBeCompressed()) will still be false until
the running thread finishes the last file. This will place all other
threads in a wait state never to be woken up.
This happened to me which is how I was alerted to the problem.
A way to fix this is to ammend the loop to read:
while(threads[0].getFilesCompressed() != filesToBeCompressed);
for (int i = 0; i < threads.length; i++ ) {
threads[i].interrupt();
}
Of course this will necessitate adding a
public int getFilesCompressed() method to the GZipThread class.
AUTHOR: This is correct.
p. 170: In the third text paragraph, "explicitly via getAddress"
should be "explicitly via getHostName".
p. 189: In the processLogFile() method in Example 6-11, PooledWeblog,
the body of the try block should read as follows:
String entry = in.readLine();
while (entry != null) {
if (entries.size() > numberOfThreads) {
try {
Thread.sleep((long) (1000.0/numberOfThreads));
}
catch (InterruptedException e) {}
continue;
}
synchronized (entries) {
entries.add(0, entry);
entries.notifyAll();
}
entry = in.readLine();
Thread.yield();
} // end while
|
Anonymous |
|
|
Printed |
Page 177
The second sentence of the third paragraph |
The second sentence of the third paragraph now reads, "The conditional operator ? tests whether signedByte is
negative." That is, unsignedByte has been changed to signedByte.
|
Anonymous |
|
Mar 01, 2001 |
Printed |
Page 189
Example 6-11 |
In the processLogFile() method in Example 6-11, PooledWeblog, bin.readLine() now reads in.readLine().
|
Anonymous |
|
Dec 01, 2000 |
Printed |
Page 195
3rd Para |
In the third paragraph, "foloowing" now reads "following".
|
Anonymous |
|
Mar 01, 2001 |
Printed |
Page 220
In Example 7-8, the line |
System.out.println(URLEncoder.encode("Thisstring"has"quote"marks"));
was missing a quote mark after the first slash. It now reads:
System.out.println(URLEncoder.encode("This"string"has"quote"marks"));
|
Anonymous |
|
Mar 01, 2001 |
Printed |
Page 252
First paragraph |
Text refers to ParserGetter class from example 8-5
This class is in fact from example 8-6
p. 265: Two changes should be made to Example 8-10 on this page.
First you need to test if the local directory exists before trying to
make it. That is, change
if (localDirectory.mkdirs()) {
to
if (localDirectory.exists() || localDirectory.mkdirs()) {
Next, to make PageSaver work with documents that use a meta tag such
as <meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">, you need to change
parser.parse(r, callback, false);
to
parser.parse(r, callback, true);
|
Anonymous |
|
|
Printed |
Page 275
1st paragraph |
Example 9-5 is a complete applet that downloads a sound file called
gong.au, which is located in the same directory as the applet, ...
should be:
Example 9-5 is a complete applet that downloads a sound file called
beep.au, which is located in the sounds directory just below the document
base, ...
|
Anonymous |
|
|
Printed |
Page 307
The first code fragment now reads |
try {
InetAddress OReilly = InetAddress.getByName("www.oreilly.com");
Socket OReillySocket = new Socket(OReilly, 80);
// send and receive data...
}
catch (UnknownHostException e) {
System.err.println(e);
}
catch (IOException e) {
System.err.println(e);
}
|
Anonymous |
|
Dec 01, 2000 |
Printed |
Page 308
The code fragment at the bottom of the page now reads |
try {
InetAddress fddi = InetAddress.getByName("fddisunsite.oit.unc.edu");
Socket OReillySocket = new Socket("www.oreilly.com", 80, fddi, 0);
// work with the sockets...
}
catch (UnknownHostException e) {
System.err.println(e);
}
catch (IOException e) {
System.err.println(e);
}
|
Anonymous |
|
Dec 01, 2000 |
Printed |
Page 309
The code fragment toward the bottom of the page now reads |
try {
InetAddress metalab = InetAddress.getByName("metalab.unc.edu");
InetAddress oreilly = InetAddress.getByName("www.oreilly.com");
Socket oreillySocket = new Socket(oreilly, 80, metalab, 0);
}
catch (UnknownHostException e) {
System.err.println(e);
}
catch (IOException e) {
System.err.println(e);
}
|
Anonymous |
|
Dec 01, 2000 |
Printed |
Page 312
first code fragment |
Uses deprecated Socket constructor
AUTHOR: The fix is to change
Socket theSocket = new Socket("java.sun.com", 80, true);
to
Socket theSocket = new Socket("java.sun.com", 80, true);
That is, delete the third argument.
p. 364: In the first line, jServerSocket should be ServerSocket
(delete the initial j).
|
Anonymous |
|
|
Printed |
Page 323-324
In Example 10-7 |
the finally block was attached to the wrong try block. It is now inside the for loop. Here's
the corrected program:
import java.net.*;
import java.io.*;
public class PortScanner {
public static void main(String[] args) {
String host = "localhost";
if (args.length > 0) {
host = args[0];
}
try {
InetAddress theAddress = InetAddress.getByName(host);
for (int i = 1; i < 65536; i++) {
Socket connection = null;
try {
connection = new Socket(host, i);
System.out.println("There is a server on port "
+ i + " of " + host);
}
catch (IOException e) {
// must not be a server on this port
}
finally {
try {
if (connection != null) connection.close();
}
catch (IOException e) {}
}
} // end for
} // end try
catch (UnknownHostException e) {
System.err.println(e);
}
} // end main
} // end PortScanner
|
Anonymous |
|
Mar 01, 2001 |
Printed |
Page 327
|
InterruptedException
has been changed to:
InterruptedIOException
|
Anonymous |
|
Mar 01, 2001 |
Printed |
Page 354
In the code fragment in the middle of the page, |
InetAddress.getHostByName now reads InetAddress.getByName
|
Anonymous |
|
Mar 01, 2001 |
Printed |
Page 372
In the main() method, on the last line of the page, |
"args.length >= 2" should be "args.length > 2".
|
Anonymous |
|
|
Printed |
Page 374
Last sentence of the 1st paragraph |
"However, that would raise some additional issues of thread safety that
Example 11-5 doesn't have to address because it's immutable."
should be:
"However, that would raise some additional issues of thread safety that
Example 11-6 doesn't have to address because it's
p. 384: In order to better handle unexpected network failures (broken
sockets), near the bottom of the page change
if (c == '
' || c == '
') break;
to
if (c == '
' || c == '
' || c == -1) break;
|
Anonymous |
|
|
Printed |
Page 385
About three quarters of the way down the page, at the end of the second code block: |
} // end try
now reads:
} // end if
|
Anonymous |
|
Mar 01, 2001 |
Printed |
Page 391
Note, last sentence |
"...Scott Oak's 'Java Security'..."
SHOULD BE:
"...Scott Oaks' 'Java Security'..."
p. 392: In the third paragraph, jre/lib/ext/security/java.security
should be jre/lib/security/java.security. That is, delete ext/ from
the path.
p. 392: In the second to last paragraph, java.policy should be java.security.
|
Anonymous |
|
|
Printed |
Page 414
Figure 13-1; Eighth byte |
"destination port"
Should read:
"checksum"
|
Anonymous |
|
|
Printed |
Page 427-429
Examples 13-3 and 13-4 |
Example 13-3 and 13-4 share a mutual bug. Both assume they're using the local host's default encoding. However, is these two
programs run of different hosts (for instance, one is a Japanese system
and one is a French system) that may well not be the same for each. The
encoding needs to be explicitly specified in both programs. On p. 427 in
Example 13-3 change
byte[] data = theLine.getBytes()
to
byte[] data = theLine.getBytes("UTF-8")
On p. 429 in Example 13-4 change
String s = new String(packet.getData(), 0, packet.getLength())
to
String s = new String(packet.getData(), 0, packet.getLength(), "UTF-8")
This will allow the two hosts to exchange data regardless of differing encodings.
p. 433: In the fith code line, change new ServerSocket(2048) to new
DatagramSocket(2048). It should read:
DatagramSocket ds = new DatagramSocket(2048)
p. 448: In the second paragraph, EchoInputThread should be SenderThread.
|
Anonymous |
|
|
Printed |
Page 465
3rd code snippet |
in the 3rd code snippet it says:
ia = new InetAddress("metalab.unc.edu");
shouldn't it say
ia = InetAddress.getByName("metalab.unc.edu");
Their is no public constructor for InetAddress(jdk 1.3)
|
Anonymous |
|
|
Printed |
Page 476
1st paragraph, 1st line |
Example 15-5 is not right exmaple in this paragraph.
instead of Example 15-5, Example 7-5 is right example that should be
written.
p. 485: In the second line of the first code fragment on the page,
last-modification should be last-modified. That is, change
long lastModified = uc.getHeaderFieldDate("last-modification", 0);
to
long lastModified = uc.getHeaderFieldDate("last-modified", 0);
|
Anonymous |
|
|
Printed |
Page 492
The first line of the second to last code fragment on the page |
"GET / HTTP 1.1"
Now reads:
"GET / HTTP/1.1"
|
Anonymous |
|
Aug 01, 2001 |
Printed |
Page 498
The first line of thesecond to last code fragment on the page |
"POST /cgi-bin/register.pl HTTP 1.0"
Now reads:
"POST /cgi-bin/register.pl HTTP/1.0"
|
Anonymous |
|
Aug 01, 2001 |
Printed |
Page 499
The first bold line on the page |
"POST /cgi-bin/post-query HTTP 1.0"
Now reads:
"POST /cgi-bin/post-query HTTP/1.0"
|
Anonymous |
|
Aug 01, 2001 |
Printed |
Page 502
in item 1, |
change "you'll use send data to the CGI program"
to "you'll send to the CGI program".
|
Anonymous |
|
|
Printed |
Page 506
1st paragraph |
java.io.Permission
should be:
java.security.Permission
|
Anonymous |
|
|
Printed |
Page 509
In the first row of the table on this page |
"! XPM2" should be "!XPM2", and should be placed in the ASCII column, not the hexadecimal column.
|
Anonymous |
|
|
Printed |
Page 510
The first line of the code fragment at the bottom of the page |
"HEAD / catalog/jfcnut/index.html HTTP 1.1"
Now reads:
"HEAD / catalog/jfcnut/index.html HTTP/1.1"
|
Anonymous |
|
Aug 01, 2001 |
Printed |
Page 512
The first line of the code fragment at the bottom of the page |
"OPTIONS /xml/ HTTP 1.1"
Now reads:
"OPTIONS /xml/ HTTP/1.1"
|
Anonymous |
|
Aug 01, 2001 |
Printed |
Page 513
The first line of the first code fragment in the DELETE section |
"DELETE /javafaq/1999march.html HTTP 1.1"
Now reads:
"DELETE /javafaq/1999march.html HTTP/1.1"
|
Anonymous |
|
Aug 01, 2001 |
Printed |
Page 514
The first line of the large code fragment in the middle of the page |
"PUT /hello.html HTTP 1.0"
Now reads:
"PUT /hello.html HTTP/1.0"
|
Anonymous |
|
Aug 01, 2001 |
Printed |
Page 515
The first code fragment |
"TRACE /xml/ HTTP 1.1"
Now reads:
"TRACE /xml/ HTTP/1.1"
|
Anonymous |
|
Aug 01, 2001 |
Printed |
Page 515
The following line |
"TRACE /xml/ HTTP 1.1"
Now reads:
"TRACE /xml/ HTTP/1.1"
|
Anonymous |
|
Aug 01, 2001 |
Printed |
Page 515
The third text paragraph |
"TRACE /xml/ HTTP 1.1"
Now reads:
"TRACE /xml/ HTTP/1.1"
|
Anonymous |
|
Aug 01, 2001 |
Printed |
Page 516
At the end of the first paragraph of the "Handling Server responses" section, |
delete ", and follows the response MIME header".
|
Anonymous |
|
|
Printed |
Page 516
The code fragment in the middle of the page |
"HTTP 1.1 200 OK"
Now reads:
"HTTP/1.1 200 OK"
|
Anonymous |
|
Aug 01, 2001 |
Printed |
Page 516
The last code fragment on the page |
"HTTP 1.1 404 Not Found"
Now reads:
"HTTP/1.1 404 Not Found"
|
Anonymous |
|
Aug 01, 2001 |
Printed |
Page 517
The second code fragment |
"HTTP 1.1 301 Moved Permanently"
Now reads:
"HTTP/1.1 301 Moved Permanently"
|
Anonymous |
|
Aug 01, 2001 |
Printed |
Page 520
In Table 15-3, in the 406 row |
"Allow field of the MIME request header"
should be
"Accept field of the MIME request header"
|
Anonymous |
|
|
Printed |
Page 522
Example 15-10 |
"HTTP 1.x"
Now reads:
"HTTP/1.x"
|
Anonymous |
|
Aug 01, 2001 |
Printed |
Page 523
The first code fragment change |
"HTTP 1.x"
Now reads:
"HTTP/1.x"
|
Anonymous |
|
Aug 01, 2001 |
Printed |
Page 534
In the last heading on the page, |
change "Protected" to "protected"
|
Anonymous |
|
|
Printed |
Page 536
In the last heading on the page, |
change "Protected" to "protected"
|
Anonymous |
|
|
Printed |
Page 536
In the last paragraph, |
change "has been stored in the URL's host field" to "has been stored in the URL's file field"
|
Anonymous |
|
|
Printed |
Page 537-540
In all the headings on these pages, |
change "Protected" to "protected"
|
Anonymous |
|
|
Printed |
Page 564
|
In point 5 change "URLConnectiongetContent() method" to "URLConnection.getContent() method".
Also, note that the word "method" should not be monospaced here
|
Anonymous |
|
|
Printed |
Page 603
3rd paragraph |
The source code for the FibonacciImpl.java (Chapter 18 , Example 18.2):
This class extends UnicastRemoteObject and also calls the exportObject(this) on this
class, which results in doing the same thing twice.(Which results in an exception
stating object already exported..)
This is a mistake only in the source code suppiled on the web site, in the text book
this class doesn't extend UnicastRemoteObject.
Here is the code snippet from web site:
public class FibonacciImpl extends UnicastRemoteObject implements Fibonacci {
public FibonacciImpl() throws RemoteException {
UnicastRemoteObject.exportObject(this);
// setLog(System.out);
}
Fix:
Only one of the two things shd be done:-
1) Extend the UnicastRemoteObject class
2) use exportObject() method
|
Anonymous |
|
|
Printed |
Page 606
12th line of the example 18-4 |
The error message of the first System.err.println should be "Usage: java
FibonacciClient ..." instead of "Usage: java Fibonacci client ...",
because class'
name is FibonacciClient.
|
Anonymous |
|
|
Printed |
Page 614
12th line of the example 18-8 |
The error message of the first System.err.println should be "Usage: java
FibonacciClient ..." instead of "Usage: java Fibonacci client ...", because the
class' name is FibonacciClient.
|
Anonymous |
|
|
Printed |
Page 622
In the 3rd paragraph, |
"perfomed" should be "performed"
p. 636: In the third paragraph, delete "like the one shown in Figure 19-1".
|
Anonymous |
|
|
Printed |
Page 648
In the last paragraph, |
"a simple HELLO command"
should be
"a simple HELO command"
|
Anonymous |
|
|
Printed |
Page 654
In the note, |
"java.netPasswordAuthentication"
should be
"java.net.PasswordAuthentication"
and
"javax.mailPasswordAuthentication"
should be
"javax.mail.PasswordAuthentication"
p. 693: In Example 19-12, AllPartsClient, I have a couple of small
improvements. Change the two lines:
if (fileName == null && (disposition.equals(Part.ATTACHMENT)
|| !contentType.equals("text/plain"))) {
to
if (fileName == null && (Part.ATTACHMENT.equalsIgnoreCase(disposition)
|| !contentType.equalsIgnoreCase("text/plain"))) {
This avoids a possible NullPointerException and handles case
insensitive MIME type and disposition matching.
p. 727: In the second column the reference to "SO TIMEOUT socket
optionn" should be "SO_TIMEOUT socket option"; that is, use an
underscore instead of a space..
|
Anonymous |
|
|
Printed |
Page 693
In Example 19-12 |
"if (fileName == null && (disposition.equals(Part.ATTACHMENT)
|| !contentType.equals("text/plain"))) {"
Now reads:
"if (fileName == null && (Part.ATTACHMENT.equals(disposition)
|| !contentType.equalsIgnoreCase("text/plain"))) {"x
|
Anonymous |
|
Aug 01, 2001 |