Lecture 4 – September 4th , 2008

 

In today's lecture we confirmed that the final will be held on December 10th, Wednesday, in ISAT/CS 236 at 7pm.

 

I expect that you will read through the materials I am posting.  You are responsible for knowing what is in them on quizzes and on tests.

 

In today's lecture we looked at a few of the slides from Tuesday's lecture that had been clarified since then.

 

We mentioned the most likely exceptions that can be avoided:

l                                  attempting to divide by zero

l                                  an array index that is out of bounds

l                                  a specified file that could not be found

l                                  a requested I/O operation that could not be completed normally

l                                  attempting to follow a null reference

 

We looked at slides on IO and Style

 

We looked at the following code examples illustrating the use of try/catch blocks and of opening and reading from files.

ReadFromFile

ReadFromFile2

ReadFromFile3

ReadFromFile4

ReadFromFile5

ReadFromFile6

InputProblem

InputProblemNo

InputProblemAvoided

 

We reviewed the meaning of the word static and the word final.

l          A static method is one that is invoked through its class name, instead of through and object of that class.  (page 199 Lewis, DePasquale, Chase)

l          Variables can be static as well.

l          Local variables are declared inside a method.

l          Instance variables are declared in a class but not inside a method.  The term is used because each instance of the class has its own version of the variable.

l          A static variable sometimes called a class variable is shared among all instances of a class.  There is only one copy of a static variable for all objects of the class. Therefore, changing the value of a static variable i one object changes it for all of the objects of that class.

I have been incorrectly using the term class variable when I should have been using the term instance variable  or class field or class attribute although these terms are not completely standardized.

 

l          A static class member belongs to the class, not objects instantiated from the class

l          An instance method performs an operation on a specific instance of the class.

l          Static fields and static methods belong to the class instead of an instance of a class.

l          Look at the following code from our text: Countable.java

o       Note line 7:  making it private means that the variable cannot be accessed outside the class.

o       Note also: StaticDemo.java from our text uses Countable.java