|
|
|
02115 Java Programming |
Autumn 2011 |
Week plan #2
For the week 5. September - 9. September
The Java knowledge of the audience
At the lectures last Tuesday we have the intentions to find out about
your current Java knowledge. But our questioning was not precise
enough.
The technical level of the course will be as stated in the official
course description and at the subpage
Course goals
But after working with the subjects from the PS textbook as
stated below in the section After the lectures you will be convinced
that the course is on a level higher than just introductory.
I much appreciate to have received exercise suggestions by e-mail, but
those exercises were unfortunately better suited for a course on
Algorithms and data structures. This week the exercises are
grouped on different levels by an or
Preparations for the week
Last week we saw how to make new objects composed of other objects,
primarily in the clock example, where a
ClockDisplay
-object is made up of two
NumberDisplay
-objects and a String
-object.
On pages 68-70 of BK we can see how that is achieved:
- Fields
hours
, minutes
and
diplayString
are declared (page 68 of BK).
- The two
ClockDisplay
-constructors both create two
NumberDisplay
-objects and assign their references
to the appropriate fields hours
and
minutes
. At last the diplayString
is assigned it's value by use of methods of the class.
On Figure 3.4 of BK (page 71) the relations between the
objects are shown - the displayString
and it's reference
to a String
-object holding the value
"15:23"
has been left out.
Actually, when experimenting with the lab-classes and the
mail-system projects, we can figure out that behind
the scene a LabClass
-object and a
MailServer
-object must hold fields which refer to
flexible object structures capable of holding arbitrary numbers
of Student
-objects and MailItem
-objects,
respectively.
This week projects using flexible object structures like
lists, sets and maps are introduced. The PS textbook gives
an overview of the available structures on page 92. Take a look,
but skip syntactic details like List<T>
,
Set<T>
and Map<K,V>
and
on the figure don't worry about interfaces and abstract classes.
Focus on the structure and on the Concrete classes of which
BK in the Chapters 4 and 5 introduces the
ArrayList<T>
,
the HashMap<K,V>
and the
HashSet<T>
. The general applicable class
types T
, K
and V
are all
substituted with class String
in the Chapter 4 and 5 BlueJ projects of BK.
Before going on with the BK textbook I presume that you
have done what has been stated in Week plan #1.
As a minimal preparation to this week study the Chapters 4 and 5 of
BK to the following extent:
- Chapter 4: 4.1 - 4.6 and 4.12.2 - 4.12.4; pages 87-94 and 117-119:
- Read the chapter introduction and sections 4.1 - 4.6,
pages 87-94
Work through the exercises 4.1 - 4.6
Section 4.5 gives you an introduction to the generic class
ArrayList<T>
showing examples
on three specific choices of T
, those
are String
, Person
and
TicketMachine
- Read sections 4.12.2 - 4.12.4, pages 117-119, including only
the exercises 4.46 - 4.48, in order to be introduced to arrays
- Chapter 5: 5.1 - 5.3.1, 5.5 - 5.6.2 and 5.7; pages 128-138,
146-149 and 152-153:
- Read the chapter introduction and sections 5.1 - 5.3.1,
pages 128-138
Don't forget to work through the exercises 5.1 - 5.6 in order to be
familiar with the idea of the TechSupport system example
and with the use of library classes, here the
String
class
- Read sections 5.5 - 5.6.2 (pages 146-149) and only work
through the exercises 5.23 and 5.24 in order to be
introduced to the important map concept and its particular
HashMap
implementation
- Read section 5.7 and do the Exercise 5.32 (pages 152-153)
to be introduced to sets and to be aware of the differences
between lists, maps and sets
The lectures
We will cover selected parts of the textbooks, primarily the following
parts of BK
- Chapter 4, pages 87-123
- Chapter 5, pages 128-165
Exercises at the PC's
In case you end up in a state of a locked terminal session you have
to kill the session by holding [CTRL] and [ALT] pressed
down and in that state press [BACKSPACE] twice.
Unsaved work is lost, but afterwards a normal logon is possible.
Exercises are taken solely from the BK textbook. The exercises
are grouped by use of or. Choose a group matching your
interests and your present Java experience:
- Chapter 4:
Either do Exercises 4.12-4.16, 4.28, 4.29 or
Exercises 4.25-4.27, 4.34-4.35 or
Exercises 4.36-4.40
- Chapter 5:
Either do Exercises 5.7-5.9, 5.25-5.30, 5.47-5.50
or
Exercises 5.32, 5.37, 4.41 and 5.59-5.60
For solving 5.37 you may refer to PS section 8.4
After the lectures
The lectures has not covered all details of the chapters 4 and 5 of
BK. Work through the missing parts and do the exercises missed
at the exercise class, refer to the section above, with the
supplements mentioned below as a minimum.
If you would like to exercise the use of ArrayList
's
in a more creative way, then do Exercises 4.25-4.27 and
4.34-4.40.
At the
end of this week you are supposed to be familiar with the following
parts of the BK textbook:
The consequences of applying the keywords static
and
final
as introduced in section 5.13 can be summarised
as follows:
Keyword |
Concept | Description |
final (without static ) |
instance constant |
Every object (instance) has it's own constant |
static (without final ) |
class variable |
All objects share one common variable (field) |
static final |
class constant |
All objects share one common constant |
In the PS textbook read the following sections:
- Section 12.5 on pages 50 and 52
This section gives an overview of the Java loop statements. By
now some of the examples hold details which are not easily
understandable.
Section 12.5.2 (page 50) states the generality of the for-loop
introduced in section 4.8.1 of BK (pages 97-99).
In Code 4.3 of BK (page 97) the field notes
is an expression which comply to have type
Iterable<t>
because an ArrayList
is iterable.
- In chapter 22 (page 92) some of the syntactic details should
be understandable after having read section 5.4.4 of
BK (page 146).
- On an
ArrayList
-object all methods mentioned
on pages 94 and 95 can be applied.
- Section 22.7 on page 102 gives an overview of the proces of
iterating over a collection. The main parts of the section can
be understood after having read sections 4.8.3 - 4.8.5 on pages
102-105 of BK.
Have in mind Example 131 (page 103) which is used in
Example 70 and Example 71 - to be studied
at special occasions.
- Section 8 on pages 16 and 18 is on arrays
Section 8.1 states the general characteristics on declaring
arrays and accessing array. Ought to be fully understandable
when sections 4.12.2 - 4.12.4 of BK (pages 117-119) has
been read.
Section 8.3 covers multidimensional arrays (not a subject of
the BK textbook) - supply with Example 22 on page 19.
- On a
HashSet
-object all methods mentioned
on pages 94 and 96 can be applied.
- On a
HashMap
-object all methods mentioned
on page 98 can be applied.
The syntactic notions ? extends K
and
? extends V
are unknown so far.
- Section 22.10 on page 108
This section gives useful advises on choosing the right kind of
collection class or map class depending on the problem to be solved.
Jens Thyge Kristensen,
Email: jtk@imm.dtu.dk
Newest edition: 1. September (the section 'The Java knowledge
of the audience' has been added)
Previous editions:
- 30. August
- 8. April (a skeleton only)