Title: Using%20Memory%20Diagrams%20When%20Teaching%20a%20Java-Based%20CS1
1Using Memory Diagrams When Teaching a Java-Based
CS1
- Mark A. Holliday
- David R. Luginbuhl
- Dept of Mathematics and Computer Science
- Western Carolina University
Department of Computer Science Univ. of North
Carolina --- Asheville September 30,
2003 Asheville, NC
2Overview
- Motivation and Introduction
- Diagramming as a teaching tool
- Classes, objects, variables, and references
- Method invocation, cascading, and composition
- Primitive types, fields, visibility, and
parameter passing - Static fields and methods
- Arrays
- Diagramming as an assessment tool
- Conclusion
3Motivation
- Problem
- How to introduce and reinforce object-oriented
concepts in an introductory CS course - How to help CS1 students visualize the state of
the computer as the Java program executes - Solution
- Develop a visual representation of the effects of
executing a sequence of Java statements - The visual representation accesses an alternative
and supplemental mode of thinking
4Relationship to Psychology
- In other application domains psychologists have
studied the effect on text comprehension by
supplementing with visual representations - P. Goolkasian, Picture-Word Differences in a
Sentence Verification Task, Memory and Cognition,
1996. - B. Henderson, personal communication. 2003.
5Goals of Visual Representation
- What goals should this visual representation
have? - Be a precise but simple visual language that a
student can use to write visually the effect of
each step during the execution of a Java code
fragment - That language should just represent the most
important concepts involved in the effects of
each Java statement. - Thus the language should represent an abstraction
but what should be in the abstraction? - object-oriented features
- state of the memory of the computer (abstractly)
during the use of these object-oriented features
6Object-Oriented Features
- Example object-oriented features we want to
include in the abstraction - Be able to distinguish between
- Classes objects references variables
- Reference types variables primitive type
variables - Private public (for fields and methods)
- Static instance (for fields and methods)
7Object-Oriented Features (cont.)
- Method invocation, object and reference
construction, return of a reference - Method composition and method concatenation
- Arrays versus other objects
- Local variables, parameters, and fields are all
variables - Visibility (scope) rules
- Parameter passing
8Language Design Principles
- Be a form of diagrams (call them Memory Diagrams)
- diagrams are sufficiently detailed since we want
to represent the Java features abstractly - is low-tech so easy for students to write
themselves during in-class groupwork and during
written tests.
9Language Design Principles
- Be a sequence of diagrams. One for each change in
the state of memory. Thus, a Java statement may
involve several diagrams. - foo 2 foo
- How can something be equal to twice itself?
- read as gets instead of as equals
- In English we read left-to-read, but here you
need to read right-to-left. - The diagram for the right-hand side of an
assignment is before the diagram for the
left-hand side and the assignment.
10Language Design Principles
- Use shape to reinforce when concepts are the same
- Use shape to reinforce when concepts differ
- Use position to reinforce concepts
11Relationship to Other Work
- Unlike UML since UML is not primarily focused on
state of memory - Diagrams used in many textbooks, but without much
emphasis - WU2001 is the closest but less developed
12Objects, Variables, and References
- String acolor, favColor // a)
- acolor blue // rhs is b)
- // lhs is c)
- favColor aColor // d)
Figure a)
- Features
- Labels on variables
- Variables are rectangles
- Rectangle is empty (null value not shown!)
13Objects, Variables, and References
- String acolor, favColor // a)
- acolor blue // rhs is b)
- // lhs is c)
- favColor aColor // d)
- Features
- Labels on objects
- Objects are circles
- Reference exists but is floating (not in
variable!)
String blue
Figure b)
14Objects, Variables, and References
- String acolor, favColor // a)
- acolor blue // rhs is b)
- // lhs is c)
- favColor aColor // d)
- Features
- Only now is the reference in the variable
- Reference starts inside the variable (so it
occupies the variable)
String blue
Figure c)
15Objects, Variables, and References
- String acolor, favColor // a)
- acolor blue // rhs is b)
- // lhs is c)
- favColor aColor // d)
- Features
- Assignment means copying the reference, not
moving it
Figure d)
16Method Invocation
- otherColor red
- aColor blue // a)
- aColor aColor.concat(otherColor)
- // rhs call is b)
- // rhs return is c)
- // lhs is d)
- Features
- Method indicated by line on object
- Indicates each object has method
- Method is public
Figure a)
17Method Invocation
- otherColor red
- aColor blue // a)
- aColor aColor.concat(otherColor)
- // rhs call is b)
- // rhs return is c)
- // lhs is d)
- Features
- Squiggly line indicates invocation
- Argument is a copy of the reference inside
variable otherColor
Figure b)
18Method Invocation
- otherColor red
- aColor blue // a)
- aColor aColor.concat(otherColor)
- // rhs call is b)
- // rhs return is c)
- // lhs is d)
- Features
- New object and reference created
- New reference is floating and is what is returned
Figure c)
19Method Invocation
- otherColor red
- aColor blue // a)
- aColor aColor.concat(otherColor)
- // rhs call is b)
- // rhs return is c)
- // lhs is d)
- Features
- New reference replaces old content of variable
aColor - blue object will be garbage-collected
Figure d)
20Primitive Types, Fields, Multiple Instances
- Primitive type variables have numeric value
- As opposed to ref types
- Private fields represented inside object
- Using rectangles indicates fields are just
variables associated with objects - Different Student objects have same fields with
(possibly) different values
Student
score
name
87
String Sue
Student
score
name
85
String Bob
21Static fields and methods
- john.punchIn()
- Employee.advance(8)
- john.punchOut()
- // figure shown at this point
- Features
- Static fields and methods are with the class
itself (displayed as a diamond and existing
before any object, i.e. circle)
Employee
(8)
advance
clock
8 16
Employee
start
end
8
16
22Static fields and methods
- System.out.println(some string)
- // figure shown at this point
- Features
- An example of a static public field that is
widely used
23Parameter Passing and this
- Car windstar new Car()
- Car outback new Car()
- windstar.drive(500)
- outback.drive(1000)
- if (windstar.driveMoreThan( outback))
- // figure shown at this point
-
- public boolean driveMoreThan(Car other)
- return this.odometer gt other.odometer
- // rectangle for variable other is
- // actually shown next to
- // the parameter declaration
- // in the method header
24Pass By Value Parameter Passing
- int num 5
- Car aCar new Car(1000)
- this.doSomething(num, aCar)
-
- public void doSomething(int value, Car theCar)
- value
- theCar new Car(500)
- // rectangles for parameters
- // are actually shown next to
- // the parameter declaration
- // in the method header
25Pass By Value Parameter Passing
- int num 5
- Car aCar new Car(1000)
- this.doSomething(num, aCar)
-
- public void doSomething(int value, Car theCar)
- value
- theCar.drive(500)
- // rectangles for parameters
- // are actually shown next to
- // the parameter declaration
- // in the method header
26Method Cascading
- String first Blue
- String second Green
- String third Red
- String last
- last first.concat(second).concat( third)
- // last is BlueGreenRed
27Method Cascading
28Method Composition
- String first Blue
- String second Green
- String third Red
- String last
- last third.concat(first.concat( second))
- // last is RedBlueGreen
- // do
- // last first.concat(
- // second.concat(third))
- // to get BlueGreenRed
29Method Composition
30Two-Dimensional Array (Primitive Base Type)
31Ragged Two-Dimensional Array (Primitive Base Type)
32Language Design Principles
- Use shape to reinforce when concepts are the same
- all kinds of variables (local variables,
parameters, and fields) are rectangles - all objects are circles
- all classes are diamonds
- all references are straight arrows
- all method calls are wiggly arrows with
parentheses (for the arguments)
33Language Design Principles
- Use shape to reinforce when concepts differ
- variables, objects, classes all have different
shapes (rectangles, circles, and diamonds) - references and method calls have different shapes
(straight arrows and wiggly arrows)
34Language Design Principles
- Use position to reinforce concepts
- public fields and methods are on the border of
the corresponding object (if instance fields and
methods) or class (if static fields and methods)
border implies accessible from both inside and
outside - private fields and methods are inside the
corresponding object or class - static fields and methods are with the class (the
diamond) while instance fields and methods are
with particular objects of that class (one of the
circles) - each object of a class has copies of all the
instance fields and methods of that class and
those copies are independent - the reference inside a reference variable starts
inside the variable, not on the border. This
indicates that the reference is what the variable
holds and that the variable can only hold one
reference at a time.
35Student Exposure to Diagrams
- We introduce these diagrams to students on the
first day of CS1 class - We ask students to produce diagrams of their own
- In weekly closed labs
- On quizzes and tests
- In in-class groupwork
36Student Exposure to Diagrams
- In in-class groupwork
- all groups at blackboards so that everyone can
see the diagrams and multiple group members can
be drawing simultaneously - everyone must be able to explain during the
demonstration - no chalk for the strongest group member
- at least a third of lecture time is spent doing
this (with an upperclass student helper assisting)
37Student Exposure to Diagrams
- How do we have the time for all the groupwork and
diagramming? - Ours is a minimalist CS1
- no exception handling
- no inheritance, abstract classes, or interfaces
- no recursion
- no inner classes or event-driven code
- no graphics
- but we do real console I/O (not hidden)
- Bottom line reinforcement of concepts in a
number of contexts - But not just for learning
38Student Assessment
- By having students use diagrams themselves, we
have them demonstrate their comprehension of
object-oriented concepts - We believe these diagrams have potential for
measuring programming comprehension
39Example Use in Assessment
- Test Problem From Last Fall Diagram the program
fragment below - Dog spot // fig a)
- spot new Dog("spot")
- // right hand side is fig b)
- // left hand side and equal sign is fig c)
- System.out.println(spot.toString()) // fig d)
- Note last line particularly
- Static public variable (System.out)
- Method composition
- PrintStream object
- Dog object
- Creation of a String object
40Results(13 students)
Dog spot // fig a) spot new Dog("spot")
// right hand side is fig b) // left hand
side and equal sign is fig c) System.out.println(s
pot.toString()) // fig d)
- Figure a
- 11 correct
- 2 labeled rectanglewith name of class
- Figure b
- 4 correct
- 2 put spot inside var rectangle
- 4 didnt show name field
- 3 had more serious errors
- Figure c all but 1 student correct
41Results(13 students)
Dog spot // fig a) spot new Dog("spot")
// right hand side is fig b) // left hand
side and equal sign is fig c) System.out.println(s
pot.toString()) // fig d)
- Figure d
- All but 3 students showed call to toString()
correctly - Of those 10
- 2 students failed only to show System.out
correctly - 1 showed nothing else correctly
- 5 missed the creation of a String object from
toString() - They got the println() call right
- 2 showed the String object
- But they missed the println() call
42Evaluation of Effectiveness for Assessment
- Above example illustrates how the diagrams are
used qualitatively to assess student
comprehension - to pinpoint problems and provide proper
reinforcement of specific concepts - Can we also use them for quantitative assessment?
- Can we also evaluate how effective they are in
assessment?
43Evaluation of Effectiveness for Assessment
- Completed Study Correlation of score on memory
diagram question with rest of test and with
course score - Three test questions from two CS1 classes
- Two studies (correlation with rest of test and
correlation with course score) for each of the
three questions (three experiments)
44Evaluation of Effectiveness for Assessment
- An example qualitative comparison using the third
test question (experiment three) - Histogram is sorted by memory diagram question
score - The three series of scores appear to track each
other - Mean score of the memory diagram question is
significantly lower - not surprising since a correct memory diagram
requires a deeper understanding of the effect of
a program fragment
45Evaluation of Effectiveness for Assessment
- In the first study there were three statistical
tests, one for each experiment. For those
statistical tests the null hypothesis was - H0 A student doing well on the memory diagram
question does not have a positive correlation
with that student doing well on the rest of the
test. - The alternative hypothesis is
- Ha A student doing well on the memory diagram
question does have a positive correlation with
that student doing well on the rest of the test.
46Evaluation of Effectiveness for Assessment
- For both studies the statistical test for each
experiment used the Pearson product moment
correlation coefficient as the test statistic. - The value of the Pearson coefficient ranges from
-1.0 to 1.0 and reflects the extent of a linear
relationship between two data sets. - The closer the value is to 1.0 the more a
positive correlation exists.
47Evaluation of Effectiveness for Assessment
- Given that the alternative hypothesis is for a
positive correlation, an upper-tail rejection
region, RR z gt za, was used. - The value a is the probability of a Type I error
and is called the significance level. - A Type I error is made if the null hypothesis is
rejected when in fact the null hypothesis is
true. -
48Evaluation of Effectiveness for Assessment
- We report what is called the p-value or the
attained significance level. - The p-value is the smallest level of
significance, a, for which the observed data
indicates that the null hypothesis should be
rejected. -
49Evaluation of Effectiveness for Assessment
Study One Experiments Study One Experiments Study One Experiments Study Two Experiments Study Two Experiments Study Two Experiments
I II III I II III
Correlation .538 .781 .782 .534 .900 .632
P-value 0.025 lt a lt 0.05 a lt 0.005 a lt 0.005 0.025 lt a lt 0.05 a lt 0.005 0.01 lt a lt 0.025
50Evaluation of Effectiveness for Assessment
- These p-values clearly indicate that the null
hypothesis should be rejected in all six
experiments. - In all the experiments the p-value is less than
the common guideline of 0.05. In fact for three
of the cases, the p-value is even less than
0.005. - Thus, the alternative hypothesis that a positive
correlation exists is accepted. -
51Evaluation of Effectiveness for Assessment
- Current Study
- On a test give the student an English description
and have the student write the Java program
fragment and the sequence of memory diagrams - Determine the correlation between the two scores
52Conclusion Memory Diagrams
- A relatively low-tech approach for teaching OO
concepts - Well-suited for classroom, labs, exams
- Importance of shape and placement for reinforcing
concepts - Having students make their own diagrams adds to
this reinforcement - Promise of diagrams for measuring comprehension
- If students can diagram what is happening in
memory, they are probably understanding the
deeper meaning of the program - Measured assessment effectiveness relative to
rest of test and course score - Currently measuring assessment effectiveness
compared to corresponding Java program fragment
53Conclusion Memory Diagrams
- To learn more
- Mark A. Holliday and David Luginbuhl, Using
Memory Diagrams When Teaching a Java-Based CS1,
Proc. of the 41st ACM Southeast Conference,
Savannah, GA, March 2003. - Mark A. Holliday and David Luginbuhl, CS1
Assessment Using Memory Diagrams, submitted for
publication, - Mark A. Holliday, Introducing Java Using Memory
Diagrams, unpublished manuscript (CS150 lecture
notes) http//cs.wcu.edu/holliday/LectureNotes/1
50/lectures.html - Presentation slides http//cs.wcu/edu/holliday/