530 likes | 781 Views
Using 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. Overview.
E N D
Using 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
Overview • 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 UNCA-CS
Motivation • 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 UNCA-CS
Relationship 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. UNCA-CS
Goals 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 UNCA-CS
Object-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) UNCA-CS
Object-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 UNCA-CS
Language 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. UNCA-CS
Language 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. UNCA-CS
Language Design Principles • Use shape to reinforce when concepts are the same • Use shape to reinforce when concepts differ • Use position to reinforce concepts UNCA-CS
Relationship 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 UNCA-CS
aColor favColor Objects, 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!) UNCA-CS
aColor favColor Objects, 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) UNCA-CS
aColor favColor Objects, 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) UNCA-CS
Objects, 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) UNCA-CS
Method 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) UNCA-CS
Method 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) UNCA-CS
Method 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) UNCA-CS
Method 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) UNCA-CS
first second Primitive 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” UNCA-CS
john Static 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 UNCA-CS
Static 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 UNCA-CS
Parameter 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 > other.odometer; … // rectangle for variable other is // actually shown next to // the parameter declaration // in the method header UNCA-CS
Pass 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 UNCA-CS
Pass 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 UNCA-CS
Method Cascading String first = “Blue”; String second = “Green”; String third = “Red”: String last; last = first.concat(second).concat( third); // last is “BlueGreenRed” UNCA-CS
Method Cascading UNCA-CS
Method 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” UNCA-CS
Method Composition UNCA-CS
Language 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) UNCA-CS
Language 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) UNCA-CS
Language 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. UNCA-CS
Student 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 UNCA-CS
Student 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) UNCA-CS
Student 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… UNCA-CS
Student 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 UNCA-CS
Example 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 UNCA-CS
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) Results(13 students) • Figure a • 11 correct • 2 labeled rectanglewith name of class • Figure b • 4 correct • 2 put “spot” inside var rectangle • 4 didn’t show name field • 3 had more serious errors • Figure c – all but 1 student correct UNCA-CS
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) Results(13 students) • 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 UNCA-CS
Evaluation 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? UNCA-CS
Evaluation 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) UNCA-CS
Evaluation 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 UNCA-CS
Evaluation 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. UNCA-CS
Evaluation 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. UNCA-CS
Evaluation of Effectiveness for Assessment • Given that the alternative hypothesis is for a positive correlation, an upper-tail rejection region, RR = {z > zα}, was used. • The value α 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. UNCA-CS
Evaluation 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, α, for which the observed data indicates that the null hypothesis should be rejected. UNCA-CS
Evaluation 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. UNCA-CS