Netbeans has a tabbed window in the Output section called "Debugger Console". Is it possible to write a message to this window using Java? If so, how?
The messages you see in the debugger console are either
When you add a breakpoint to a line of code, the default behavior of the breakpoint is to suspend the thread that executed the line of code, and to print the text "Breakpoint hit at line {lineNumber} in class {className} by thread {threadName}."
.
You can configure a breakpoint to print a custom text. This text will be output in the debugger console when it reaches the breakpoint. To do so, right click on a breakpoint, open the propoerties window, and enter your text in the field Print text
.
A useful trick is to configure a breakpoint so that it does not block (suspend : no thread
), and to enter a text. The effect is the same than adding println
lines in your code, but the benefit is that you don't have to recompile the code, and it's easier to activate/deactivate these debugger logs (and it obviously does not stay on production code).
Note that, in the text of the breakpoint, you can use one of the special values {lineNumber}
, {methodName}
, {className}
or {threadName}
, and you can also evaluate some code with the syntax {=xxx}
. Just replace xxx with a variable name, or a method call, or whatever.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With