Java -- OOP (c++,objectiveC,SmallTalk,...) A java program is a bunch of "classes" - class ~ type of object (eg Bug, 2DWorld, ...) subclass of some other class inherit instance variables & methods of the superclass - create instances (objects) of this type send instances "messages" to tell them to do things message -> method defined in class parameters must match! (number,data type) - instance variables: store state of instance idealTemperature, outputHeat, ... - methods: what the objects can do Ex: bug.step() getIdealTemp(); setIdealTemp(200); - methods do things by: - sending messages to other objects to ask them to do things! - the usual programming constructs, eg: instance variables class variables local variables method parameters variable types: primitive: int double float ... reference: pointers to objects! Double Bug Agent ... if ( expression ) { do some stuff if expression is true } else { do some stuff if not true } while ( expression ) { ... } for ( int i = 0; i <= maxI; ++i ) { ... } - Classes can be from: - Standard Java libraries (*lots* of useful things) - RePast libraries - Other 3rd party libraries (*lots* of these) - Your own program (and/or libraries) *** A Few Programming Tips **** - Case matters. - You have to define variables. To be used, a variable must be "in scope": - class variable usable anywhere in class always the same value for all instances - instance variable usable anywhere in class may be different values for each instance - method parameter accessible only in that method - local variable accessible only from it definition to end of enclosing block (pair of { ... } ) - The compiler is very very seldom wrong... Look for errors starting at the first method mentioned from your program Look for errors from line mentioned and then go backwards in program (error may be many lines before that!) - COMMENTS -- write them *before* you write the methods! - use it to think thru what it should do - use it as outline to guide the coding - if you don't do it then, you never will!! (and you'll be sorry later...) - Self-documenting programs: - variable names, method names that say what they are or do! - Pick a standard "style" and ALWAYS USE IT!!! Make it habitual. - indentation - case of variables, methods - horizontal, vertical space => emacs and other tools help: auto-indent, etc. - Write short methods -- fit on one screen! If you need something longer, put some of it into another method! - Start *very* simple, get something running, then add to it. DO NOT TRY TO WRITE IT ALL AT ONCE, then compile it. You will just have a zillion errors...hard to debug, and depressing! - avoid embedded constants. Use symbolic names. public static final int HOT = 0;