CSC297.XX (Java), Class 4: Classes and Objects Admin * Homework/demos due * Reminder: Arts weekend * Other useful resource: Experiments in Java http://www.cs.grinnell.edu/~rebelsky/EIJ/ Overview * Reminder: What is an object. * Reminder: What is a class. * Exercise: A point class. * Extensions? Notes on the first homework: * Formatting matters for readability * You can create procedures by using public static RETURN_TYPE NAME(PARAMS) { BODY } * Don't use System.out * Try/Catch only necessary when you are doing things that can explicitly fail. * Save your non-working code so that we can discuss it What is an object? * Something that groups values and functions * Used to help ensure that our programs are "type safe" * Used to "encapsulate" the values, so that you in only access them in 'appropriate" ways (e.g., if you don't want someone to change one of those values, they can't). What is a class? * Collection of objects that have similar functions * Description of common features of certain objects In Java, before you can create an object, you (or someone else) must first create the more generic class Typically five parts to a class (not all necessary) * Object fields/attributes: The key values of the objects; the way two objects differ * Object methods: Instructions by which all objects do similar things. * Object constructors: The instructions for building a new object, given certain parameters. * Class fields/attributes: Values shared by all objects in a class * Class methods: Methods that relate to the objects, but do not require them. Let's create a sample class