Java best practices summary

This document is an extension of the Software engineering best practices summary, dedicated to Java-specific issues.

Dates

  • Use the LocalDateTime API (LocalDate, LocalTime, LocalDateTime, etc.) instead of other solutions (like JodaTime)

Streams

  • Wherever it makes sense, use Java 8’s streams – they are usually more readable than classic for-loops
  • Every function call after .stream() should start from a new line
  • If an anonymous function has more than one line, consider extracting it into a separate method

Optionals

  • Prefer .orElse() instead of .isPresent()