CS 121 Final Review Sheet NOTE: This is not an exhaustive list of things on the final, just a reminder of some of the concepts that may be on the final. All of the information from the midterm is fair game, though some of this information will be covered on this review as well as the old review as it is relevant to both halves of the course 1) Declarations and Assignments * Know how to declare both variables that have primitive data types (double, int, boolean, char) and user defined data types (i.e. classes) * Know how to declare legal variable names for all types of variables and to assign legal values to them. * Know how to use final and static variables * Know how to use the this keyword 2) while Loops and switch statements * Know how to use a while loop and to convert between for loops, for each loops and while loops * Know how to write a do-while loop * Know how to use a switch statement and the fact that cases "fall through" without using the break keyword * Know how to use the break keyword during looping 3) Wrapper Classes * Know how to use a wrapper class to convert Strings into primitive data types String some_number = "1979"; int some_int = Integer.parseInt(some_number); 4) Arrays * Know how to get the length of an array, and know that this is not the same as getting the length of a String * Know how to declare and assign arrays of both primitive data and objects * Know to assign values to an array with brace notation * Know how to loop through an array using a for loop, a for-each loop and a while loop * Know that array indices start at 0, not 1 5) Inheritance * Be able to write a complete subclass that extends an existing class * Know the use of the super keyword in the context of both constructors and other methods * Know how to use methods from a superclass in a subclass * Know that every class in Java automatically extends type Object * Know that objects declared as a subclass type can be assigned to objects declared as a superclass type String s = "this is some text"; Object o = new Scanner(s); * Know that the same goes for interfaces Comparable c = new Integer(k); * Know that to go the opposite direction requires casting String s = "this is some text"; Object o = new Scanner(s); String word = (Scanner)o.next(); * Know how to define an interface * Know how to write a class that implements an interface * Know that it might be a good idea to have a separate class in which to implement static methods that do operations on all objects of classes that implement an interface (see below example) * Know how to define a method that exploits an interface to do something to objects of many different types (i.e. all of the classes that implement the interface) public class maxFunctions{ //contains methods that find the max of objects of classes that implement the Comparable interface public static int max(Comparable[] compArray){ //returns index of maximum entry in compArray int best_index = 0; for(int i = 1; i < compArray.length; i++){ if(compArray[i].compareTo(compArray[best_index]) == 1) best_index = i; } return i; } } 6) Exceptions * Know how to use the throws keyword * Know how to use try / catch * Know that all exceptions extend the class Exception 7) File I/O * Know how to use a FileReader object to read text files * Know how to use a PrintWriter object to write text files * Know that file i/o operations throw an IOException and how to handle this exception through throws and try/catch 8) Graphics * Know that certain graphics method are only called by the graphics manager, and are not supposed to be called directly by the programmer ( like paint() ) * Know how to use the ActionListener/EventListener interface (i.e. implement the actionPerformed method and use the addActionListener method ) public class SomePanel extends JPanel implements ActionListener{ JButton q = new JButton("Quit"); public SomePanel(){ this.add(q); q.addActionListener(this); } public void actionPerformed(ActionEvent e){ if(e.getSource() == q) System.exit(0); } }