A Guide to Java Code Quality Tools: Alibaba Java Coding Guidelines, CheckStyle, PMD, FindBugs, and SonarLint
This article introduces several Java code‑quality tools—including Alibaba Java Coding Guidelines, CheckStyle, PMD, FindBugs, and SonarLint—explaining their purpose, installation steps, key features, and how they can improve code review efficiency and overall code health.
1. Alibaba Java Coding Guidelines
1. Overview
Alibaba Java Coding Guidelines focuses on Java coding standards, providing real‑time inspection and categorizing violations as Blocker, Critical, or Major, many of which can be auto‑fixed.
The guideline covers OOP rules, concurrency handling, control statements, naming conventions, constant definitions, and comment conventions.
2. Installation
File > Settings > Plugins > Marketplace then search for “Alibaba Java Coding Guidelines” and install.
3. Usage
3.1 Run method
(1) Tools > 阿里编码规约 > 编码规约扫描
(2) Right‑click in the editor or project view and select “编码规约扫描”.
3.2 Menu functions
编码规约扫描 : start scanning
打开/关闭实时检测功能 : toggle live inspection
切换语言至英文 : switch language
3.3 Result
Results are shown with three severity levels: Blocker > Critical > Major .
2. CheckStyle
1. Overview
CheckStyle checks coding style and formatting issues such as naming, Javadoc, whitespace, method length, duplicate code, and unused imports. It does not detect bugs.
2. Installation
Use File > Settings > Plugins > Marketplace to search for “CheckStyle” and install.
3. Usage
After installation, the plugin shows style violations; most are related to indentation and formatting.
3. PMD
1. Overview
PMD focuses on security‑related rules and provides data‑flow and path analysis. It supports custom rule sets and detects potential bugs, dead code, misuse of String/StringBuffer , complex expressions, duplicated code, object creation in loops, and resource leaks.
2. Installation
Install via File > Settings > Plugins > Marketplace searching for “PMDPlugin”.
3. Usage
Run from Tools > Run PMD or right‑click a file/package/project. Results appear in a panel; rules can be configured under Settings > Other Settings > PMD.
4. FindBugs
1. Overview
FindBugs detects runtime bugs such as null‑pointer dereferences, unreleased resources, and incorrect string comparisons, providing suggested fixes.
2. Installation
Install via File > Settings > Plugins > Marketplace searching for “FindBugs”.
3. Usage
Analyze a file, package, module, or whole project via right‑click and view results in a panel; clicking an item jumps to the source line.
5. SonarLint
1. Overview
SonarLint extends static analysis beyond bugs to code quality, dependencies, coupling, complexity, and duplicated code. It works as an IDE plugin.
2. Installation
Install via File > Settings > Plugins > Marketplace searching for “SonarLint”.
3. Usage
Run SonarLint on a class or directory; configure a SonarQube server for remote analysis if needed.
Conclusion
For coding‑style checks, use Alibaba Java Coding Guidelines.
For bug detection, combine PMD, FindBugs, and SonarLint; PMD offers strong customisation, FindBugs is useful for training, and SonarLint provides the richest rule set.
Java Captain
Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.