Java Language Best Practices

zno2 / 2023-06-06 / 原文

https://docs.oracle.com/cd/A97688_16/generic.903/bp/java.htm

  • Avoid or Minimize Synchronization

     

  • Monitor Synchronization

     

  • Monitor and Fix Resource Leaks

     

  • Always Use a Finally Clause In Each Method to Cleanup

     

  • Discard Objects That Throw Catch-All Exceptions

     

  • Design Transactions Usage Correctly

     

  • Put Business Logic In the Right Place

     

  • Avoid Common Errors That Can Result In Memory Leaks

     

  • Avoid Creating Objects or Performing Operations That May Not Be Used

     

  • Replace Hashtable and Vector With Hashmap, ArrayList, or LinkedList If Possible

     

  • Reuse Objects Instead of Creating New Ones If Possible

     

  • Use Stringbuffer Instead of String Concatenation