GUI and Events Flashcards
How do you declare a generic class in java?
class myClass { ... }
How do you make wildcard extend a super type?
extends T>
How do you make wildcard a supertype of a specific class?
super T>
How do you implement selection sort?
- repeat i times -> n
- find the smallest element in the sub set {n, i - 1}
- Move this element to position n
What is the run time complexity of selection sort?
O(n^2)
How do you implement insertion sort?
- repeat i-1 times -> n
- Itterate backwards through the sub set {0, n - 1} -> z
- If the element z is greater than element n continue itterating
- Otherwise, insert the element at position z + 1
What is the runtime complexity of insertion sort?
O(n^2)
How do you implement bubble sort?
- Repeat i times -> n
- repeat n - 1 times -> z
- If element z is greater than element z + 1 swap the two elements
What is the runtime complexity of buble sort?
O(n^2)
What is the runtime complexity of merge sort?
O(n log n)
How do you create a checked exception class?
make it extends Exception
What is the superclass of unchecked exceptions?
Error
How do you create a printwriter for a file?
File fName = new File(...); PrintWriter myPrintWriter = new PrintWriter(fName); myPrintWriter.println(...);
What exception should be caught when opening files?
IOException
How do you read data from an internet source?
URL url = new URL("www.mysite.com"); Scanner data = new Scanner(url.openStream());
How do you create a new file reader in java
FileReader(File file) or
FileReader(String fileName)
What exception should you handle when creating FileReader
FileNotFoundException
What exception should be handled with PrintWriter
FileNotFoundException
What exception occurs when there is an arithmetic error?
ArithmeticException
What exception is thrown when an out of bound array location is accessed.
ArrayIndexOutOfBoundsException
What exception is thrown when referencing a null object?
NullPointerException
What exception occurs when out of bound string location is accessed?
StringIndexOutOfBoundsException
What interface must event handlers implement?
EventHandler
How do you use a lambda expression in java?
(param1…, paramn) -> action