Last updated October 6, 2002.
Add the keyword assert to the table.
"Casting the reference literal null, which is not of any type, to a reference type results in a compile time warning."
and should be replaced by:
"The reference literal null can be cast to any reference type."
(a) Member variable i is accessible in all classes in other packages.
(b) Member variable j is accessible in all classes in other packages.
(c) Member variable k is accessible in all classes in other packages.
(d) Member variable k is accessible in subclasses only in other packages.
(e) Member variable l is accessible in all classes in other packages.
(f) Member variable l is accessible in subclasses only in other packages.
In the middle of the page, replace the line beginning with:
" setKWH from the superclass ... "
with:
" setWatts() from the superclass ... "
Change choice (e)
(e) The overriding method can have a different return value than the overridden method.
to (replace "value" with "type"):
(e) The overriding method can have a different return type than the overridden method.
With line (2) uncommented, the compiler distributed with J2SE 1.4 compiles the code without error. However, this is a recent change to the Sun compiler. We cannot see that the Java Language Specification (JLS) has been changed to allow such disambiguation, and other standards compliant compilers such as IBM's Jikes still reject the code. We don't know whether this is a case of misinterpreting the JLS, or a bug in the Sun Java compiler distributed with J2SE 1.4.
In the paragraph for Blocked state, make the following two changes:
Change "Blocking state" to "Blocked state".
Change the sentence:
"A thread also blocks if it fails ..."
to:
"A thread will be blocked if it fails ..."
The bullet:
"The wrapper classes (Boolean, Character, Number, Byte, Short, Integer, Long, Float, Double)"
should read (delete Number):
"The wrapper classes (Boolean, Character, Byte, Short, Integer, Long, Float, Double)"
In the middle of the page, change "\u0000" to '\u0000'.
The sentence:
"The remove() method deletes and returns the element at the specified index, contracting the list accordingly."
should read:
"The remove(int index) method deletes and returns the element at the specified index, contracting the list accordingly."
The following import statement can be deleted:
import java.applet.*;
The sentence:
"The Polygon class has the following constructors:"
should read:
"The Polygon class has the following constructor:"
In the row for the PrintWriter, change the sentence:
"A filter that allows textual representations of ..."
to:
"A writer that allows textual representations of ..."
Change the exception in the constructors:
RandomAccessFile(String name, String mode) throws IOException
RandomAccessFile(File file, String mode) throws IOException
to:
RandomAccessFile(String name, String mode) throws FileNotFoundException
RandomAccessFile(File file, String mode) throws FileNotFoundException
In the middle of the page, replace the following:
"It also has a special method that has the same name as the class. Such methods are called constructors, ..."
with:
"It also has a special method-like declaration that has the same name as the class, (2). Such declarations are called constructors, ..."
In the middle of the page, replace the sentence:
"Static members are distinguished from instance variables in a class definition by the keyword static in their declaration."
with:
"Static members are distinguished from instance members in a class definition by the keyword static in their declaration."
Replace the last row of the table:
-2147483648 |
-017777777777 |
-0x7fffffff |
with:
-2147483648 |
-020000000000 |
-0x80000000 |
A short note on creating and using packages.
A package statement can only occur as the first statement in a Java source
file.
The statement
package com.acme;
instructs the compiler to place the Java byte code for all the classes (and interface) specified in the source file in the package com.acme.
Think of a package name as a path in the file system.
In this case the package name com.acme corresponds to the path name com/acme.
So the Java byte code for all the classes (and interface) specified in the
source file Exercise1.java will be placed under the catalog com/acme.
Question: where is com/acme?
You can choose the location of com/acme by using the -d option (d for
destination) when compiling with javac. Assume that the current directory is called work, and the source code file
Exercise1.java is to be found here. The command
javac -d . Exercise1.java
(note the dot after the -d option to indicate the current directory) will create com/acme under the current directory, and place the Java byte code for all the classes (and interface) in it.
work | ------------------------ | | Exercise1.java com | acme | Exercise1.class
How do we run the program? Since the current directory is work and we want to run Exercise1.class, the *full name* of the Exercise1 class must be specified in the java command:
java com.acme.Exercise1
This will now result in the main() method from the com.acme.Exercise1 class being executed.
"Narrowing conversions between char and byte (or short) values on assignment always require an explicit cast, even if the value is in the range of the destination datatype."
The new rules state that a narrowing primitive conversion is valid if the following conditions are fulfilled:
1. The right-hand side expression (i.e. source) is a constant expression
of type byte, short, char or int.
2. The type of the left-hand variable (i.e. destination) is byte, short,
or char.
3. The value of the constant expression is in the range of
the destination datatype.
Replace the sentences:
"The number of bits shifted is always in the range modulus 32 for an int value, and in the range modulus 64 for a long value."
with:
"The shift distance is calculated as the value of the expression (right operand value & (size-1)), where size is either 32 or 64 depending on whether the promoted type of the left operand is int or long. Thus the shift distance is always in the range 0 to 31 when the promoted type of left operand is int, and in the range 0 to 63 when the promoted type of left operand is long."
Replace the following sentence in the lower half of the page:
"The value LITTLE_ADVICE results in only one advice at (5) being given."
with:
"The value LITTLE_ADVICE results in only one advice at (4) being given."
Entity | Declaration Context | Accessibility Modifiers | Outer Instance | Direct Access to Enclosing Context | Defines Static or Non-static Members |
Package level interface | As package member | public or default | No | N/A | Static variables + non-static method prototypes |
Top-level nested interface | As static class member | all | No | Static variables in enclosing context | Static variables + non-static method prototypes |
To make the figure consistent with Example 7.2, do the following:
In the figure, add public accessibility, '+', to the class AccessInTopLevelClass.
In the figure, remove public accessibility, '+', from the interface NestedTopLevelInterface1.
On top of the page, replace the line:
String replace(char old, char new)
with:
String replace(char oldChar, char newChar)
Replace the question:
"What would be the effect of calling enableEvent(AWTEvent.KEY_EVENT_MASK) on a component?"
with:
"What would be the effect of calling enableEvents(AWTEvent.KEY_EVENT_MASK) on a component?"
In the middle of the page, replace the sentence:
"Note that the first read() method read a byte, but returns an int value."
with:
"Note that the first read() method reads a byte, but returns an int value."
In the lower half of the page, replace the line:
FileOutputStream(File file) throws IOException
with:
FileOutputStream(File file) throws FileNotFoundException
"Note that the read() methods read an int in the range 0 to 65535 (0x0000–0xFFFF), i.e. a Unicode character. The value –1 is returned if the end of file has been reached."
should read:
"Note that the read() methods read Unicode characters which are 16-bit integer values in the range 0 to 65535 (0x0000–0xFFFF). The first method returns the character read as an int. The last two methods return the number of characters read into the char array. The value –1 is returned by all methods if the end of file has been reached."
To the existing list, add the following:
@see <class-name>#<member-name> <label>
@see <class-name>#<method-signature> <label>
{@link <class-name>#<member-name> <label>}
{@link <class-name>#<method-signature> <label>}
Additional explanation:
Strict adherence to the Java language specification requires the following declaration to start the execution of a Java program:
public static void main(String[] args)
This does not rule out any other legal non-accessibility modifiers like final. The Java compiler is however taking liberties with the specification allowing other declarations for starting the execution of a Java program.
See also the note on Inheritance of Superclass Members at the end of this errata.
public class BinConversion { public static void main(String args[]) { System.out.println(convert(43)); }
public static String convert(int i) { String res = ""; do { res = i % 2 + res; i /= 2; } while (i >= 1);
return res; } }
The Java Language Specification
(JLS) states in section 8.2 that:
"Members
of a class that are declared private are not inherited by subclasses of that
class. Only members of a class that are declared protected or public are
inherited by subclasses declared in a package other than the one in which the
class is declared.
Constructors, static initializers, and instance
initializers are not members and therefore are not inherited."
According to this view, inheritance is linked to DIRECT ACCESSIBILITY of superclass members. In this sense the private members of the superclass are NOT inherited by the subclasses, but these members do EXIST in a subclass OBJECT. Private members of the superclass may be indirectly accessible from a subclass object if the superclass provides the appropriate implementation. In the example below, the private variable i in superclass A exists in object b of subclass B, but this data member is not inherited by the subclass B.
class A {
private int i = 10; // Not
inheritable
public void printI() { //
Inheritable
System.out.println("i " + i);
}
}
class B extends A {}
public class Inheritance {
public static
void main(String[] args) {
B b =
new B();
b.printI();
}
}
Output from the program:
i 10
JLS further states (section 8.4.6):
"A class inherits from its direct superclass and direct superinterfaces all the non-private methods (whether abstract or not) of the superclass and superinterfaces that are accessible to code in the class and are neither overridden (§8.4.6.1) nor hidden (§8.4.6.2) by a declaration in the class."
We will make the appropriate changes in accordance with JLS in the second edition.