Java programming study notes

Recently, I was reading the book Effective Java, and here I briefly recorded 78 suggestions in the book. Because of some programming experience, most of the rules and regulations in the book are in practice, and some are used but I don’t know why. , of course, such as enumeration, concurrency, etc., still need more practice.

  1. Consider using static factory methods instead of constructors
  2. Consider using a builder when multiple builder arguments are encountered
  3. Enhancing Singleton properties with private constructors or enum types
  4. Enhancing non-instantiable capabilities with private constructors
  5. Avoid creating unnecessary objects
  6. Eliminate expired object references
  7. Avoid using finalizers
  8. Follow general conventions when overriding equals
  9. Always override hashCode when overriding equals
  10. Always override toString
  11. Override clone carefully
  12. Consider implementing the Comparable interface
  13. Minimize the accessibility of classes and members
  14. Use access methods in public classes instead of public fields
  15. minimize variability
  16. Composition is greater than inheritance
  17. Either design for inheritance and document it, or disallow inheritance
  18. Interfaces are better than abstract classes
  19. Interfaces are only used to define types
  20. Class hierarchy takes precedence over label classes
  21. Representing policies with function objects
  22. Prefer static member classes
  23. Please don't use primitive types in new code
  24. Eliminate unchecked warnings
  25. Lists take precedence over arrays
  26. Generics are preferred
  27. Prefer generic methods
  28. Use restricted wildcards to increase API flexibility
  29. Prefer type-safe heterogeneous containers
  30. Use enum instead of int constant
  31. Replacing ordinal numbers with instance fields
  32. Replacing Bitfields with EnumSets
  33. Use EnumMap instead of ordinal index
  34. Mock scalable enums with interfaces
  35. Annotations take precedence over naming patterns
  36. Stick with the Override annotation
  37. Defining Types with Marker Interfaces
  38. Check the validity of parameters
  39. Protective copying if necessary
  40. Carefully design method signatures
  41. Use overloading with caution
  42. Use variadic parameters sparingly
  43. Returns a zero-length array or collection instead of null
  44. Write documentation comments for all exported API elements
  45. Minimize the scope of local variables
  46. for-each loop takes precedence over traditional for loop
  47. Understanding and Using Class Libraries
  48. Avoid float and double if you need an exact answer
  49. Primitive types take precedence over boxed primitive types
  50. Try to avoid strings if other types are more suitable
  51. Beware of String Concatenation Performance
  52. Referencing an object through an interface
  53. Interfaces take precedence over reflection mechanisms
  54. Use native methods sparingly
  55. Optimize carefully
  56. Follow generally accepted naming conventions
  57. Use exceptions only for exceptional cases
  58. Use checked exceptions for recoverable cases and runtime exceptions for compilation errors
  59. Avoid unnecessary use of checked exceptions
  60. Prefer standard exceptions
  61. Throws the exception corresponding to the abstract
  62. Exceptions thrown by each method must be documented
  63. Include a message that catches the failure in the detail message
  64. Strive to keep failure atomic
  65. Don't ignore exceptions
  66. Synchronized access to shared mutable data
  67. Avoid over-synchronization
  68. executors and tasks take precedence over threads
  69. Concurrency tools take precedence over wait and notify
  70. Documentation of thread safety
  71. Use lazy initialization with caution
  72. Don't rely on the thread scheduler
  73. Avoid using thread groups
  74. Implement Serializable Interface Carefully
  75. Consider using a custom serialization method
  76. Write the readObject method protectively
  77. For instance control, enum types take precedence over readResolve
  78. Consider using serializing proxies instead of serializing instances

Guess you like

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