How do I monitor a variable when running a program?

   I have a program that I am debugging.  I would like to run the program and monitor what is stored in a particular object while the program runs but do not want to insert breakpoints.  Is there a way to do this in NetBeans 6.1?

Who is Participating?
Kevin CrossConnect With a Mentor Chief Technology OfficerCommented:
You mean aside from adding breakpoints and using the debug view?  Think you can profile the code:  Not sure that is what you are looking for, but those are the options I know of in NetBeans.
Kevin CrossChief Technology OfficerCommented:
Hello pbenito,

Click on the debug main project button or right-click on java file containing a public static void main class and select debug from the context menu -- this will bring you to the debug view and stop at breakpoint(s) you specified.  While stopped on a breakpoint or line of code as you step through code, you can hover over a variable and see its current value.  There will also be a pane usually bottom right of screen that has tab that says local variables that you can click on Object values that have been defined to this point.

Hopefully that helps.

Best regards,

pbenitoAuthor Commented:
Thanks - I am looking for a way to monitor the variable or object without establishing breakpoint(s).  Is there anyway to do this?
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Kevin CrossChief Technology OfficerCommented:
You mean debug code while in use.  You could add a verbose switch or I guess if this is what you want make your application verbose all the time -- when in verbose mode, simply trace the value of the variable at moments you are wanting to know its value to a log file or standard output.
pbenitoAuthor Commented:
Thanks - pardon my ignorance, but how do I add a verbose switch?
Kevin CrossChief Technology OfficerCommented:
:) Code logic.

You don't even need one was my point.  I was saying, you can make your program verbose (meaning displays a lot of information in log, etc.) by adding System.out.println() statements or logging to file in code wherever you want it.

What I do is usually have a parameter or command line switch for my program that indicates debug mode.

For objects I want this kind of tracing, I have a variable:
boolean debug = false;

And if I turn on debug, this gets changed to true, then in code I have this:

if (debug) {
    // log something
pbenitoAuthor Commented:
Thanks - is there another way to do this without introducing code into my baseline using NetBeans?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.