//****************************************************// //***********Test 3 Review - November 14th, 2016*****// //**************************************************// -"The real reason you get a PhD is to get 5 professors gathered in the same place at the same time - which is an NP problem, by the way" -Prof. Simpkins -Fact: In the military, sometimes the instructor would "stomp their feet" in order to note that something is particularly important...so, possibly pay attention the next time I randomly stomp. ------------------------------------------- -So, we'll be going over Chapter 3 - the test will be here on Wednesday, usual place, usual time. You know the drill! -Exceptions are classes, just like any other, that have super classes - they're a great example of OOP as well as the standard library, which makes them great for teaching -REMEMBER THE HIERARCHY: "Throwable" is a subclass of Object, "Exception" extends "Throwable," etc. -SO, the highest superclass of an exception is NOT "Throwable" - IT'S OBJECT! "Throwable" is the highest type of exception, however -Remember, THROWABLE IS INSTANTIABLE - it's NOT abstract! -Remember the difference between Checked vs Unchecked exceptions -Unchecked are exceptions that happen at runtime, and DON'T need to be thrown/ put in a try-catch statement -Checked exceptions NEED to be either thrown or caught - the "catch-or-declare" rule - or the compiler will throw a fit -ANY method, including mains, can throw an exception - but if an exception isn't caught by the time it reaches the JVM (outside of "main"), it prints out the exception's error message / "stack trace" and then terminates the program -RANDOM REMEMBERANCE: "Liskov Substitution Principle" - you should be able to use a subclass wherever it's superclass is used -THIS IS BROKEN if you try to say that you're throwing a checked exception when you're actually throwing an unchecked exception -"Not 100% sure about this now - many people (not quite most) are moving away from exceptions where possible, and modern languages have been using them less and less", due to try-catch statements making code more complex, being harder to read, occasionally causing scope issues, etc. ~Simpkins -Example: At Google, Exceptions are NOT allowed to be used for certain languages (most notably C++, where exceptions are notoriously fiddly) -THROWS vs THROW - "throw" is used INSIDE of the method to throw an exception, "throws" is used in a method header -"throw" will immediately stop the method in its track if it executes - control will go to the "catch" block -FOR FIRST EXCEPTION EXAMPLE QUESTION: 3 is wrong since A doesn't extend B, yet is thrown, BUT 2 WILL COMPILE, since C is a runtime exception, meaning the compiler won't check what we're throwing (VERIFY THIS) -If you declare that a method throws an exception, Java DOESN'T check to see if anything will actually ever be thrown -"if (true)" statements necessary to make it compilable, as otherwise, Java would freak out about never being able to reach the return statements -COLLECTIONS - these are all INTERFACES, NOT CLASSES! -"Iterable" is the interface with an "Iterator<>" interface inside; DOUBLE CHECK HOW THIS IS IMPLEMENTED -Know that "Iterable<E>" and "Iterator<E>" BOTH have to be implemented -Iterators are most commonly used to traverse a collection -ESSENTIAL because they abstract getting information from a structure away from the structure itself - we don't need to know what the structure itself is in order to get / add something -3 methods: "next", "hasNext," "remove" -"next" ALWAYS calls "hasNext" to check if it's at the end of the array -FOR INNER CLASSES: use "(Inner Class Name).this.(field)" to get a field in the inner class when another method / variable with the same name exists in the outer class -Sets have no duplicate elements and no particular order; could used a HashSet (under-the-cover uses the hashCode() method to remove duplicates), etc. -LOOK OVER ALL REVIEW SLIDES!!!