Sensible Java Coding Standards
General
Never, ever, ever copy-and-paste source code. If I had my way, the copy/paste function in the editor would be disabled.
Never copy a file to create a new file, always use File->New
use as few lines of code as possible to accomplish the mission
Stick to the standards
Use highest-level tool that accomplishes the mission
Use JavaEE for messaging and transaction management
Use JPA O/R mapping to the highest degree possible, but not any higher
Use JPA relationships rather than separate queries
Never, ever, ever copy-and-paste source code
Don't use workarounds, since we use almost 100% open-source software
Adhere to Immutability Standards
never use static mutable state and use immutable objects
Check before introducing new infrastructure or "infrastructure"-y code. The requirements are probably already met by the environment. If in doubt, ask.
Keep the trunk clean. Â Source trunk should be production-ready at any time.
Use java.time.* as in LocalDateTime/LocalDate etc. classes instead of java.util.Date and companions. The latter is considered deprecated
Do's
Use Project Lombok for getters/setters/equals/hashCode and other boilerplate
Use @SneakyThrows to avoid catching checked exceptions
Use JPA CriteriaQuery or JPQL instead of native SQL
Use XA transactions where necessary
Use JavaDoc
Use meaningful variable names
Use immutable objects
Dont's
Never, ever, ever copy-and-paste source code (can't say this enough times)
Don't catch/log/hide system exceptions, let the infrastructure handle them
Don't catch generic Exception or Throwable directly. Catch only specific exceptions by using Java 8 multi-catch or @SneakyThrows
Don't write your own getters, setters, equals or hashCode, delete these even when generated by IDEs. Use Lombok to handle them
Don't use native SQL or stored procedures
Never, ever, ever copy-and-paste source code (can't say this enough times)
Don't introduce new infrastructure without checking first what already exists
Don't break the trunk builds and functionality
Don't use meaningless variable names, such as ttt, ccc, xxx, etc.
Don't create "defensive" code that checks parameters passed by infrastructure. Â Let infrastructure do user input checks instead
Don't use "defensive" null checks. Use @NonNull instead
Don't use static mutable state in objects, use @Singleton instead, or nothing at all








