Java Midterm Review Chapter 2: -Accessor method (getter method): A method that accesses an object and returns some information and does not change internal data of object on which is invoked -Mutator method: modifies the internal data of an object -Java classes are grouped into packages -Calling methods are used with a dot operator -Void is used when a method has no return value -Object reference: denote the memory location of an object -Mainly about GUI’s Chapter 3: -Instance variables: store data of an object (private typeName variableName;) -Instance of a class: an object of a class -Encapsulation: process of hiding implementation details and providing methods for data access -To encapsulate: declare variable as private and declare public methods to access the variables -implicit parameter: object on which the method is invoked -Explicit parameter: all other parameter variables -Local variable: variable that is declared in the body of a method -Parameter variable: variables that are declared in method headers Chapter 8: Cohesive public interface: refers to a class should only represent a single concept and the concept should be closely related to a single concept Side effect of method: any kind of modification of data that is seen outside the method -Mutator method’s side effect is the modification of implicit parameter All caps usually means that you should use public static final Static: shares memory, makes it the same property if new object is created Java Packages: Set of related classes Packaging classes is convenient to organizes classes but needs to avoid name clashes Use the extend Chapter 9 -Inheritance: relationship between a more general class (superclass) and a more specialized class (called the subclass) -substitution principle: you can always use a subclass object when a superclass object is expected -To implement subclass use the extends keyword -Override: feature that allows a subclass to use the same name as the method from a superclass -Overloading: when two methods have the same name but different parameter types -Polymorphism: Allows you have one interface with multiple implementations(extends) -Override toString(): Used to get a proper output when an object is used in print() or println() -equals method: used to determine if 2 instances are equal -instanceof Operator: used to test whether the object is an instance of the specified type (class or subclass or interface) Chapter 10 -Interface type: used to specify required operations -Inner class: A class that is defined inside another class, can be declared inside an enclosing class, but outside its methods -Event Handling objects -Event listeners: indicates which events it needs to receive by installing event listener -belongs in class provided by application programmer -Methods describe the actions to be taken when an event occurs Event source: User interface component that generates a particular event -add an event listener object to the appropriate event source -Button is created by using a JButton class, JButton button = new JButton (“Add Interest”); -Javax.swing.Timer generates equally spaced timer events, sending events to installed action listeners, useful when you want to have an object updated in regular intervals -Mouse events listener is a component that is added by calling the addMouseListener method -Call repaint is used to tell the component to repaint itself to show rectangle in new position -When mouse is pressed, mouse listener moves rectangle to the mouse location Chapter 11 -Scanner class used to read text files -To read from disk file: -File inputFile = new File(“input.txt”); -Loop to process numbers in the input file: While (in.hasNextDouble() ) { Double value = in.nextDouble(); } -To write a file, construct a PrintWriter object PrintWriter out = new PrintWrite(“output.txt”); -FileNotFoundException -When the input or output file doesn’t exist, a FileNotFoundException can occur -Text Input and Output -next method of the scanner class reads a string that is delimited by white space -delimiter(word separator): to print each word into separate lines, useDelimiter method -White space include: spaces, tab characters, and the newline characters that separate lines -Formatting output types: %d decimal integer, %f fixed floating-point, %e Exponential floatingpoint, %g General floating-point, %s String -Command Line Arguments, is a method used to add extra information for the program to use -useful for automating tasks -program takes in command line arguments, an optional -d flag to indicate decryption instead of encryption, input file name, and output file name -Exception Handling – Throwing Exceptions -Provides a flexible mechanism for passing control from the point of error detection to a handler that can deal with error -When exception is throw, method terminates immediately and the normal control flow is terminated -try statement contains one or more statements that may cause an exception to the kind that you are willing to handle -scanner constructor can throw a FileNotFoundException -Scanner.next can throw a NoSuchElementException -Integer.parseInt can throw a NumberFormatException -Exceptions that you throw and catch can: -Internal errors reported by the type Error -RuntimeException -check exceptions, indicates that something has gone wrong for external reasons -out.close are used to close a resource