Corrections to Chapter 1 of Java I/O, Introducing I/O

p. 8: Delete the following paragraph and code fragment:

Even simple arithmetic with small, byte-valued constants as follows produces "Explicit cast needed to convert int to byte" errors:

byte b = 1 + 2;

This is not true in Java 1.1 and later.

p. 9: In the middle of the page, the arithmetic algorithm given for finding the last byte of the number is incorrect for negative numbers. That section should read like this:

This is the effect of taking the remainder modulo 256 of the int b and adding 256 if the value is negative; that is,

b = b % 256 >= 0 ? b % 256 : 256 + b % 256;

More simply, using bitwise operators,

b = b & 0x000000FF;

p. 10: In the line of code near the top of the page the greater than sign should be greater than or equals; that is,

 int unsignedByte = signedByte >= 0 ? signedByte : 256 + signedByte;
p. 10: In the fifth paragraph change "the absolute value of the number" to "The absolute value of a negative number"

p. 13: EBCDIC is more often an eight-bit character set than a seven-bit set (but only IBM knows for sure in all the different versions of EBCDIC that exist)

p. 15: In Java 1.1 and later, compilers can figure out if an operation performed on char literals (though not char variables) will overflow the bounds of a char. Thus change the the paragraph beginning, "A char used in arithmetic..." and the following code fragment and paragraph to:

A char used in arithmetic is promoted to int. This presents the same problems as it does for bytes. Admittedly, performing mathematical operations on chars is a much less common thing to want to do than performing them on bytes.

p. 21: In the second paragraph of the System.out section change "Hello World" to "Hello World!"

p. 23: In the first paragraph on the page, change

For example, if the user types "Hello World", the following bytes will be read from System.in in this order:
to

For example, if the user types "Hello World!" and hits the return or enter key, the following bytes will be read from System.in in this order:

[ Java I/O Corrections | Java I/O Home Page | Table of Contents | Examples | Order from Amazon ] ]

Copyright 1999 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified August 6, 1999