Errata for unit 1

advertisement
Errata to unit 1 of COMPS311

Page 2, 3rd paragraph
soft copy of chapters 38 to 43 ...
should be changed to:

soft copy of chapters 38 to 48 ...
Page 4, Reading 1.1
Sections 1.6 and 1.7 in the textbook explain the usefulness of Java
and can motivate you to learn it well. Section 1.8 has a trivial
'Welcome to Java‘ program that you can use in the upcoming
Activity 1.1 to test your IDE installation.
Should be changed to:

Sections 1.5 and 1.5 in the textbook explain the usefulness of Java
and can motivate you to learn it well. Section 1.7 has a trivial
'Welcome to Java‘ program that you can use in the upcoming
Activity 1.1 to test your IDE installation.
Page 7, first paragraph after example, first line
... from Listings 9.3 and 9.4 in...
should be changed to:

... from Listings 10.3 to 10.4 in ...
Page 12, Reading 1.2
Section 7.6 in the textbook discusses status variables and their
differences with instance variables. Section 9.4 explains the use of
this reference to refer to the current object. Section 9.5 covers
abstraction and encapsulation. Section 10.2 has an example of parent
and child classes.
should be changed to:

Section 8.7 in the textbook discusses status variables and their
differences with instance variables. Section 10.4 explains the use of
this reference to refer to the current object. Section 10.5 covers
abstraction and encapsulation. Section 11.2 has an example of parent
and child classes.
Page 12, Self-test 1.1
Study Listings 10.1, 10.2 and 10.3 on pages 359–61 of the textbook.
1 Identify the subclasses and the super class.
2 Name the methods that the subclasses inherited from the super class.
3 Describe the difference between an instance variable and a class
variable. Determine if the data field radius declared on line 2 of
Listing 10.2 is an instance variable or a class variable.
4 Explain the use of this keyword on line 8 of Listing 10.2.
5 Study Listing 10.4 on page 362 of the textbook. Use this example to
explain encapsulation.
should be changed to:

Study Listings 11.1, 11.2 and 11.3 on pages 399-402 of the textbook.
1 Identify the subclasses and the super class.
2 Name the methods that the subclasses inherited from the super class.
3 Describe the difference between an instance variable and a class
variable. Determine if the data field radius declared on line 2 of
Listing 11.2 is an instance variable or a class variable.
4 Explain the use of this keyword on line 8 of Listing 11.2.
5 Study Listing 11.4 on page 403 of the textbook. Use this example to
explain encapsulation.
Page 16, Reading 1.3
Section 10.8 of the textbook explains polymorphism and dynamic
binding.
should be changed to:

Section 11.8 of the textbook explains polymorphism and dynamic
binding.
Page 17, first paragraph
We shall explain the notion of abstract classes using Listing 11.1 on page
390 in the textbook. An abstract class is identified with the abstract
modifier as highlighted on line 1 of the listing. An abstract class usually
has one or more abstract methods also identified with the abstract
modifier. In the example, the abstract class GeometricObject has two
abstract methods declared on lines 44 and 47.
should be changed to:

We shall explain the notion of abstract classes using Listing 14.1 on page
482 in the textbook. An abstract class is identified with the abstract
modifier as highlighted on line 1 of the listing. An abstract class usually
has one or more abstract methods also identified with the abstract
modifier. In the example, the abstract class GeometricObject has two
abstract methods declared on lines 51 and 55.
Page 19, Reading 1.4
Section 11.2 of the textbook explains abstract classes.
should be changed to:

Section 14.2 of the textbook explains abstract classes.
Page 22,
Generics is a new feature introduced to Java since JDK 1.5. It is quite
similar to the templates in C++. It allows you to declare classes,
interfaces, and methods that use a class but without committing to a
specific class. Consider MyStack.java from the textbook in Listing 10.9.
should be changed to:

Generics is a new feature introduced to Java since JDK 1.5. It is quite
similar to the templates in C++. It allows you to declare classes,
interfaces, and methods that use a class but without committing to a
specific class. Consider MyStack.java from the textbook in Listing 11.9.
Page 22, caption of program 1.15:
Program 1.15 MyStack class from the textbook (Listing 10.9)
should be changed to:
Program 1.15 MyStack class from the textbook (Listing 11.9)

