7

I would like to know which tool is best for finding any kind of bugs in my code. I know this may be some what theoretical or never ending question so I would like to modify it in terms of the efficiency of bug reporting (including the naming convention as well). So you can say which tool reports and maximum bugs and if effectively used in the industry? I heard about findbug is it really good?

aioobe
  • 413,195
  • 112
  • 811
  • 826
amod
  • 4,190
  • 10
  • 49
  • 75
  • 4
    Use the one situated between your ears, that's the most potent one and is not replaceable by any machine tools ;-) – Péter Török Sep 06 '11 at 14:18
  • @Peter nice comment... but sometime it dont seems practical specially when you are just a starter... these tool will help you to increase your database of tool named as brain which can be used later.... findbug improved my coding practice a lot. – amod Sep 06 '11 at 14:23
  • 3
    Indeed. But unless you actually learn *why* the specific FindBugs warnings are issued and how to avoid them, i.e. how to write better code (for which you must use your brains), you won't become a better developer, no matter how many code analysis tools you use. – Péter Török Sep 06 '11 at 14:45
  • @peter i do agree to that peter and respect your comment – amod Sep 06 '11 at 17:33

5 Answers5

10

FindBugs is probably one of the most prominent ones and well worth a try.

For naming conventions etc, I'd suggest you have a look at CheckStyle.

aioobe
  • 413,195
  • 112
  • 811
  • 826
  • Yes I have used find bugs but we dont have any bug for style. Going through check style let me try that as well. – amod Sep 06 '11 at 14:15
3

Findbugs is quite good. However, I would recommend using sonar to maintain code quality. http://www.sonarsource.org/ It integrates well with maven (sonar:sonar). Other than this I believe the use of maven site to create checkstyle, pmd, findbugs et-all report also helps keep the developers on toes.

Scorpion
  • 3,938
  • 24
  • 37
2

It depends on what you are looking for. Personally, I use a combination of FindBugs and PMD for performing static analysis of Java code. However, I recently discovered an Eclipse plugin called CodePro Analytix by Google.

There are two types of analysis for Java code - source code analysis and byte code analysis. PMD looks at the source code to find possible bugs, unused code, suboptimal code, complicated expressions, and duplicated code. FindBugs looks at the generated byte code to find possible errors. Both are essential when analyzing an application.

However, when it comes to finding defects, nothing beats a good testing framework and (if necessary) a mocking library. I've had good successes with JUnit and Mockito. This will enable you to write unit tests for your modules. Writing code system, integration, and smoke tests, either using automated tools or test procedures is also important so that you can cover core functionality and quickly see when something is broken.

Mike Samuel
  • 118,113
  • 30
  • 216
  • 245
Thomas Owens
  • 114,398
  • 98
  • 311
  • 431
1

I prefer to use the Code Analysis in IntelliJ. It not only finds many probable bugs and improvement but has quick fixes for a lot them which makes it practical to fix large amounts of code.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • does it also shows standard naming convention as well? – amod Sep 06 '11 at 14:17
  • 1
    Standard naming conversions with quick fixes as well. i.e. if a `public static final` is in camelCase, it highlights (or it appears in a report) and gives you the option to rename it to UPPER_CASE changing all the references (even in comments, String and files) – Peter Lawrey Sep 06 '11 at 14:24
0

use a compiler to find syntax 'bugs'

use test cases to find usability 'bugs'

use test harnesses in the code to find regression issues with code modifications.

Randy
  • 16,480
  • 1
  • 37
  • 55