Debugging skills 101 for java developer

Debugging skills 101 for java developer

In today's software development short cycles and the increase of complexity of the product and architecture, analyzing and debugging on development environment and on production environment has become a critical impact on the high quality demand of a product.

This article will introduce debugging skills which every developer should add to his skill set tools.

IDE debugger knowledge:

No matter what is your favorite IDE, every IDE has the following debugging abilities

  1. Breakpoint - Allows you to specify in the code a point that when reached there is a temporary halt in the program which stops the automatic execution and starts a manually and step by step execution of each line of code. By doing so, we can analyze a specific logic and data and correct it if needed.
  2. Conditional Breakpoint - Like breakpoint, the conditional breakpoint also temporarily halts the program and stops the automatic execution, but with one difference, we can specify a condition along with the breakpoint. This feature may come in handy in many cases when the code gets a lot of input or loop over some data and you want your breakpoint to kick-in only when the condition is valid. For example, let's say that you iterate over a list of 1000 objects and you want to debug the code on the 800 objects or maybe on the one with specific id? if you will use regular breakpoint … well, try it and you’ll understand.
  3. Code evaluation/execution - This allows you to execute some code and even modify some values while you're in debug mode on a breakpoint.
  4. 3rd party libraries debugging, just download the source - sometimes 3rd party libraries may have bugs and sometimes we just do not use them correctly. If you use open source you can just attach their code and debug them like it was your own code for non-open source libraries you can use decompile plugin or other use methods(log level changes ...)
  5. Remote server debugging - Some times you will need to debug a remote server, each server may require a different procedure to do so, some use agent that should start with the server and some uses jdwp (java debug wire protocol), Nevertheless, you should remember that it can be done and mostly recommended with conditional breakpoint unless you are the only one that is using the server.

Logging:

Log is one of most important debug and failure detection tools we have, especially on production. 

  1. Write informative log, it will come handy in hard times.
  2. Log level changes - you can change the log level to DEBUG at least on the component that is failing and get more informative logs. Log level can be changed in many ways without restarting the application, for example you can change it using JMX.

      Make sure that when writing log messages, you should use the right log level code for each message.

SQL server log

In case you what to check what is the query that is being executed in the DB you can breakpoint just before you execute it or even change your logging  level on the connector layer but also you can easily enable the DB logging, for example, in MySQL, just execute the following commands:

SET global general_log = 1;

SET global log_output = 'table';

and you can query the log

select * from mysql.general_log

you can disable it with the following:

SET global general_log = 0;

Java thread dump

You can get thread dump from the jvm and analyze it using jVisualVM or any other tool.

The thread dump gives a snapshot of the threads and their statuses(new,runnable {blocked,waiting,timed_waiting},terminated) and stack trace, therefore, you must take a few of them to understand the thread status and to be able to analyze it.

See https://dzone.com/articles/how-analyze-java-thread-dumps for more details 

Profiling tools, Monitoring and JMX

Many profiling tools and monitoring tools can be used to get more info on the machine and the application status.

From architecture aspect, java defined a standard for management and monitoring - JMX, it can be easily exposed and give realtime information and management actions.

JMX can be accessed via many jmx clients with their own access rights and credentials.

תודה רבה לך על השיתוף🙂 אני מזמינה אותך לקבוצה שלי: הקבוצה מחברת בין ישראלים ואנשי העולם במגוון תחומים. https://chat.whatsapp.com/BubG8iFDe2bHHWkNYiboeU

Like
Reply

nice very much useful.. devs should follow it :)

To view or add a comment, sign in

More articles by Ran Brandes

  • From Idea to Production - AI 1st

    How I built a full-stack project using an AI-first workflow 🚀 I recently took a project from initial requirements to a…

  • Supercharging UI/UX Debugging with Playwright MCP and Claude

    As we're constantly looking for ways to help our teams work smarter, not harder. I want to share a game-changing…

    4 Comments
  • The Power of Multi-Timezone Teams

    Its not a new concept - but we sometime do not take the advantages it gives us. Working with a team spread across…

  • Journey in technological revolutions and feelings

    Looking back, software feels less like “technology” and more like a series of belief systems — each decade worshipping…

  • From zero to Hero : Extracting text from image

    OCR (optical character recognition) is not a new concept, these days you can run a POC very quickly by using OCR…

    3 Comments

Others also viewed

Explore content categories