Java advanced (iii) ------ java programming specifications-Comparison of FindBugs, PMD, and CheckStyle code quality detection tools
In the previous article, we have learned how to automatically set the code format in myeclipse.
During the development process, we will find that we do not have much time to perform code check and review. However, we can use tools to automatically check the code to improve work efficiency. FindBugs, PMD, and CheckStyle are the three tools for this purpose. These three tools allow us to write more standardized code and improve the performance of our code.
These three tools have different focuses on code check. Let's take a look at their differences:
Tools |
Purpose |
Check items |
Features |
FindBugs |
Check. class Find potential bugs in javabytecode (. class file) based on the concept of Bug Patterns |
This mainly checks the bug patterns in bytecode, such as NullPoint NULL pointer check, the resource is not properly closed, and the same string judgment error (=, rather than equals ). |
Most of FindBugs prompts are useful and worth changing No search function is configured, but the abbreviation allows us to quickly find a rule. Provides independent programs on the GUI to detect jar files and generate reports, which is very convenient. Many plug-ins are not implemented. You can use FindBugs independently, but you cannot modify the source code at the same time. |
PMD |
Check source files Check potential problems in Java source files |
It mainly includes: Empty try/catch/finally/switch statement Block Unused local variables, parameters, and private methods Null if/while statement Too complex expressions, such as unnecessary if statements Complex class |
Relatively strict Independent programs operate in the form of command lines You can configure rules for the plug-in and have a view that displays issues independently. Generally, custom rules are required to pass the test. |
CheckStyle |
Check source files Main concern format Check whether the Java source file is consistent with the Code specification. |
It mainly includes: Javadoc comments Naming rules Useless Imports Size measurement, such as the method that is too long Necessary spaces are missing. Whitespace Duplicate code |
Too strict According to Sun's specification, it is too strict and requires custom rules. Plug-in custom rules do not have the search function, so it is troublesome to search for rules. You can only perform the check and not modify the code. You can use Jalopy to modify the code. |
By default, the Checkstyle plug-in has two built-in configuration files for code check: Sun Checks and Sun Checks (Eclipse ). However, these two files are checked in great detail. Even a good open-source project will check out a lot of error messages, so we need to import our own configuration file.
To write a rule configuration file, you must first understand the rule.
Checkstyle
Detailed description of CheckStyle check rules (138 rules in total)
Checkstyle Official Website: http://checkstyle.sourceforge.net/
Checkstyle. xml and formatting templates based on Huawei java programming specifications, and comment templates