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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值