Thursday 31 October 2013

System.out.println Debugging


Who hasn't done the following? Adding appropriate System.out.println statements to your code, in order to actually see what is going on.

I admit to using it once or twice. I must even admit that once or twice I've managed to accidentally check my printlns in.

I found the following Small Gem in the Tips and Tricks of Eclipse[1].

A picture of the properties of a breakpoint in Eclipse is available to the left.

I'm going to assume that a similar trick can be used in other IDEs.

Some special notes about the breakpoint:
  • it's conditional
  • it will only suspend execution when the condition evaluates to true
  • the condition will always evaluate to false
  • conclusion: the breakpoint will never suspend execution
  • it contains System.out.println statements

In effect, we have created a System.out.println statement, without actually changing the code.

This has certain advantages:
  • Debugging code isn't actually checked in by accident
  • You do not actually need to have the source code or to deploy anything to get the print statements
Already it is being used at my workplace by the Helpdesk for easy access to which SQL queries are sent to the database.

References

[1] Tips and Tricks (JDT) (Java Development Tools
Eclipse Java development user guide

No comments:

Post a Comment