Page 23, Reading 1.6

The first part of the reading covers Sections 10.11 and 11.9. It shows
should be changed to:
The first part of the reading covers Sections 11.12 and 14.9. It shows
Page 25, Reading 1.7
Section 22.1 of the textbook describes the hierarchy of the interfaces,
abstract classes and concrete classes in the Java Collection
Framework. Section 22.2 explains the Collection interface which
declares the methods for our use its concrete child classes. Section
22.3 discusses a few implementations of sets. Section 22.5 explains
lists implemented as arrays and linked lists. Section 22.10 covers
maps that allow you to access a data item using a key.
should be changed to:



Section 22.1 of the textbook describes the hierarchy of the interfaces,
abstract classes and concrete classes in the Java Collection
Framework. Section 22.3 explains the Collection interface which
declares the methods for our use its concrete child classes. Section
22.4 discusses a few implementations of sets. Section 22.6 explains
lists implemented as arrays and linked lists. Section 22.11 covers
maps that allow you to access a data item using a key.
Page 28, 1st line
In our sample code taken from Listing 11.8, the action of pressing the..
should be changed to:
In our sample code taken from Listing 14.8, the action of pressing the
Page 29. Reading 1.8. This reading cannot be found in the 8th edition of the book. You
can find a copy of the reading at:
http://plbpc001.ouhk.edu.hk/~mt311/2010-OCT/12.5-4.pdf
Page 31. Reading 1.9.
Section 13.8 of our textbook explains the use of JPanel.
should be changed to:
Section 12.6 of our textbook explains the use of JPanel.

Page 31, second last line:
.. read the explanation in Section 13.8 for help.
should be changed to:
.. read the explanation in Section 12.6 for help.

Page 33, 3rd line:
.. MessagePanel in Listing 14.10 of...
should be changed to:

.. MessagePanel in Listing 15.8 of...
Page 33, last line of 3rd paragraph

... version of ButtonDemo in Listing 16.2 of the textbook.
should be changed to:
... version of ButtonDemo in Listing 17.2 of the textbook.
Page 34, last line:

.. consult Section 15.3.2 in the textbook.
should be changed to:
.. consult Section 16.5 in the textbook.
Page 35, 1st paragraph
Visit the textbook webpage for Chapter 16 and download the five files
associated with Section 16.6. Compile and run
should be changed to:

Visit the textbook webpage for Chapter 17 and download the five files
associated with Section 17.6. Compile and run
Page 35, last paragraph:
• JTextArea — Enters multiple lines of texts (Chapter 16)
• JComboBox — Selects a single item from a list (Chapter 16)
• JList — Selects one or more items from a list (Chapter 16)
• JScrollBar — Scrolls vertically or horizontally (Chapter 16)
• JSlider — Scrolls vertically or horizontally with marked
measurement (Chapter 16)
should be changed to:

• JTextArea — Enters multiple lines of texts (Chapter 17)
• JComboBox — Selects a single item from a list (Chapter 17)
• JList — Selects one or more items from a list (Chapter 17)
• JScrollBar — Scrolls vertically or horizontally (Chapter 17)
• JSlider — Scrolls vertically or horizontally with marked
measurement (Chapter 17)
Page 36, reading 1.10
Section 16.2 of the textbook teaches the coding for buttons. Sections
16.3, 16.4, 16.5 and 16.6 discuss checkboxes, radio buttons, labels
and text fields respectively used in everyday GUI.
should be changed to:

Section 17.2 of the textbook teaches the coding for buttons. Sections
17.3, 17.4, 17.5 and 17.6 discuss checkboxes, radio buttons, labels
and text fields respectively used in everyday GUI.
Page 36, last paragraph:
Modify the program in the previous activity with two new features. You
are expected to modify the existing classes instead of creating new
classes. If you have no clue to this exercise, study section 16.2.4 for the
use of buttons or section 16.4 for the use of radio buttons. If reading the
textbook still does not help, you can watch the various videos available
from the textbook‘s video webpage for chapter 16.
should be changed to:

