Section 2, Thu July 3 Goals: - Review homework 1 - Review material introduced in lecture - Discuss homework 2 - Continue talking about the development process (1) Agenda -> Homework 1 - Lecture review - Homework 2 - Working with code (2) Homework 1 - Solutions distributed in lecture - Coding question UWPerson p = new UWPerson("Sigurdsson", "Stefan", "stebbi"); - Written assignment - Model, properties, responsibilities - Class, member variables, methods - Questions? (3) Lecture review From last week: - Modeling - Objects - Properties - Property types - Property values - Object state - Responsibilities - Object relationships - Object design - An object has a value for each property - Properties are typed - Values must match the property types - The state of an object is the combination of its values New concepts: - Invoke object responsibilities by sending messages - Queries - Commands - Classes are implementations of models in Java - In Java, objects are instances of classes - Two separate but identical objects of the same class *are different* - Boxes and bubbles; graphical notation for classes and objects - Object types are either rich or simple - The type of an object is its class - The int type is our first simple type - All classes are rich types - Instance variables - Methods - Constructors - Specification vs. implementation - Class definitions - Class name - The class keyword - "public" was not discussed in lecture - Class implementations - Surrounded by curly braces {} - Identifiers and keywords - Class and property identifiers -> use nouns - Method identifiers -> verb-based - Capitalization convention - Method specification - "public" not discussed yet - Return type; the void keyword - Return statement - Parameters - Statement - Expression - Composing methods from statements and expressions - Arithmetic operators/expressions - Assignment expressions/statements - Variables and values; binding - Constructor syntax (4) Homework 2 Questions to consider: - What is the relation between - Models, objects, classes, class instances? - Properties, types, values, member variables, state? - Method parameters, member variables, local variables? - What is a variable assignment? - What are the Java class libraries? - What is a method return type? - What is the signature of a method? - What is the difference between a method returning a value, and a program printing to the console output? (5) Homework 2 - Questions about the PetSet and beastie code? (6) Working with code - Overview - Review from last week's section - New concepts: Libraries, API documentation - Coding example; the MutableString class (7) Working with code - Process overview 1 Run development environment 2 Write source code in editor 3 Save source files 4 Compile all source to create class files 5 Run the class file with the main method 6 Loop back to step 2 as necessary (8) Libraries - Libraries are code written by others and useful to you - The code is usually not available - Instead documentation is made available - The standard Java class libraries are documented on-line at http://java.sun.com/docs/api/ - API means Application Programming Interface (The String class illustrates library use in the running example) http://java.sun.com/j2se/1.4.1/docs/api/ -> java.lang.String (9) Testing - The compiler detects syntax errors - Semantic errors are not detected by the compiler - You need to test your program to ascertain that it works as intended - The interactions pane is very useful for testing (10) Debugging - If testing reveals flaws in the program you need to find and fix them - This process is called debugging - Eniac story - If you don't learn how to test and debug you will not enjoy this course - Debugging is a main subject of next week's section (11) Working with Code - Updated process overview 1 Run development environment 2 Write source code in editor Use libraries as much as you can 3 Save and compile 4 Run the class with the main method *or* test and debug using the interactions pane 6 Loop back to step 2 as necessary