Technical University of Denmark DTU
02115   Java Programming
Autumn 2011

Week plan #5

For the week   26. September - 30. September


Preparations for the week

Just a comment on Example60 from the PS textbook to the execution of
      D1 d2 = new D2();

The variable d2 will refer to an instance of class D2 thus defining its dynamic type. The details are as follows (refer to the last seven lines of page 28 in the PS textbook):

  1. The field f of the D2-instance is initialized to the default value 0
  2. The constructor of the superclass D1 implies an application of method m2()
  3. Method m2() prints out D1.m2   and then applies method m1()
  4. Because method m1() of class D1 has been overriden in the subclass D2 the method m1() of class D2 will be executed because the dynamic class type of d2 is D2
  5. The execution of m1() from class D2 prints out D2.m1:0. The value 0 is the default value given to f previously
  6. At last the assignment f = 7 from the constructor D2() gives f its final value

The lectures of the last week has covered most of the Chapters 8 and 9. And if you have followed up by working through the text as told in the section After the lectures on the last Week plan you have become familiar with the concepts and are able to use them.

On page 291 a reference was given to Joshua Bloch's Effective Java, a textbook which I strongly recommend. I was not able to look up sample chapters of the book on the net, but I have the printed book.

Before buying the book mentioned above just take a look at the paper   Java performance   written by Peter Sestoft and referenced at the course home page link to Some Java supplement. The paper gives some advices on improving the execution of Java programs.

Do you think a class can inherit from more than one superclass ?
In the textbook PS section 9.5 (page 22) the form of an extends-clause is described by

      class C extends B { ... }

and we are told, that class C is a subclass and hence a subtype (section 5.5) of B. And from that we can judge, that it does not make sense if a class should be a subtype of two or more probably independant super classes.

Thus: A class can only have one super class.



The BlueJ environment has surprised me when I put a new BlueJ project on the subpage 'Some BlueJ projects': I just defined a project consisting of the two files from Example 27 and Example 28 of the PS textbook (page 23) without spliting up Example 27 into four separate files.
Try to save the .jar, and then compile and run the main() method from within BlueJ.



The Chapters 10 and 12 present important concepts and very useful Java constructs to be used by the experienced programmer.

Chapter 10 introduce abstract classes and interfaces and thus gives the full background for understanding the description in the PS textbook on collections, refer to the overview on page 92. Chapter 12 introduce the SortedMap interface and the concrete classes TreeSet and TreeMap.

As an introduction to this week, prepare yourself by study the BK textbook to the following extent:

  1. Chapter 10: 10.1 - 10.2.4; pages 300-314:
  2. Chapter 12: 12.1 - 12.3; pages 381-393:


The lectures

We will cover selected parts of the textbooks, primarily the following parts of BK
  - Chapter 10, pages 300-336
  - Chapter 12, pages 381-406

But many subjects of the chapters are left for personal studies.



Exercises at the PC's

Exercises are taken solely from the BK textbook:

After the lectures

The lectures has left out many details of the Chapters 10 and 12 of BK. Work through the missing parts and do the exercises missed at the exercise class, refer to the section above. Feel free to add exercises of your own choice.

At the end of this week you are supposed to be familiar with the following parts of the BK textbook:



Besides the above mentioned sections of the PS textbook read the following sections:
Jens Thyge Kristensen, Email: jtk@imm.dtu.dk

Newest edition:   26. September (minor corrections to the language and the addition of a reference to the last seven lines of page 28 in the PS textbook)
Previous editions:
    - 21. September (comments on PS - Example60 added and pages 407-423 of the BK textbook has been skiped to next week)
    - 20. September
    -   8. April (just the heading and footing)