Exam 2 will take place on Friday, April 11, 2018.
Card c1 = new Card(); // create a random card
Card c2 = new Card(0); // create a card with index 0
System.out.println(c2); // prints: Ace of spades
Die d1 = new Die(); // create a die with 6 sides.
System.out.println(d1); // prints: Die with 6 sides
int r = d1.roll(); // rolls the die object and returns a value from 1 to 6
Die d2 = new Die(12); // create a die with 12 sides.
int r = d2.roll(); // rolls the die object and returns a value from 1 to 12
Person p = new Person("Frank", 18); // create a Person with name Frank and age 18
System.out.println(p); // prints: Frank, age 18
Vocabulary
increment/decrement operators
postfix/prefix modes
flow charts
while-loop (a pretest loop)
for-loop (a pretest loop)
unwinding and hand tracing
do-while-loop (a posttest loop)
nested loop
break and continue statementControl variable, initialization, condition, update; loop body
sentinel value
counter, running total
sum & average: running totals, accumulator
searching for matches
infinite loop
random numbers
Misc Topics
Vocabulary
array (1D, 2D, multi-dimensional)
Declaring an array
Accessing array elements
Initializing an array
Enhanced for-loop
Out of bounds problems
Calculating with arrays:
... comparing, summing, min/max, averages, swap elements
... sequential search, sorting
Arrays class
Arrays as arguments & parameters
Arrays of objects
Selection sort
Binary search
2D Arrays
... declaring
... obtaining number of rows/columns
... accessing elements
... as arguments & parameters
ArrayList class
... Creating and declaring an ArrayList
... Diamond syntax <>
... Auto-boxing/wrapping
Misc Topics
Vocabulary
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
Vocabulary
Static (or class) member variables (fields)
Static (or class) methods
Method signature (name + parameter types)
Comparing objects (.equals)
Copy constructor
Deep vs shallow copying
Topics
Vocabulary
Inheritance, "Is a" relationship (extends keyword)
superclass (or base or parent class)
subclass (or derived or child class)
super()
Object class
Polymorphism
dynamic binding (dynamic method look-up)
Abstract (vs concrete) class
Interfaces (implements keyword)
protected access / package access
inheritance hierarchy
overriding methods (e.g. equals) (not to be confused with overloading)
instanceof operator
comparable interface
Topics
super()
in the first line of constructor
super.method_name()
anywhere in a subclass method.
Employee[] employees = new Employee[3];
employees[0] = new HourlyEmployee();
employees[1] = new SalariedEmployee();
for (int i=0; i < employees.length; i++) {
System.out.println("The employee is " + employees[i].getName() +
" and their pay is " + employees[i].calcPaycheck());
}
public abstract class Employee {
public abstract double calcPaycheck();
...
Must define method in the subclass. Can't create an Employee object; can only create a subclass.
final
so that one can't override a method in the subclass.
Object
instanceof
operator can be used to check what type of object you have. For example, if you need to
cast an object. Should be used sparingly. Don't use as a way to implement different behavior, i.e. to bypass polymorphism.
implements
keyword.