Bittiger Lesson3
java
bittiger
fundanmental
Review
Quicksort:In-space, non-stable
Mergesort: not in-space. stable, O(n) extra memory usage
Primitiive Value: Quicksort
Objects: Mergesort (what is being sort is objects' refrence)
<=7 array: Insertion Sort
Class
variables
method
modifier
private/default(package)/protected/public
static--dont need instance
Class -- static
- static class
- static member class
- non-static member class
- static method
- static variable
- static initializer
- static block(first run)
static member class
class List {
private static Node{
Node next;
}
}
static member class is isolated from enclosing class instance.
non-static member class
Class -- static
- static class : static inner class, isolated from enclosing class instance. (Iterator 和instance有关系)
List里的Node常用static class
- static method:
Class--final
- Final class: class cannot be extended
- Final method: method cannot be override
- Final variable:variable can only be assigned onve.(Reference!)
Q:static final variable is immutable?
Not really. see slides 19.
final是array(object)的refrence,内存中的refrence不能被改(也不能再new一个array),但array里面的元素(Object里的内容)是可以改的.只有final修饰primitive value才能达到immutable. Guava里的ImmutableList可以做到.
- Finally:finally block -- code section
Interfaces and Abstract Classes
- interface
- Unrelated classes implement your interface.(eg Comparable)
- Define a new data type. (e.g List)
- Multiple inheritance types.(e.g List, Deque <== LinkedList)
- Abstract Class
- Share code among classes
- Share commo non-public methods, variables
- Share code which coul change the state of the object.
Reflections
if (obj instanceof Objecct) {
...
}
Reflection--class