Lecture Notes, Sep 10 * Questions * Check in about installing stuff * Directory on akbar with some software; see Resources on home page * XEmacs as a choice for editing - for either window or mac or unix folks! * setting PATH environment variable in "Control Panels->System->Advanced", add ;C:\jdk1.4.0_01\bin to end of it. (This adds that directory to the places searched for words you type at the prompt.) * A Java program is made up of * Classes, which are made up of... * Variables - a place to put some data, i.e. " Let X be 2. " * Methods - a series of commands that does something to something (That was clear as mud...) which are made up of * Statements - one line commands * Variables * Come in different types, depending on what you're storing * Must be "Declared" - this reserves space in memory * Must have a name. ("The naming of cats is a difficulty matter...") Examples: int i; // Declare an integer named "i" and reserve space for it. // Declare "j" and set it to zero. int j = 0; // NOTE that here "=" is not testing for equivalence! // It is saying "Put the value 0 into the variable named j". int i = 1, j = 3; // You can declare several at once. * Some types (see pg 42) int double boolean // Note that these are all lower case. char // These are "primitive" types, built into the language. which take value like 1 12 2.3 5.6e-3 true false 'a' 'b' '%' * You can assign a variable to something. (Note that statements end with a semi-colon) i = j + k; i = i +1; * Errors: not declaring variable, declaring twice, not initializing (Show examples) * Invoking a method looks like this something = classname.methodname(argument1,argument2); Example: double x,y; y = 4.5; x = Math.sqrt(y); * Input and Output - jumping off the deep end. See javacode/SampleProgram.java , which has several new things * A new type : String * A new statement: import, which reads in other classes * Several new classes and methods of those classes SimpleIO.prompt SimpleIO.readLine Convert.toDouble (Remember, each of these is className.methodName) * A new meaning of "+", namely to append something to a string (Actually does a conversion to string, too.) * The backslash does something special to the next character in a string: "This \n is \n\n what?" See pg 59 * Debugging: take the comments on pg 71 to heart. When it isn't working, some rules of debugging are (1) Never assume anything. (2) Check everything, with lots of extra println() statements to watch it work. (3) Comment things out until you get a program sparse enough that it runs, then add things back in a bit at time. (4) Stare at the code hard. Real hard. (5) When all else fails, bail and email me the code. (mahoney@marlboro.edu) * That's plenty for today...