Final Exam Topics Review
- System.out.print() and System.out.println()
- Also used by PrintWriter objects
- Reading input from the keyboard
- keyboard input: System.in
- File input: File object ← may throw an Exception
- methods to read input
- methods to peek at input (hasNextSOMETYPE())
- Declaring and initializing variables
- variableType variableName; ← declaration
- type could be a primitive, could be a provided class from a Java library, could be from a class that you’ve defined
- initialization
- literal: int x = 5;
- using constructor: String str = new String(“Hello”);
- from some method call: MyClass c = createNewMyClass();
- int[][] x = initalizeA2DArray(num);
- difference between primitive and reference types
- primitive types: int, double (numeric), char, boolean
- reference types: reference variables contain reference to object; multiple reference variables can be references to the same object (be careful with the assignment operator!)
- numeric operators (+, -, …)
- augmented assignment operators (+=, …)
- increment(++), decrement(--)
- Math class methods
- static methods
- invoked Math.methodName() ← ClassName.methodName()
- logical operators (!, &&, ||, ^): operate on one or more booleans
- relational operators: operate on two or more non-boolean values = boolean expression
- if, if-else, if-else if-else
- nested if
- switch statements
- char, Character class methods ← static methods
- String class, String methods ← instance methods
- loops
- while, do-while
- for loops
- loop continuation conditions
- counter-controlled loops vs. sentinel-controlled loops
- pretest (for, while), posttest loops (do-while)
- common algorithms: summation, searching
- nested loops
while (!found) {
for (i = 0; i < 10; i++) {
for (j = 0; j < 5; j++) {
found = true
}
}
}
- writing a method header
- return values (make sure to include a return statement when a method returns a value)
- specifying, passing parameters, primitive vs. reference params
- overloading methods
- variable scope
- declaring, initializing arrays
- iterating over the elements of an array
- copying arrays
- searching an array
- Example: OddArrayValues.java
- The Arrays class
- ArrayLists
- data fields
- methods, including constructor(s)
- static vs. instance (non-static)
- public/private/protected (abstract classes--protected can only be used in a subclass)
- this keyword
- instantiate a new object of a particular class
- Example: UsingCars.java
- Casting: CastingExample.java (uses the BankAccount and SavingsAccount classes)
For Wednesday:
- more inheritance and polymorphism
- abstract classes, interfaces
- exceptions
- file I/O
- …
- Examples
Wednesday
- inheritance & polymorphism
- extends keyword; superclass and subclass (extends the superclass)
- super keyword
- when invoking constructor in subclass, first must invoke (explicitly or implicitly: super()) a constructor for the superclass
- abstract class: cannot be instantiated (but can be used as datatypes); abstract methods are only implemented in subclasses
- overriding methods (redefining an inherited method)
- double d = 5.5;
- int i = (int)d;
- Examples: CastingExample.java, checkpoints for ch. 13
- instanceof operator
- Object class: equals(), toString() methods
- interfaces
- implements keyword
- Comparable<E> interface, compareTo() method
- Example: UsingCars.java
- try-catch,
- checked vs. unchecked exceptions
- (re)throwing exceptions
- chained exceptions
- File class
- Reading from files: Scanner class
- Writing to files: PrintWriter class