1, the name is strictly prohibited the use of pinyin and English mixed way.
2, domain model naming conventions
1 data object: Xxxdo, XXX is the data table name.
2 Data Transmission object: Xxxdto, XXX is the name of the business domain.
3 Display object: Xxxvo, XXX General for Web page name.
4) POJO is a general designation of DO/DTO/BO/VO, which is forbidden to be named Xxxpojo.
3, long or long when the initial assignment, must use uppercase L, lowercase easily with the number 1
Confusion, resulting in misunderstanding.
4, to avoid the use of a class of object references to this class of static variables or static methods, unnecessary increase in compiler resolution
This, directly with the class name to access.
5. Note: The variable parameters must be placed at the end of the argument list. (Encourage students to program without variable parameters)
Positive example: Public User getusers (String type, Integer ... IDs); (nullable parameter last)
6, Object Equals method is easy to throw null pointer exception, you should use constants or determine the value of the object to call equals.
Positive example: "Test". Equals (object);
7, all the same type of wrapper class object comparison between the values, all using the Equals method comparison.
Description: For integer var= the assignment between 128 and 127, the integer object is in the Integercache.cache
Generated, will reuse the existing object, this interval of the Integer value can be directly used to judge, but this interval
All data outside, will be generated on the heap, and will not reuse the existing object, which is a big pit, recommend the use of the Equals side
Method of judgment.
8. Note that Serialversionuid inconsistency throws a serialized Run-time exception.
9, on the basic data types and packaging data types use the following standards:
1 All POJO class attributes must use the wrapper data type.
2 The return value and parameters of the RPC method must use the wrapper data type.
3 All local variables recommend the use of basic data types.
10, final can improve the efficiency of the program response, declared as final situation:
1 variables that do not need to be assigned a value, including class attributes, local variables.
2 The object parameter is previously added final, indicating that the reference is not allowed to be modified.
3 The class method determines that it is not allowed to be overridden.
11, the object of the Clone method by default is a shallow copy, if you want to achieve deep copy need to rewrite the Clone method to implement the Property object
Copy.
12. When the key of Map/set is a custom object, you must override Hashcode and equals.
In the positive example: string overrides the Hashcode and equals methods, so we can happily use string objects as
Used for key.
13, ArrayList sublist result can not be strong turn into ArrayList, otherwise will throw classcastexception
Exception: Java.util.RandomAccessSubList cannot is cast to java.util.ArrayList;
Description: sublist return is ArrayList's inner class sublist, not ArrayList, but ArrayList
View, all actions for the Sublist child list will eventually be reflected on the original list.
14, list<string> List = new arraylist<string> (2);
List.add ("Guan");
List.add ("Bao");
string[] Array = new string[list.size ()];
Array = List.toarray (array);
Note: Using the ToArray method, the ToArray method will be reassigned internally when the array space allocated by the parameter is not large enough
Memory space and returns a new array address, or an array labeled [List.size ()] If the array element is larger than is actually required
The element is set to NULL, and the other array elements hold the original value.
15. When using the tool class Arrays.aslist () to convert an array to a collection, you cannot use it to modify a collection-related method.
Its Add/remove/clear method throws a Unsupportedoperationexception exception.
Description: Aslist's return object is a Arrays inner class and does not implement the set modification method. Arrays.aslist
Reflects the adapter mode, just the transformation interface, the background of the data is still an array.
string[] str = new string[] {"A", "B"};
List List = Arrays.aslist (str);
In the first case: List.add ("C"); Run-time exceptions.
The second situation: str[0]= "Gujin"; Then List.get (0) will also be modified.
16, do not remove/add the element in the Foreach Loop operation (will throw concurrentmodificationexception). remove element Please use iterator
method, if concurrent operation, need to lock iterator object.
17. Map Collection: VALUES () returns a collection of V values, which is a list collection object; keyset () returns a collection of K values, which is
A set collection object; EntrySet () returns a collection of K-v value combinations.
18, high concurrency, synchronous calls should consider the performance of the lock loss. Can use the unlocked data structure, do not use the lock;
Lock block, do not lock the whole method body, can use object lock, do not use class lock.
19, thread pool is not allowed to use executors to create, but through the threadpoolexecutor way, so
The processing way lets write the classmate to be more explicit the thread pool The running rule, avoids the resource exhaustion risk.
Description: Executors The disadvantages of each method:
1) Newfixedthreadpool and Newsinglethreadexecutor:
The main problem is that a stacked request-processing queue can consume very large memory, or even OOM.
2) Newcachedthreadpool and Newscheduledthreadpool:
The main problem is that the maximum number of threads is integer.max_value and may create a very large number of threads, even OOM.
20. Note that the child thread throws an exception stack, which cannot be try-catch to the main thread.
21. Note Math.random () This method returns a double type, noting that the value range 0≤x<1 (to be able to fetch
To zero value, note exception 0.
22, a single table row number of more than 5 million lines or a single table capacity of more than 2GB, it is recommended for the Sub-Library table.
23, where a=? and B>? Multiple query conditions, the distinction of high in the former, have = in the former.
24, prohibit the use of stored procedures, stored procedures difficult to debug and expand, and no portability (hidden in the db, not intuitive difficult to maintain).
25, delete and modify records, first select, avoid false deletion, confirm the correct ability
Commit execution.
26, in operation can avoid to avoid, if you do not avoid, you need to carefully assess the number of elements in the back of the collection, control
System within 1000.
27, <isNotEmpty> is executed when it is not NULL and is not NULL, <isNotNull> when the value is not NULL.
28, MySQL type of decimal is actually stored in a string. Try to replace float and double with decimal.
Https://yq.aliyun.com/articles/240163?spm=5176.10695662.1996646101.searchclickresult.7b4515c54fNXir