There are a lot of plug-ins in the eclipse environment that can help us with the static analysis of the code, which can help us find bugs in the code as early as possible. Here are a few common plug-ins:
1. PMD
We can install the PMD plug-in for eclipse through Http://pmd.sourceforge.net/eclipse.
PMD is a Java source Code analysis tool based on static rules. It comes with some rules that can be used directly, and users can define their own rules to check for potential problems with Java code: Possible bugs-such as empty TRY/CATCH/FINALLY/SWITCH statement block useless code-such as local variables not used, parameters and private methods Empty if/while expressions are overly complex expressions-such as unnecessary if,for loops can be used directly with the while loop suboptimal code-for example, String/stringbuffer's improper use class has too much complexity to duplicate the code
Of course, the problem that PMD finds may not be a real bug, it needs to be judged by yourself.
2. Checkstyle
Checkstyle Plugin Installation Address Http://eclipse-cs.sourceforge.net/update
For more detailed information, refer to http://eclipse-cs.sourceforge.net/downloads.html
Checkstyle is also a rule-based Java code Static Analysis tool for better quality, readability, and reusability of Java code. Checkstyle defines the degree of rigor that can be configured, and each of its rules has corresponding notifications, warnings, and errors. Its check analysis features include: Java code annotation naming specification method parameters number, the length of each line of code in the code of the Space class when constructing the way to duplicate code complex code
In actual use, you will find that Checkstyle check out a lot of problems, you can choose according to the needs.
3. FindBugs
Checkstyle Plugin Installation Address http://findbugs.cs.umd.edu/eclipse/
For more detailed information, refer to http://findbugs.sourceforge.net/manual/eclipse.html
As the name suggests, FindBugs is a tool to help us analyze bugs in the code, but unlike the two tools above, it is discovering the problem by matching the code's bytecode (class file) and a set of bug patterns. That is, FindBugs does not pay attention to style or format, it tries to find only real flaws or potential performance problems, such as: Hash equals mismatched null pointers before detection initialization read fields
In the actual development process, the personal thought of practical degree: FindBugs > PMD > Checkstyle