CSE 115 1st EditionFinal Exam Study Guide Lecture 16 3/30- Static variables o Belong to a class, not an object- Realizationo public class EventHandler implements ActionListener {}Lecture 17 4/6- Data Structureso HashMap <Key, Value>o Collection Framework Collection<E> interface ArrayList<E> class HashSet<E> class- Control Structureso Foreach statemento While statement o If statement- Collectionso A collection object can store arbitrarily many references to objectso java.util.Collection<E> interface Collection class is defined in here boolean add(E item) boolean remove(Object item) boolean contains(Object item) int size()o <E> Type variable- Collection<String> denotes a collection of String objects- Collection<ActionListener> denotes collection of ActionListeners o 2 Specific Collections ArrayList<E>- Permits duplicates- Allows client to control order of elements These notes represent a detailed interpretation of the professor’s lecture. GradeBuddy is best used as a supplement to your own notes, not as a substitute.- Not declared as an instance variable HashSet<E>- Does not permit duplicates- Does not allow client to control order of elements- Ex: Records students from CSE 115, 241, and 191, but it does not enter duplicate studentso Declare and Assign HashSet<String> names = new HashSet<>(); Add/Remove- names.add(“Fred”);- names.remove(“Fred”):- HashMap<Key,Value>o Not a collection class*o Provides mapping from Key to Valueo put(Key,Value)o containsKey(Key)o get(Key)Lecture 17 4/8- Control Structureso Conditional statements (selection) If else Ifo Loop statements (repetitions) Foreach (enhanced for loop) While Foro If else If <expr> is true perform <stmt1> if not perform <stmt2> then exit loopo If If <expr> is true perform <stmt> if not then exit loopo While While <expr> is true perform <stmt> increment/decrement until <expr> is false then exit loopo Foreach For (<type> <identifier>: <collection>){<stmt>;} Ex: for(String s: names) {System.out.println(“Name is” +s);}Lecture 18 4/15- Iterator Method of Collectiono Collection<E> has this method public Iterator<E> iterator() returns an iterator over every element in the collection guarantees to visit every element in the collection exactly once - public boolean has Next()o return true if it has not visited every elemento return false if it has visited every element- public E Next()o returns one of the unvisited values- Syntactic Sugaro Foreach loop is syntactic sugar Adds convenience, but doesn’t add any argument to the language Prior to Java 5 there was no foreach loop- Inheritanceo Relationship between 2 classes 2 interfaceso Reduces “code smell” (code duplication)o Syntactically simpleo Conceptually messy- Class to Class Inheritanceo Instead of having 2 classes implementing a Noisy interface, change the Noisy interface toan abstract class Has abstract methods Cant be instantiated public abstract class Noisy() {} public class Cat extends Noisy {} public class Dog extends Noisy {} Abstract class can contains concrete and abstract methods* Interface only has abstract methods (implicit)Lecture 19 4/17- Inheritance o “extends”o Source class Subclass Child class Derived classo Target class Superclass Parent class Base classo Implications of “extends” Same type implications as interfaces- Instances of subclass belong to subclass type and superclass type Non-private member of the superclass can be accessed via subclass object - It’s as if the methods in the superclass are defined in the subclass (inherited method) Eliminates duplicate code (Pull Up Method) CatString sound()Cat(String n) 1.o public abstract class Noisy {DogString sound()Dog (String n)NoisyString _myNameNoisy(String n)String getName()String sound()private String _myName;public Noisy(String name){_myName = name;}public abstract String sound();public String getName(){return _myName;}} 2.o public class Cat extends Noisy {public Cat(String n) {super(n);}} 3.o public class Dog extends Noisy {public Dog(String n) {Super(n); {}}- Object Classo Predefined class in languageo Object doesn’t extend any class and it’s the only class that doesn’t have a parent classo Any class (other than Object) which doesn’t have an explicit “extends” clause in its header extends Object by default o Interface Inheritanceo Interface can extend 0 or more interfaces 0 interfaces- public interface A {public void foo();} 1 interface- public interface B extends A {public void bar();} many interfaces- public interface C extends B, ActionListener {public ActionEvent getEvent();}Lecture 20 4/20- Overridingo Complete overriding When a subclass provides a new definition for a method that would’ve been inherited from the superclasso Partial override When a subclass provides a definition for a method that would’ve been inherited from the superclass, but calls the method via super() - Lets the method compute adds changes- Object Layout in Memoryo Object class, A class implicitly extending Object, B class explicitly extending A Memory for Object B is allocated for each part of Object B (Object part, A part, Bpart) - Default Constructoro If no explicit constructor is defined, the compiler provides one public A {public A () {super();}}Lecture 21 4/22- Constructor Calls and Inheritanceo The constructor of the parent class is always called before any of the child class constructorso Runtime Stack- when Object constructor is done compiling it’s removed, when A is done it’s removed, when B is done it’s removed, when C is done it’s removedC()B()A()Object()o MemoryObjectABC- Primitive Types in Javao 8 types Boolean Integral- Signed: long, int, short, byte- Unsigned: char Floating point- Double, floato Value of types are NOT objects No properties No capabilitieso Int Negative and positive integers Operations: +, -, *, /, %o Integral types’ representation Signed values = “two’s complement” representation Unsigned values = “binary” representationo Two’s complement Fixed-width encoding Encodes a limited range of values Encodes negative and non-negative values Familiar arithmetic properties hold- 0 = -0- x + 0 = 0 + x = x- x = -(-x)- x + (-x) = 0- x – y = x + (-y)Lecture 22 4/24- Bit Pattern Interpretationo Half of bit patterns (those with a zero in
View Full Document