Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Java Debugging Checklist

DZone's Guide to

Java Debugging Checklist

It's not your library or JDK, it's you.

· Java Zone ·
Free Resource

Get the Edge with a Professional Java IDE. 30-day free trial.

Debugging is mostly used when an application is not behaving as expected, and every developer should learn how to use it. However, it requires a lot of time to master it. Fortunately, Java provides tools as part of the JDK (for example, jstack), and there are third-party tools, such as JMeter, that can help us. There is also a very good integration with IDEs, such as IntelliJ or Eclipse, so it is very important to know how to use the debugging features of our favorite IDE. In order to speed up this learning process, we can follow these guidelines:

  • Do not be afraid of reading code, especially if the code is from others. We should go as deep as we can to understand what is really happening under the hood.
  • Do not blame the JDK or libraries. And, never assume that Java is broken, because probability is always against you. 99 percent of the time, the bug is in something you coded.
  • Make assumptions, but do not trust yourself, because we might create blind spots.
  • Walk away from the problem and come back when you are fresh (work out, go to bed, meet your friends — just take a break).
  • Do not program by coincidence, or in other words, do not try code without knowing what you are doing.
  • Google is your best coding friend.
  • Check the JDK javadoc when you are not sure about how a Java feature works.
  • Use proper log levels (info, warn, error, debug).
  • Use breakpoints to have a full view of the program on a particular point of our application. Conditions on breakpoints are also very useful when we are debugging a loop with thousands of values.
  • Use tools such as JMeter for load testing or jstack to capture thread dumps.
  • Have a remote debugger for your applications deployed on dev and pre-production environments.
  • If we are not able to find the source of the issue by any of the previous guidelines; firstly, start eliminating code; secondly, check your environment; and thirdly, check libraries.

Debugging is a difficult skill to master, and practice makes perfect. So, start building your debugging skills as soon as possible!

Get the Java IDE that understands code & makes developing enjoyable. Level up your code with IntelliJ IDEA. Download the free trial.

Topics:
java ,debugging ,jdk ,jmeter ,jstack ,code

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}