Master Java Code Quality with Alibaba Guidelines, CheckStyle, PMD, FindBugs, SonarLint
This article introduces essential Java static analysis tools—including Alibaba Java Coding Guidelines, CheckStyle, PMD, FindBugs, and SonarLint—detailing their installation, usage, and key features to help developers improve code quality, reduce review effort, and prevent bugs in growing backend systems.
As a system grows, code complexity and hidden risks increase, making code quality checks essential. This guide presents several Java static analysis tools that help improve code quality and reduce code‑review workload.
Alibaba Java Coding Guidelines
Overview
Alibaba Java Coding Guidelines focuses on Java coding standards, categorizing violations as Blocker, Critical, or Major, many of which can be auto‑fixed. It provides real‑time inspection during coding.
Installation
File > Settings > Plugins > Marketplace– search "Alibaba Java Coding Guidelines" and install, then restart the IDE.
Usage
Run the scan via
Tools > Alibaba Coding Guidelines > Scanor right‑click in the editor/project view and select "Scan".
Menu functions include:
Scan : start scanning the code.
Toggle Real‑time Inspection : enable/disable live detection.
Switch Language : toggle between Chinese and English.
Rerun Inspection : run the scan again.
Close : close the AJCG panel.
Expand All / Collapse All : control the tree view.
Go to Previous / Next Problem : navigate between issues.
Group by Severity / Directory : group results.
Filter Resolved Items : hide already fixed issues.
Autoscroll to Source : jump to the source code.
Export : export results as XML or HTML.
Edit Settings : modify plugin settings.
CheckStyle
Overview
CheckStyle checks coding style and formatting rules such as naming conventions, Javadoc, whitespace, method length, duplicate code, and unused imports. It focuses on syntactic style rather than bug detection.
Installation
File > Settings > Plugins > Marketplace– search "CheckStyle" and install.
Usage
Run the inspection from the Tools menu; the UI shows style violations.
PMD
Overview
PMD focuses on security‑related coding rules and provides data‑flow and path analysis. It supports custom rule sets and can detect potential bugs, dead code, misuse of String/StringBuffer, complex expressions, duplicated code, object creation in loops, and resource leaks.
Installation
File > Settings > Plugins > Marketplace– search "PMDPlugin" and install.
Usage
Run PMD via
Tools > Run PMDfor the whole project or via the right‑click context menu for a selected scope. Results appear in a panel with a tree view; clicking an issue jumps to the source line.
FindBugs
Overview
FindBugs detects real bugs such as null‑pointer dereferences, resource leaks, and incorrect string comparisons. It provides concise suggestions for fixing each issue.
Installation
File > Settings > Plugins > Marketplace– search "FindBugs" and install.
Usage
Analyze a file, package, module, or whole project via the right‑click menu. Results are displayed in a panel; selecting an item opens the offending code.
SonarLint
Overview
SonarLint extends static analysis beyond bugs to code quality, dependency analysis, complexity, and code duplication, offering a comprehensive view of project health.
Installation
File > Settings > Plugins > Marketplace– search "SonarLint" and install.
Usage
Right‑click a project or file and select SonarLint analysis. Issues are shown in a report with suggested fixes. You can also configure a SonarQube server for remote analysis.
Conclusion
For coding‑style checks, use
Alibaba Java Coding Guidelines.
For bug detection, combine
PMD,
FindBugs, and
SonarLintto cover different scenarios.
macrozheng
Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.
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.