1 / 23

Teaching Java —with OO first

Teaching Java —with OO first. David Gries Computer Science Cornell University Ithaca, NY 14850. Michael Caspersen discusses these in his PhD thesis. Approach based on cognitive science, educational psychology, cognitive skill acquisition, research in programming methodology.

nancyslater
Download Presentation

Teaching Java —with OO first

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. Teaching Java —with OO first David Gries Computer Science Cornell University Ithaca, NY 14850

  2. Michael Caspersen discusses these in his PhD thesis.Approach based on cognitive science, educational psychology, cognitive skill acquisition, research in programming methodology. Introduces stepwise improvement. Caspersen, M.E. Educating Novices in the Skills of Programming. PhD Dissertation, Computer Science, Aarhus, Denmark, June 2007. Principle 1. Reveal the programming process, in order to ease and promote the learning of programming. Principle 2.Teach skills, and not just knowledge, in order to promote the learning of programming.

  3. Principle 1. Reveal the programming process, in order to ease and promote the learning of programming. Principle 2.Teach skills, and not just knowledge, in order to promote the learning of programming. Most texts teach programs, not programming. They focus largely on knowledge, not skill. CS people in general put little emphasis on the programming process. Every lecture should deal in some way with the skill of program development.

  4. Kim Bruce. Using abstractions to make concepts concrete. SIGCSE Education Award lecture, 2005. • Peter Denning et al. Computing as a discipline. CACM 1989. • Three major paradigms, or cultural styles, used in CS: • theory • abstraction (modeling) • design Principle 3. Present concepts at the appropriate level of abstraction.

  5. The computer is not the appropriate level of abstraction to describe variables, assignment, and other programming language concepts! "A variable is name for a memory location used to hold a value of some particular data type." "The computer must always know the type of value to be stored in the memory location associated with a variable." "An object reference variable actually stores the address where the object is stored in memory." Principle 3. Present concepts at the appropriate level of abstraction.

  6. The computer is not the appropriate level of abstraction to describe variables, assignment, and other programming language concepts! Computer-centric view: • Can create unnecessary and confusing detail —especially for a novice, who doesn't yet know about much about computers and computing. • Gives the impression that only the computer can execute a program. Principle 3. Present concepts at the appropriate level of abstraction.

  7. Principle 3. Present concepts at the appropriate level of abstraction. The computer is not the appropriate level of abstraction to describe variables, assignment, and other programming language concepts! "An object has its own unique identity, which distinguishes it from all other objects in the computer’s memory … An object’s identity is handled behind the scenes by the Java virtual machine and should not be confused with the variables that might refer to that object."

  8. Algol 60 language definition —CACM, Jan 1963. "The purpose of the algorithmic language is to describe computational processes. … " • "A variable is a designation given to a single value. • Assignment statements serve for assigning the value of an expression to … variable …. The process will be understood to take place in three steps: • 4.2.3.1. Subscript expressions occurring in the left part variable are evaluated in sequence from left to right. • 4.2.3.2. The expression of the statement is evaluated. • 4.2.3.3. The value of the expression is assigned to the left part variable, with any subscript expressions having values as evaluated in step 4.2.3.1."

  9. When teaching Java, principle 3mandates teaching OO first. /** Print "Hello World" */ publicclass FirstClass { publicstatic void main(String[] pars) { System.out.println("Hello World); } } Principle 4. Order the material so as to minimize the introduction of terms or topics without explanation —as much as possible, define a term when you introduce it. Almost every line of a Java program deals with a class or an object!!

  10. Principle 5. Use unambiguous, clear, precise, terminology. Don't use pointer and reference. Novices do not know what they mean. Use inheritance properly.Java version: private components are not inherited.Better version: all components are inherited from the superclass, because they all appear in each object of the subclass. Use parameter – argument, not formal parameter – actual parameter. These sentences from texts completely confuse the issue: “The semantics of an assignment for primitive types and for objects is different.” “When an object is passed to a method, we are actually passing a reference to that object.”

  11. Facilitating the teaching of OO first • An IDE that does not require a Java application —e.g. DrJava or BlueJ. • An appropriate notational machine —model of execution. • Constructive alignment: Course outcomes, teaching/learning activities, and assessment methods are all aligned. • Biweekly quizzes: Students are told exactly what will be on the quiz and are expected to get 100/100 on them. • Closed labs. • One-on-one sessions.

  12. Notational machine • Two aspects: • Structural/organizational —ØØ • Procedural —algorithms, conditionals, loops, arrays, etc. • When teaching Java, principle 3 mandates teaching OO first. • We provide a model for classes and objects that • Can be taught after the students know only about (a) types and expressions, (b) variables, (c) the declaration <type> <variable>; and (d) the assignment statement. • Does not mention the computer. • Is in terms of a concept with which students are already familiar.

  13. Whoever creates the folder gets to decide on the name that goes on the tab. Must be unique! C1 Patient name B. Clinton address New York owes $250.00 A class is a file drawer. It contains manila folders, all having the same kind of information Names that go on tabs of manila folder form a new type. Importance cannot be overestimated. Allows us to eliminate terminology like pointers and references. manila folder: an object or instance of the class

  14. Whoever creates the folder gets to decide on the name that goes on the tab. Must be unique! C1 Patient name B. Clinton address New York owes $250.00 A class is a file drawer. Its manila folder contain the same fields and instructions (methods) getName() { … } Deposit(double) { … } Instructions in folder for people to carry out: methods Function: returns a valueProcedure: does something, does not return a value

  15. C1 Patient name B. Clinton address New York owes $250.00 pat C1 variable contains the name of the folder getName() { … } Deposit(double) { … } pat.getName() function call. Its value is “B. Clinton” pat.deposit(250.0); procedure call. Subtract 250.0 from field owes.

  16. C2 Patient name ? address getName() { … } Deposit(double) { … } ? owes 0.0 C2 m ? C2 variable contains the name of the folder new Patient() An expression: create a new folder (put it in file-drawer Patient) and give as the value of the expression the name of the folder. m= new Patient(); A statement: evaluate new Patient() and store its value (the name of the new folder) in variable m. C2

  17. a0 javax.swing.JFrame show() hide() setTitle(String) getTitle() getHeight() getWidth() setSize(int, int) getX() getY() setLocation(int, int) isResizable() setResizable(boolean) a0 j variable contains the name of the folder A manila folder (object) of class javax.swing.JFrame() Maintains a window on your monitor, with methods(instructions) for manipulating it

  18. a0 a0 j javax.swing.JFrame show() hide() setTitle(String) getTitle() getHeight() getWidth() setSize(int, int) getX() getY() setLocation(int, int) isResizable() setResizable(boolean) variable contains the name of the folder SquareJFrame area() {…} setHeightToWidth() { …} Drawing a folder (object) for a subclass. Students learn how to draw such folders. It is important for later understanding that they know that the complete method resides in the folder.

  19. a0 a1 JFrame JFrame … area() … … area() … SquareJFrame SquareJFrame a1 a0 j a1 k Assignment is seen to follow the normal rules for an assignment: To execute j= k; evaluate expression k (gives the value a1) and store its value in j.

  20. Model helps, right from the beginning • Students understand what an object is, right from the beginning. The explanation is not in terms of a computer. • The pictorial nature of the model is important. The name on the tab is most important. Our students learn to draw objects for subclasses, and they use it later to learn various concepts (inheritance, overriding, the inside-out rule for determining what declaration a method call or variable refers to. • Pointer and reference are not used. • UML diagrams are inadequate because they do not have the equivalent of the name on the tab of an object. Although it would be easy to extend UML diagrams for objects to include it.

  21. i Inside-out rule: To determine to which variable declaration a variable reference refers, search in the current scope, the enclosing scope, its enclosing scope, etc. until it is found. (Similar rule for method declarations and calls.) a1 v 2 C SC w 4 m(int p) { int lv; while ( … ) { int n; … sv … n } } sv m() { …} 5 SC's file drawer Inside-out rule used in just about every programming language and in predicate logic:

  22. Closed labs, after lectures 1, 3, 5, …, give practice with concepts. Lecture 1.Types, expressions, variables, assignments Lecture 2. Objects Lecture 3. Class def. Subclass of JFrame with 2 methods Lecture 4. Fields, getter/setter methods. Junit testing Lecture 5. Class hierarchy. Static variables Lecture 6.Methods; method bodies; local variables; if-statement Lecture 7. Super-this; inside-out rule. Stepwise refinement Lecture 8.Overriding; constructors in subclasses Stepwise refinement Lecture 9 and 10. Recursion Lecture 11. Casting about; instanceof Lecture 12.Loops

  23. David and Paul Gries. A Multimedia Introduction to Programming Using Java. Springer Verlag, NY 2005. Comes with a CS that has 250-odd 2-5 minute lectures with synched animation. Here, we can really concentrate on program development. Webpage for last Spring's course. http://www.cs.cornell.edu/courses/cs100j/2007sp/ You can get slides of lectures and labs, assignments, etc.

More Related