CSC152 2005F, Class 22: About Exam 2 Admin: * Exams returned * No homework * Changes to syllabus Overview: * General reactions Distribution 90+ 80-90 60-80 60- Expect 40% 40% 10% 10% This yr 3 3 0 8 Last year about 100: 30% about 80: 30% about 60: 30% Solution: * Start again, but move really quickly (Five weeks in four days) i Java is imperative and object-oriented * Imperative: Focus on operations that store and retrieve values and on sequencing those operations * Object-oriented: In the context of "objects" * Objects collect data * Objects 'do things' * Descriptions of 'do things' is imperative E.g., (1) look up your current value (2) look up a value associated with a peer (3) combine them (4) update your value * Values in Java are 'typed' and must be declared * Typical programs begin with a main class which includes a main method public class CLASSNAME { public static void main(String[] args) throws Exception { // SEQUENCE OF INSTRUCTIONS TO BUILD OBJECTS } // main(String[]) } // class CLASSNAME Note: Definitions of how new kinds of objects behave is outside the scope ofthe main class. The main class simply arranges everything and sets it in motion. Sample sequences of operations * Declare names TYPE NAME; or TYPE NAME = INITIAL_VALUE; TeachingAssistant heyyou; TeachingAssistant heyyour = new TeachingAssistant("took csc152"; "extroverted"; "less obnoxious than sam, but not much"); Point pt; Point pt = new Point(1,2); * For most complex types, the most natural way to construct is with new NAMEOFTYPE(values-to-help-you-initialize) * For some, there are other ways to build them, too. * For "primitive" types, don't use the keyword "new" int i; int i = 3; * The primitive types are: int, short, byte, char, double, float, long, boolean * Strings are a special case; somewhat primitive, somewhat complex. You can write both String str = "Hello"; Strinb rts = new String("Hello"); * Second key operation: "Assignment" NAME = EXPRESSION; i = i + 5; When working with primitive types, most operations are symbolic and written in "infix" or "prefix" notation When working with complext types (objects), most operations are alphanumeric and they are typically written OBJECTNAME.OPERATION(PARAMETERS) heyyou.throwSomethingAt(sam); // Whoever has defined "TeachingAssistant" needs to specify // how throwSomethingAt works and what effects, if any, it has // on the base object and on the parameter object. Point newpoint; newpoint = pt.translate(10,22); // Translate does not affect the original point. Instead, // it creates a new point. Terminology: When we write OBJECTNAME.OPERATIO(PARAMETERS), the OPERATION is a "method". (Also "procedure", "function") See ProgramOne.java for a *very* simple program. Assignment: Write a program that helps you verify that you understand input, output, main class, and such.