CSC 222: Object-Oriented Programming
Test 1 Review
Note: Test 1 only covers material through the lecture on Simulation & Libraries.
In particular, ArrrayLists and file I/O will not be covered on Test 1.
Object-oriented design goals
abstraction: ignore details to focus attention on higher level of problem
object-focused: identify the objects in the real-world system & model each
with a class
modularization: design each class/method to be well-defined & self-contained,
so that they can be built/examined separately & reused easily
Java classes
using classes
loading a BlueJ project, creating an object, inspecting an object's state
calling a method, parameters, return values
defining/examining classes
fields: maintain the state of an object
access using this. prefix
can be static (shared by class) and/or final (unchangeable)
constructor(s): initialize the fields for a newly created object
methods: implement the behaviors of the method
accessor method returns a field value; mutator method changes field(s)
can define local variables for temporary values
must specify return type (void if no return)
class/constructor/methods are (usually) public; fields are (usually) private
comments (/** ... */ or // ..) are for documentation
Java statements
assignment statements
data types (String, int, double, char, boolean)
variables, expressions (+, -, *, *, %)
arithmetic assignments: +=, -=, *=, /=, ++, --
primitive types vs. object types (using new)
variable scope (field = entire class; parameter/local = that method only)
output statements
System.out.print, System.out.println
return statements
conditional statements
1-way: if; 2-way: if-else; multi-way: cascading if-else
comparison operators: ==, !=, <, >, <=, >= (danger: = vs. ==)
logical connectives: && (AND), || (OR), ! (NOT)
repetition statements
while: conditional repetition
for: counter-driven repetition (shorthand version of while loop)
method calls
internal call: this.METHOD(PARAMETERS)
external call: OBJECT.METHOD(PARAMETERS)
Java library classes
String
implicit call to new when assigning, immutable
methods: length, charAt, contains, indexOf, substring, toUpperCase,
toLowerCase, equals, compareTo, ...
Character
static methods: toUpperCase, toLowerCase, isLetter, isUpperCase, isLowerCase, ...
Integer
static method: parseInt
Random
methods: nextInt, nextDouble, ...