Using Memory Diagrams When Teaching a JavaBased CS

Using Memory Diagrams When Teaching a Java-Based CS 1 Mark A. Holliday David R. Luginbuhl Dept of Mathematics and Computer Science Western Carolina University ACM-SE Conference March 7, 2003 Savannah, GA

Overview § § Motivation and Introduction Diagramming as a teaching tool – – § § Objects, variables, and references Primitive types, fields, visibility, and parameter passing Static fields and methods Arrays Diagramming as an assessment tool Conclusion ACM-SE 3/7/2003

Motivation § Problem: – – § How to help CS 1 students visualize state of computer as Java program executes How to introduce and reinforce object-oriented concepts in an introductory CS course Solution: – Diagrams • – “UML”-like • – Abstraction; visualization UML not primarily focused on state of memory Diagrams used in many textbooks, but without much emphasis ACM-SE 3/7/2003

Criteria § § § Take into account features of language (for us, Java) Visualize state of computer Distinguish between – – – § § Objects: classes: reference variables Reference types: primitive types Private: public Consistency for similar concepts Method invocation and object construction Labels, as appropriate Arrays vs. other objects ACM-SE 3/7/2003
![Memory Diagrams § Similar to other diagrams – – § See, particularly, [WU 2001] Memory Diagrams § Similar to other diagrams – – § See, particularly, [WU 2001]](http://slidetodoc.com/presentation_image_h2/62c410570ffa8492ea6c625444e06bd0/image-5.jpg)
Memory Diagrams § Similar to other diagrams – – § See, particularly, [WU 2001] But with extensions and particular emphases Important aspects – – Shape matters Importance of reference and invocation Indication of values with variables Visibility rules ACM-SE 3/7/2003

Objects, Variables, and References String acolor=“blue”; String fav. Color=a. Color; String other. Color; Features: § Labels on objs and vars § Different shapes § Reference lines begin inside variable ACM-SE a. Color other. Color fav. Color String “blue” 3/7/2003

Method Invocation a. Color = a. Color. concat(other. Color); Features: § Method indicated by line on object – § § Indicates each object has method Method is public Squiggly line indicates invocation New object created New value for a. Color; old value removed ACM-SE a. Color other. Color X () String “blue” “red” concat String “bluered” 3/7/2003

Primitive Types, Fields, Multiple Instances § Primitive type variables have numeric value – § § As opposed to ref types Private fields represented inside object – first Using rectangles indicates fields are just variables associated with objects Different Student objects have same fields with (possibly) different values Student score name 87 second String Student score name 85 “Sue” String “Bob” ACM-SE 3/7/2003

Static fields and methods § Static fields and methods are displayed in a diamond instead of a circle – § Punch clock provides a nice example for static fields and methods See paper for more examples, including passing parameters and diagramming arrays ACM-SE (8) Employee clock 8 16 john advance Employee start end 8 16 3/7/2003

Student Exposure to Diagrams § § We introduce these diagrams to students on the first day of CS 1 class We ask students to produce diagrams of their own – – – § In groupwork In directed lab work On quizzes and tests Bottom line: reinforcement of concepts in a number of contexts – But not just for learning… ACM-SE 3/7/2003

Student Assessment § § By having students use diagrams themselves, we have them demonstrate their comprehension of objectoriented concepts We believe these diagrams have potential for measuring programming comprehension – Anecdotal evidence from several semesters of application ACM-SE 3/7/2003

Example 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. to. String()); // fig d) § Note last line particularly – – – Static public variable (System. out) Method composition Print. Stream object Dog object Creation of a String object ACM-SE 3/7/2003

Results (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(spot. to. String()); // fig d) Figure a 11 correct – 2 labeled rectangle with name of class – § Figure b 4 correct – 2 put “spot” inside var rectangle – 4 didn’t show name field – 2 had more serious errors – § Figure c – all but 1 student correct ACM-SE 3/7/2003

Results (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(spot. to. String()); // fig d) Figure d All but 3 students showed call to to. String() 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 to. String() – • 2 showed the String object – § They got the println() call right But they missed the println() call Summary for this exam – “Decent” correlation between overall grades and grades on diagramming problem ACM-SE 3/7/2003

Summary for Assessment § § We have more work to do We are considering a more rigorous examination of diagramming as a student assessment tool – – Not just to measure progress We hope we can pinpoint problems and provide proper reinforcement of specific concepts ACM-SE 3/7/2003

Conclusion – 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 More work to do ACM-SE 3/7/2003
- Slides: 16