Items in one sentence about java

  1. Always assume most extreme inputs and most weird operations.
  2. Assume user’ hardware configuration(CPU/memory/disk) is lower than average level.
  3. Use BufferedInputStream and BufferedOutputStream for file I/O.
  4. Use try-with-resource for file I/O.
  5. Always consider out of memory when read/write file or data.
  6. Notice charset when read/write text file.
  7. Notice charset when convert between bytes and string.
  8. Condition to determine whether reach end of file should be "len > 0". If use "len != -1", endless loop may happen if zero byte is read.
  9. Call "System.gc()" before delete/move/rename file, to avoid failure due to cache.
  10. When handle information in tree, like files system, endless loop should be avoided. If the operation will change source node, the target node should not be the source node nor its descendants.
  11. If delete list by indices, delete items from the end index to the start index.
  12. When class has many parameters, do not write many constructors to initialized different sets of parameters. Better coding is static creator and chain assignment by return “this” in all “set” methods.
  13. Anonymous class is very useful for scenario like lots of duplicated codes with only difference that several methods have difference implements.
  14. Generic is very useful for scenario like lots of duplicated codes with only differernce of data type.
  15. Define as less instance variables/methods as possible in class if it generates lots of instance.
  16. As less float-point calculations as possible in loop. If can, change float-point calculations as integer calculations.
  17. When listen data changing, need judge whether change trully happens, and avoid too frequently manufactures by setting minimum threshold of changing.
  18. Reboot application when change JVM parameters or need clean env in simple way.
  19. Notice whether the index is 0-based or 1-based, especially for thrid-party codes. 0-based is default. If 1-based, should write comment for it.
  20. Generally, index in user interface starts from 1, while index in codes data starts from 0.
  21. Generally, range(start-end) in user interface includes end, while range(start-end) in codes data excludes end.
  22. Double.MIN_VALUE is the minimum positive double(almost zero). -Double.MAX_VALUE is the minimum double.
  23. When handle money, store integer numbers for each unit.
  24. BigDecimal is much slower than double. Double is enough for most situations.
  25. To determine value's broken, write if (abs(x - 7.3) < TOLERANCE) instead of if (x == 7.3).
  26. Value of final static constant should be determined at compling time.
  27. When JDBC read numbers, if SQL value is null, ResultSet.getDouble/getFloat/getInt/getShort returns 0. Use ResultSet.getObject instead if need distinct zero and null. ResultSet.html#getDouble
  28. From Java18, Charset.defaultCharset() is always UTF-8. This will affect commands and results of ProcessBuilder. Process JDK-8266075