How to improve your code quality---using PMD

Source: Internet
Author: User

To improve the quality of your code, in addition to improving logical control and understanding of business processes, there is room for improvement in the code itself, such as some potential problems that can be avoided early. Similar to the content of the coding code, if all rely on the coder to do their own checks, it will undoubtedly require a lot of work, if you can use the static inspection tools to check the code, then greatly improve the efficiency of coding.
This article is the first of a series of articles on improving code quality, which focuses on how to automate the code with the PMD tool to circumvent some potential problems and find logic errors in the code.
1. What is PMD?
PMD is a code-checking tool that examines Java source code to identify potential problems as follows:
®       Potential bugs: Empty try/catch/finally/switch statements
®       Unused code: Unused local variables, parameters, private methods, and so on
®       Optional code: Misuse of String/stringbuffer
®       Complex expression: An If statement that is not required, a for loop that can be completed using a while loop
®       Duplicate code: Copy/Paste code means copy/paste bugs
Can be at the following address Download PMD, and can be in Rule Set IndexPage to see a preview of all the rules.
At the same time, PMD has been associated with JDeveloper, Eclipse, JEdit, JBuilder, BlueJ, Codeguide, NetBeans, Sun Java Studio enterprise/creator, IntelliJ Idea, TextPad, Maven, Ant, Gel, JCreator, and Emacs are integrated together.
2. Installing the PMD plug-in in eclipse
PMD can be integrated into many popular Ides as Plug-ins, and many plug-ins contain the PMD jar file, which contains the rule set. So while some plug-ins use Rulesets/unusedcode.xml as a parameter to refer to the rule set, they actually use the getResourceAsStream () method to load from the PMD jar file.
Because Eclipse is the more popular open source JAVA/J2EE development IDE, this article focuses on how to use the PMD tool for code checking in eclipse.
The process of installing Eclipse's PMD plug-in is as follows:
®       Start eclipse
®       Select Help-->software Updates-->find and Install
®       Select next to select New remote site
®&nb
<

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.