Java programming specifications and performance summary help improve

Source: Internet
Author: User

Performance -------------------------------- rules ------------------------------------------ log rules for Debug, before output of Info-level logs, you must first judge the current debugging level. This indicates that logs generally have many strings for processing. if it is not Debug-level, there is no need to process the example if (logger. debugEnable () {logger. debug ("request:" + request. getMethod ();} the rule indicates that the logger object in the log tool class should be declared as static to prevent repeated new logger objects. logger indicates that various log tool classes can be log4j, common log, jdk logger, although some logger has some optimizations to the LogFactory, we must also prevent the code from running the array rule array replication to use the System. arraycopy (*) indicates better performance set rules. Do not convert the set into an Array Using loops. You can use toArray () of the Set () method Description: better performance code more concise String rules: adding a large number of strings should use StringBuffer to describe that a large number of strings are added equal to processing performance consumption. "A large number" is generally more than 5 times "+ = ". or in the loop string + = operation http://www.52mvc.com -------------------------------- recommended --------------------------------------- other API functions are recommended to use JDK built-in API functions, do not write similar function descriptions by yourself: JDK's own functions provide better performance in terms of reliability and performance, in particular, for algorithm I/O, it is recommended that I/O operation streams use classes with Buffer functions to demonstrate better performance. No Buffer output streams are frequently used for I/O operations. However, low I/O operation efficiency is recommended for public-type underlying functions. when determining invalid parameters, the system should take the initiative to throw a RuntimeException, indicating that the underlying function must ensure the correctness of the input parameters and then perform other processing to prevent subsequent code from throwing errors. Unnecessary subsequent code execution uses RuntimeException to reduce try. catch is everywhere and helps to quickly locate the Exception Code example www.2cto. compublic void doDivide (int a, int B) {if (B = 0) {throw new IllegalArgumentException ("denominator can't be zero ");}...}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.