Find Programming Errors And Duplicate Lines of Code In Java, C, C++,etc

Editor Ratings:
User Ratings:
[Total: 1 Average: 5]

PMD is an open source code analyzer to find various programming errors like empty loops, unused variables, and so on in various programming languages like C, C++, Java, C#, and many more. It also finds duplicate lines of code that you can export as text, CSV (comma), CSV (tabbed), and XML file format.

When you compile source code on a compiler, then it checks for syntax errors and notifies you about them. But while compiling, a compiler might ignore logical errors like unused variables, checking empty loops, unnecessary object instantiation, and so on. So this free source code analyzer can be used to find these errors. This feature is quite handy for finding logical errors inside a large source code file. To find programming errors you need to integrate PMD with an IDE like BlueJ, Netbeans, JEdit, and many others supported by it.error
You can use this software to find programming errors and duplicate lines of code but if you want to calculate or analyze various code metrics like complexity, code to whitespace ratio, or code to comment ratio then you can go with CodeAnalyzer. Or you can also try SourceMonitor which displays code complexity through bar graph. But PMD can find logical errors in your source code like unused variables, empty try-catch loops, unnecessary instantiation of class objects, and so on. And it supports more programming languages as compared to CodeAnalyzer and SourceMonitor.

How to find duplicate lines of code in programs:

You can find duplicate lines of code through PMD Code Detector. To run PMD Code Detector, download PMD using the link given at the end of this software. Extract the downloaded zip file and run cmdgui Windows Batch file. You can find this file in pmd-bin-5.5.1\bin directory.

For finding duplicate lines of code, you just need to specify a location of your source code and select programming language of that code. You can use it to search following programming languages: Objective-C, C#, Ruby, Scala, Java, PHP, Javascript, Apache Velocity, APEX, XML, PLSQL, Swift, Matlab, GO, Python, and Fortran.

It then scans the whole directory and searches for any duplicate line of code. It also scans for duplicate lines of code in different files also. After scanning, it displays the result  and you can also save the results as text, XML, CSV (comma), and CSV (tabbed) file format. It also specifies line numbers from where the code is being repeated.

You can choose to ignore these tokens while searching for duplicate lines of code:

  • Literals
  • Identifiers
  • Annotations / Comments
  • Header files / Usingsduplifiule

How to find programming errors using PMD:

As I mentioned earlier, you need to integrate PMD with an IDE (that should be supported by PMD) to find programming errors. It can be installed as a plugin in any of its supported list of IDE. You can integrate PMD with any of these IDE.

  • Textpad
  • BlueJ
  • Maven 2
  • Code Guide
  • Netbeans
  • Jcreator
  • Jbuilder
  • IntelliJ Idea
  • Jedit
  • Maven
  • Eclipse
  • Gel
  • Weblogic Workshop 8.1.x
  • IntelliJ Idea-QA Plug
  • Emacs
  • eclipse-pmd
  • JDeveloper

There are different methods to integrate PMD with different IDE. If you are familiar with any other IDE available in this list then you can read the steps for integrating here.

I will tell you how you can find programming errors by integrating PMD with BlueJ.  If you are not familiar with BlueJ then you can read this article to get more insights about it.

So lets get started by seeing how to integrate PMD with BlueJ.

Step 1: To integrate PMD with BlueJ, you need to download PMDExtension jar file (just around 1 MB). Download PMDExtension Jar file from here.

Step 2: Place it in BlueJ/lib/extensions and start BlueJ.

Now you have successfully integrated PMD with BlueJ.

Now for checking errors in your source code, right click a class and select PMD>>Check Code, as shown in the main screenshot. It will then display a pop-up message if there are any errors in your code. errormsg


This free code analyzer software is quite useful as it can detect logical programming errors that can help you in minimizing number of bugs and improve code security. It also lets you find any duplicate lines of code by PMD code detector. As compared to other source code analyzers, this one is quite unique as it can be integrated with many IDE and can detect logical programming errors as well. Do give it a try.

Get this open source free code analyzer from here.

Editor Ratings:
User Ratings:
[Total: 1 Average: 5]
Works With: Windows
Free/Paid: Free

Leave A Reply


Get 100 GB FREE

Provide details to get this offer