1 / 53

Using Memory Diagrams When Teaching a Java-Based CS1

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.

kimberly
Download Presentation

Using Memory Diagrams When Teaching a Java-Based CS1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. 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

  3. 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

  4. 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

  5. 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

  6. 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

  7. 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

  8. 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

  9. 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

  10. 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

  11. 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

  12. 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

  13. 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

  14. 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

  15. 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

  16. 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

  17. 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

  18. 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

  19. 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

  20. 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

  21. 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

  22. 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

  23. 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

  24. 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

  25. 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

  26. Method Cascading String first = “Blue”; String second = “Green”; String third = “Red”: String last; last = first.concat(second).concat( third); // last is “BlueGreenRed” UNCA-CS

  27. Method Cascading UNCA-CS

  28. 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

  29. Method Composition UNCA-CS

  30. Two-Dimensional Array (Primitive Base Type) UNCA-CS

  31. Ragged Two-Dimensional Array (Primitive Base Type) UNCA-CS

  32. 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

  33. 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

  34. 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

  35. 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

  36. 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

  37. 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

  38. 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

  39. 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

  40. 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

  41. 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

  42. 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

  43. 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

  44. 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

  45. 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

  46. 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

  47. 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

  48. 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

  49. Evaluation of Effectiveness for Assessment UNCA-CS

  50. 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

More Related