| Contents [0/9] | 
| Video [1/9] | 
| Abstract Data Type (ADT) [2/9] | 
| ADTs in Java [3/9] | 
| Data structure [4/9] | 
| Fields and methods [5/9] | 
| Static fields and methods [6/9] | 
| Generic classes [7/9] | 
| Interfaces [8/9] | 
| What is memory? [9/9] | 
(Click here for one slide per page)
| Video [1/9] | 
In several parts.
Only the first video will be covered on exams. The rest is for orientation, so that you can read the code. These topics will be revisited in SE350, CSC347 and CSC373.
00:00 Abstract Data Types and Data Structures 03:40 First example: main method 07:18 The representation of Strings 08:50 The meaning of arrows 11:31 Constructors and this 15:31 Push 18:34 IsEmpty and pop
00:00 Static fields 03:23 Static methods
00:00 Generic class parameters 02:26 Generics and array creation 04:47 Generic type enforcement 05:34 Iterators 12:29 The Iterable interface and forall loops
| Abstract Data Type (ADT) [2/9] | 
An Abstract Data Type (ADT) specifies
For example, a stack (think of a stack of plates) includes the operations to :
s
| ADTs in Java [3/9] | 
In Java we write this as follows (using Strings instead of plates):
| 
01 | package algs13; public class StackOfStrings { public StackOfStrings { /* ... */ } public boolean isEmpty () { /* ... */ } public void push (String item) { /* ... */ } public String pop () { /* ... */ } } | 
We use the ADT as follows:
| 
08 | StackOfStrings stack = new StackOfStrings(); stack.push("a"); if (! stack.isEmpty()) { String item = stack.pop(); } | 
| Data structure [4/9] | 
A data structure provides code to implement an ADT
The most important choice is how to store data
For stack, we will look at two choices:
Data storage affects performance of all the operations
| Fields and methods [5/9] | 
Local variables are stored in method invocations. Fields are stored in objects.
file:XFixedCapacityStackOfStrings.java [source] [doc-public] [doc-private] 
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 
      
| Static fields and methods [6/9] | 
          The keyword static changes the meaning of fields and methods.
        
file:XFixedCapacityStackOfStringsWithStaticMember.java [source] [doc-public] [doc-private] 
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
| Storage | Where stored? | When allocated? | 
|---|---|---|
| static | stored with class | when class loaded | 
| nonstatic | stored with object | when object allocated (with new) | 
| local variable | stored with method invocation | when method called | 
| Method | Has "this"? | 
|---|---|
| static | no | 
| nonstatic | yes | 
 
      
| Generic classes [7/9] | 
A generic class has a type parameter. Type is not stored at runtime.
file:XFixedCapacityStack.java [source] [doc-public] [doc-private] 
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 
      
| Interfaces [8/9] | 
          Some language features use special interfaces, such as Iterable.
        
file:XFixedCapacityIterableStack.java [source] [doc-public] [doc-private] 
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
| Nonstatic | Static | |
|---|---|---|
| field | stored with object | stored with class | 
| method | has "this" | does not have "this" | 
| class | has "this$0" | does not have "this$0" | 
 
      
| What is memory? [9/9] | 
What does the machine memory look like when you see a picture like this:
 
        To fully answer this question, you need to take the systems classes. But it is useful to have an idea of the memory, even if the details are not exactly correct.
| Method calls (Stack) | Objects (Heap) | |||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 
 
 | 
 
 | 
          Above, I show two parts of memory.  On the left is storage for
          method calls (commonly called the stack), on the right is
          storage for objects (commonly called the heap).  Arrays are
          objects in java.  Machine addresses are shown as hexadecimal numbers
          beginning with the prefix 0x.
        
Each entry includes some overhead.
getClass() method.  If you are interested, you can
            read
            more.
          Revised: 2008/03/17 13:01