Chapter One: Introduction to Objects
1. Abstract process (class-to-object relationships)
A class is a common behavior (member function) and state (member variable) of a class of objects, and an object is an instantiation of a concrete class. (Eg. Humans are a class of common behaviors: Eating, State: name. )
"The class creator needs to think about this and look back at the concept of the four-character clairvoyant, each time you create this class, think about the principle that this class is what member functions and member variables are needed to satisfy a single duty "
2. Each object provides services : The goal of the program design itself is to create a series of objects that provide services to solve the problem.
3. the specific implementation is hidden: The class creator and the client programmer's user.
Often, each programmer is a combination of identities, and the creator of the class is responsible for creating the object and using it whenever it needs to expose the behavior that needs to be exposed. Package
4. reuse a specific class implementation : When creating a new class, the combination should be given precedence. Has a
"Open closure principle"
5. Inheritance:
Based on an existing class, copy it, add a new method to the subclass, or overwrite the old method. is a (subclass can completely replace the parent class) and is like a (subclass has a function that the parent class does not have) "polymorphic"
6. Interchangeable objects that accompany polymorphism
Upward transformation is a safe "Richter substitution principle", and downward transformation is not secure. "Dependency reversal Principle"
7. Single-Root Inheritance structure object
Any class is inherited to an object.
8. Container (the question is, will the container hold a reference to other objects?) Answer: Both are references, and the original data is modified. The results were obtained by random examination. )
Set:
HashSet:
Public boolean Add (E e) { return Map.put (E, PRESENT) ==null; } Public V put (K key, V value) { if (table = = empty_table) { inflatetable (threshold); } if (key = = null) return Putfornullkey (value); int hash = Sun.misc.Hashing.singleWordWangJenkinsHash (key); int i = indexfor (hash, table.length); for (hashmapentry<k,v> e = table[i]; E! = null; e = e.next) { Object K; if (E.hash = = Hash && (k = e.key) = = Key | | key.equals (k))) { V oldValue = e.value; E.value = value; E.recordaccess (this); return oldValue; } } modcount++; AddEntry (hash, key, value, I); return null; }
Linkedhashset:extends HashSet.
TreeSet:
List:
ArrayList:
Public boolean Add (E e) { ensurecapacityinternal (size + 1); Increments modcount!! elementdata[size++] = e; return true; }
LinkedList:
Public boolean Add (E e) { linklast (e); return true; } void Linklast (e e) { final node<e> l = last; Final node<e> NewNode = new node<> (l, E, null); last = NewNode; if (L = = null) First = NewNode; else l.next = NewNode; size++; modcount++; }
MAP:
HASHMAP:
Public V put (K key, V value) {if (table = = empty_table) {inflatetable (threshold); } if (key = = null) return Putfornullkey (value); int hash = Sun.misc.Hashing.singleWordWangJenkinsHash (key); int i = indexfor (hash, table.length); for (hashmapentry<k,v> e = table[i]; E! = null; e = e.next) {Object K; if (E.hash = = Hash && (k = e.key) = = Key | | key.equals (k))) {V oldValue = E.value; E.value = value; E.recordaccess (this); return oldValue; }} modcount++; AddEntry (hash, key, value, I); return null; } void AddEntry (int hash, K key, V value, int bucketindex) {if (size >= threshold) && (null! = Tabl E[bucketindex]) {Resize (2 * table.length); hash = (Null! = key)? Sun.misc.Hashing.singleWordWangJenkinsHash (key): 0; Bucketindex = iNdexfor (hash, table.length); } createentry (hash, key, value, Bucketindex); } void Createentry (int hash, K key, V value, int bucketindex) {hashmapentry<k,v> e = Table[bucketindex]; Table[bucketindex] = new hashmapentry<> (hash, key, value, E); size++; } hashmapentry (int h, K K, v V, hashmapentry<k,v> N) {value = V; Next = n; key = k; hash = h; }
In addition: In fact, the list is to change the key of the map to subscript: 0/1/2/3.../n, and set is the value of the map to become null.
9. Creation and life cycle of objects
Although Java has a garbage collection mechanism, it is necessary to understand the Java memory model (PC, virtual machine stack, local method stack, heap, method area of the respective role)
10. Exception Handling: Handling Errors
11. Concurrent Programming
1, the distinction between concurrency and parallelism, assuming that there is only one processor, the two individuals believe that the performance is consistent.
2, concurrency and parallelism difference: at the same time. (Eg. Concurrency: You are in the process of eating, the phone is coming, you can only put down the rice chopsticks to listen to the phone. Parallel: You are in the process of eating, the phone is coming, you can eat while listening to the phone. )
3, in Java programming, the program is not concerned about parallel or concurrency, only the concept of logical threads.
Java programming thought "restudying"