"Ali Development Manual" reading notes (5)

9.1 1. [Mandatory] When using regular expressions, make good use of its pre-compilation function, which can effectively speed up regular expressions.

Description: Do not define in the method body: Pattern pattern = Pattern . compile( rule );


9.4 4. [Mandatory] Note that the Math.random () method returns a double type, pay attention to the range of values ​​0≤ x < 1 ( zero value can be obtained , pay attention to the exception of division by zero ) , if you want to obtain a random number of integer type , do not magnify x by several times of 10 and then round it, use the nextInt or nextLong method of the Random object directly .



9.5 5. [Mandatory] Get the current milliseconds System . currentTimeMillis(); instead of new Date() . getTime();
Note: If you want to get a more accurate nanosecond time value, use System . nanoTime() . In JDK 8 , the Instant class is recommended for scenarios such as counting time.


9.7 7. [Recommendation] The size of any data structure should be specified when constructing or initializing it to prevent the data structure from growing indefinitely and eating up memory.


9.8 8. [Recommended] For " clearly discontinued code and configuration " , such as methods, variables, classes, configuration files, dynamic configuration properties
, etc., must be resolutely removed from the program to avoid causing too much garbage.



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324692803&siteId=291194637