Boost Java Code Quality: Guide to Alibaba Guidelines, CheckStyle, PMD, FindBugs & SonarLint
This article explains why code quality matters in growing Java projects and introduces five essential static analysis tools—Alibaba Java Coding Guidelines, CheckStyle, PMD, FindBugs, and SonarLint—covering their purpose, installation steps, usage instructions, and key features to help developers reduce bugs and improve review efficiency.
Alibaba Java Coding Guidelines
1. Overview
Alibaba Java Coding Guidelines focuses on Java code conventions, helping developers format code consistently. The plugin scans code and categorises violations as Blocker, Critical, or Major, many of which can be auto‑fixed, and provides real‑time inspection while coding.
2. Installation
File > Settings > Plugins > Marketplace– search for "Alibaba Java Coding Guidelines", install, and restart the IDE.
3. Usage
3.1 Run Scan : Tools → Alibaba Coding Guidelines → Scan Code.
3.2 Right‑click menu : select "Scan Coding Guidelines" from the context menu.
3.3 Menu Functions
Scan Coding Guidelines : start scanning.
Toggle Real‑time Inspection : enable for faster feedback on capable machines.
Switch Language to English : toggle UI language.
3.4 Scan Results
Results are grouped as Blocker > Critical > Major, indicating severity.
Blocker > Critical > MajorSelecting an issue shows detailed information and navigation options.
3.5 Toolbar Functions
Rerun Inspection: run the scan again. Close: close the AJCG panel. Expand All / Collapse All: toggle tree view. Go Prev Problem / Go Next Problem: navigate issues. Group by Severity / Group by Directory: change grouping. Filter Resolved Items: hide resolved issues. Autoscroll to Source: jump to source code. Export: export results as XML or HTML. Edit Settings: open configuration.
CheckStyle
1. Overview
CheckStyle checks coding style and format, such as naming conventions, Javadoc, whitespace, method length, duplicate code, and unused imports. It focuses on grammar‑level rules and does not detect bugs.
2. Installation
File > Settings > Plugins > Marketplace– search for "CheckStyle", install, and restart.
3. Usage
After installation, the plugin mainly shows indentation and formatting warnings.
PMD
1. Overview
PMD focuses on security‑related coding rules and provides data‑flow and path analysis. It supports custom rule sets. Common rule categories include potential bugs, dead code, misuse of String/StringBuffer, complex expressions, duplicate code, object creation in loops, and resource leaks.
2. Installation
File > Settings > Plugins > Marketplace– search for "PMDPlugin", install, and restart.
3. Usage
3.1 Run from Tools menu : Tools > Run PMD scans the entire project.
Results show rule categories such as "Pre Defined" (built‑in) and "Custom Rules" (user‑defined).
Pre Defined : use all or select specific rule sets.
Custom Rules : import custom rule files via settings.
3.2 Run from right‑click menu : select "Run PMD" on a file, package, or module to scan the selected scope.
3.3 Configure Rules
Open File > Settings > Other Settings > PMD to manage rule sets and import custom configurations.
FindBugs
1. Overview
FindBugs detects runtime bugs such as null‑pointer dereferences, unreleased resources, and incorrect string comparisons. It provides simple suggestions for fixing identified issues.
2. Installation
File > Settings > Plugins > Marketplace– search for "FindBugs", install, and restart.
3. Usage
Analyze a file, package, module, or whole project via the right‑click menu. /module or /project can be selected for scanning.
After analysis, a results panel appears; clicking an item navigates to the problematic code.
4. Common Issue Types
Bad practice (code smells)
Dodgy code
Internationalization issues
Performance problems
Experimental warnings
Malicious code vulnerabilities
Multithreaded correctness
General correctness
SonarLint
1. Overview
SonarLint extends beyond FindBugs by analysing code quality, dependencies, coupling, complexity, and duplicated code, offering a comprehensive view of project health. It is available as an IDE plugin.
2. Installation
File > Settings > Plugins > Marketplace– search for "SonarLint", install, and restart.
3. Usage
Right‑click a project or file and select SonarLint actions. Issues are reported in a panel, and clicking an issue shows suggested fixes.
4. Configure SonarLint Server
In the plugin settings, add a SonarQube server (Configuration Name, URL, login/password) and associate the desired project.
After linking, select the project from the connection dropdown and run analysis on chosen classes or directories.
Conclusion
For coding standards, use Alibaba Java Coding Guidelines.
To find bugs, combine PMD, FindBugs, and SonarLint for complementary coverage.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
