//beyond basics... //Note: The information provided here will NOT be in exam exception: An exception is an event that occurs during the execution of a program that disrupts the normal flow of instructions. Example? //we can write more robost program! instead of crashing, we catch exception and //handle them try{ //eg open a file and read its content } catch (IOExecption e){ //do somthing } //we can also throw (our own) exception! throw new IOException("Cannot find file!") //Concrete vs Abstract Classes //Often there is not enough info to implement some methods in a supper class and more specific //info in child is needed. We can make such methods abstract in the supper class. Then //provide various implmentations in each child. The super class then will be an abstract class //We cannot create an object of abstract class!, why? //interface: Java does not allow multiple inheritance for classes (ie. a subclass being the extension of more than one superclass). To tie elements of different classes together Java uses an interface. Interfaces are similar to abstract classes but all methods are abstract and all properties are static final. When you create a class that uses an interface, you reference the interface with the reserved word "implements" Interface_list. Interface_list is one or more interfaces as multiple interfaces are allowed. Any class that implements an interface must include code for all methods in the interface. Advanced Data structures: arraylist: dynamic Lists (LinkedList) in java collections and iterators queue/stack/priority queue, tree, etc recursion: a method that calls itself! Example: Merge Sort: a= 1 5 3 8 10 2 9 20 11 //break into two lists b and c b= 1 5 3 8 10 and c=2 9 20 11 sort b and c: b= 1 3 5 8 10 and c= 2 9 11 20 now merge two sorted lists: 1 2 3 5 8 9 10 11 20 //algorithm: mergeSort(a){ break a into equal size b and c mergeSort(b) //sort b (notice the name mergeSort!) mergeSort(c) //sort c return merge(b,c) //merge two sorted array } This is very fast N*log(N) compared to N^2 we have seen before. Applet: running your code in browser. Portable, any platform, anywhere! Very easy to make one. see the example applet posted. //a fun exercise: convert your A3 example into an applet! //good luck and have a great summer. // I hope you enjoyed the course.