Modify the program in the previous activity with two new features. You
are expected to modify the existing classes instead of creating new
classes. If you have no clue to this exercise, study section 17.2.4 for the
use of buttons or section 17.4 for the use of radio buttons. If reading the
textbook still does not help, you can watch the various videos available
from the textbook‘s video webpage for chapter 17.
Page 37, reading 1.11
Section 18.2 of the textbook gives an overview of exception
handling. Section 18.5 goes into more details.
should be changed to:


Section 13.2 of the textbook gives an overview of exception
handling. Section 13.5 goes into more details.
Page 38, 1st paragraph
Figure 18.3 on page 634 of the textbook shows how an
should be changed to:
Figure 13.3 on page 465 of the textbook shows how an
Page 38, first paragraph of section Exception types
Figure 18.1 on page 630 of the textbook shows the hierarchy of the
commonly used exception classes defined in Java. Throwable is the root
class of all exception classes. Figure 18.4 on page 635 of the textbook
shows a few methods that can be used to get information from...
should be changed to:

Figure 13.1 on page 461 of the textbook shows the hierarchy of the
commonly used exception classes defined in Java. Throwable is the root
class of all exception classes. Figure 13.4 on page 466 of the textbook
shows a few methods that can be used to get information from...
Page 39:
...
2 In Listing 18.6 of page 637 in the textbook, line 26 declares an
exception and line 30 throws an exception. Will the program work if
we remove the exception declaration?
3 What are the benefits of using exception handling?
4 Answer Question 18.2 on page 645 of the textbook. Explain the
program output. ...
should be changed to:

...
2 In Listing 13.8 of page 468 in the textbook, line 26 declares an
exception and line 30 throws an exception. Will the program work if
we remove the exception declaration?
3 What are the benefits of using exception handling?
4 Answer Question 13.2 on page 475 of the textbook. Explain the
program output. ...
Page 44, self-test 1.1
1 Circle4 and Rectangle1 are the subclasses of GeometricObject1. In
other words, GeometricObject1 is the super class of Circle4 and
Rectangle. (Remedial reading Section 10.2)
2 The methods that the subclasses inherited from the super class are
getColor, setColor, isFilled, setFilled, getDate and toString.
(Remedial reading Section 10.2)
3 Every object of the same class has its own copy of an instance
variable. The change of its value for one object does not affect
another object. On the other hand, a class variable is shared by all
objects of the same class. The change of its value affects all objects.
Since the variable on line 2 does not have the static modifier, it is an
instance variable. (Remedial reading Section 7.6)
4 The parameter of the method is radius. It collides with the instance
variable with the same name declared on line 2. The use of this
before radius allows us to refer to instance variable not the method
parameter. (Remedial reading Section 9.4)
5 The main method of TestCircleRectangle invokes getArea method of
Circle4 and Rectangle1. Without the knowledge of how areas are
computed, the method can display the correct areas. Classes Circle4
and Rectangle1 are said to have encapsulated area calculations.
(Remedial reading Section 9.5)
should be changed to:
1 Circle4 and Rectangle1 are the subclasses of GeometricObject1. In
other words, GeometricObject1 is the super class of Circle4 and
Rectangle. (Remedial reading Section 11.2)
2 The methods that the subclasses inherited from the super class are
getColor, setColor, isFilled, setFilled, getDate and toString.
(Remedial reading Section 11.2)
3 Every object of the same class has its own copy of an instance
variable. The change of its value for one object does not affect

another object. On the other hand, a class variable is shared by all
objects of the same class. The change of its value affects all objects.
Since the variable on line 2 does not have the static modifier, it is an
instance variable. (Remedial reading Section 8.7)
4 The parameter of the method is radius. It collides with the instance
variable with the same name declared on line 2. The use of this
before radius allows us to refer to instance variable not the method
parameter. (Remedial reading Section 10.4)
5 The main method of TestCircleRectangle invokes getArea method of
Circle4 and Rectangle1. Without the knowledge of how areas are
computed, the method can display the correct areas. Classes Circle4
and Rectangle1 are said to have encapsulated area calculations.
(Remedial reading Section 10.5)
Page 47, self-test 4.7. Again, Section 12.5 is not in the 8th edition of the textbook.
Please refer to the copy at:
http://plbpc001.ouhk.edu.hk/~mt311/2010-OCT/12.5-4.pdf
Download