CS141: Topics for Oct 21, 23, & 25, 2013
Homework and Reading
The reading and homework for this week can be found here: Lab 9
Continue working on TicTacToe. Instructions (pdf)
and TicTacToeStubs Netbeans Project (zip)
Chp 7 Vocabulary
Note, we will not cover everything in this chapter. Your main task is
to become familiar with the code in the Netbeans project:
IOExampleProject (zip file)
If you had to modify it to read in or write to a file, would you know how to change the program?
File
Ascii (text) file vs binary file
Opening a file
Closing a file
White space
|
Exception
Throwing an Exception
Catching an Exception
try-catch
Delimiter
|
Topics: Chp 7 - Input/Output and Exception Handling
- Reading ascii text files using the Scanner and File classes
- Writing to ascii text files using the PrintWriter class
- Opening and closing
- Binary data (anything other than ascii, e.g. images) - can't be represented on a console
- Checking for more data using in.hasNextInt(), in.hasNextDouble(). These return a boolean value.
- Reading words (tokens) vs lines using next()
- Converting Strings to numbers, e.g. using Double.parseDouble, Integer.parseInt()
- Exception Handling; Dealing with errors; How to gracefully survive a crash.
- Throwing an exception
- Catching an exception; Catching multiple exception types
- Types of Exceptions - see Javadoc for the Exception class
- The finally clause - cleaning up no matter what happens, e.g. closing a file
- Sample Netbeans project showing how to read and write files:
IOExampleProject (zip file)
Chp 8 Vocabulary
Object-oriented programming
Encapsulation
Public interface
Private implementation
Class
Object (instance of class)
Member (instance) variable
Instance method
Constructor
The keyword: new
Object reference
Null reference
|
Mutator method (setter)
Accessor method (getter)
toString method
Sending a message
Overloading
Class (static) method
Class (static) variables
Modifier (public, private)
this reference
Unit testing
|
Topics: Chp 8 - Objects and Classes
- Motivation of Classes and Objects: Organizing and structuring code to promote reusability, readability, and correctness
- Encapsulation: Separating the public interface from the private (hidden) implementation
- Class vs Object Analogies: script vs actor, cookie recipe vs the cookie itself
- Examples: Die class, Card class
- Components of a Class (also see categories):
- Data:
- Member (instance) variables (one for each object)
- Class (static) variables (one for all objects)
- Actions:
- Public interface (public methods)
- Common for most classes:
- Access to data: Mutators and Accessors (also called getters and setters)
- Handy Utilities: toString
- Creation: Constructor
- Public methods for a specific class (e.g. In the Die class, one might have a roll() method)
- Private Implementation:
- Data hiding: data is usually private. Use accessors & mutators instead.
- private methods - not accesible from outside of the class.
- Working with Objects
- Creating an object using the keyword
new
and a constructor
- Object references
- Objects as method parameters and return types: Pass by Reference (not Pass by Value)
*** Recall discussion with arrays
- The
null
keyword and Null Pointer Exceptions
- Testing your code.
- Sending an object a message using the public interface. (calling a method)
- Self referencing using the keyword
this
- Overloading: Methods with he same name but different signatures (headers)
- Class (static) methods and variables - class methods can only access class variables
In Class Practice Activities