CS100A, Fall 1998
After discussing the notion of an algorithm and (computer) program briefly, the first lecture will introduce method calls, since method calls are mandatory when doing any I/O or graphics and since they are one of the most frequently used statements.
First, we will discuss the heading of a method --the precise comment that specifies what the method does, prefix modifiers, name, and parameters. Throughout, the need for a precise specification will be emphasized, for without a precise specification, one can’t easily tell what the method does. Then, we will discuss method calls (invocations), using a substitution semantics: the method call does what the specification of the method says, but with parameters replaced by arguments of the call.
We will discuss the fact that THEY (the students) could execute something like drawOval(5,5,4,3), if given the right color crayon and the graph paper on which to draw it. Something like drawOval(5,5,4,3) is simply shorthand for the comment of the method, with the parameters replaced by the arguments.
We will illustrate this on the computer, using a small program that draws circles/squares and titles for them in a window. We will also step through execution of the program using the debugger, so they get the idea of sequential execution.
A nice feature of using the debugger for this is that we can show what happens when the Drawing window is first covered by another window and then uncovered by moving the other window away: the Drawing window is now all messed up --but the system calls method paint in order to redraw that window! Thus, the students get a bit of a feel for what is going on behind the scenes when they move windows around.
Necessarily, we will also mention integer arithmetic, but weleave a full explanation of integer expressions to the first section.
We will explain carefully that many parts of a Java program will not be understandable at this point --prefix modifiers, classes, the “g.” on “g.drawOval(…)”, and so forth. These will all become clearer as the course progresses.