Java Coding Standards and Best Practices

This page lists the output of Code Reviews done in the project as a list of coding practices.
Severity levels are from 5 (low severity) to 1 (high severity). Low severity issues may not be fixed. High severity issues must be fixed.
Best Practices
Naming:
Implementation classes should have postfix *Impl
Interfaces should not have prefix I*
Classes should not contain the CS prefix
Class structure:
Strings should be extracted to constants and given a name
Class member access inside a class must be done by direct member access with prefix: this.member
Dependency injection should be done using only setter injection (no constructor injection is used), use spring annotation @Required
Logging:
log4j Logger static class member should be named LOGGER
Use "if (LOGGER.isDebugEnabled())" only if the message construction is a complex computation
Comments:
Source code files should contain copyright comments at the top of the file
Code comments should be minimal and, if used, should tell WHY you are doing something, not WHAT you are doing. Most of the
times, if there is something to explain, it is worth to use extractMethod and explain it in both the extracted method name and it's
javadoc
Exception handling:
Non business exceptions (for example: IOException) must be always wrapped by business exceptions (CSRamServiceException)
Messages of non business exceptions cannot be displayed to the user; this means that business exceptions do not blindly append
non business messages to the end of its own message; exceptions to this rule will exist
Catch an exception only if you want to do something with it; for example, solve it, wrap it or use its error message
Caught exception must be handled, re-thrown, or wrapped, exceptions must NOT been swallowed
Unchecked exceptions can be used when errors cannot be handled by the application; for example, DAO runtime exceptions are
handled using spring AOP
User error messages should be defined as class members, not in the catch block
Project structure:
There is no src/test/resources folder, all configuration files should be in etc/example
Unit Tests:
Unit tests should not have Javadocs

 

你可能感兴趣的:(java)