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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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?
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.
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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?
Kevin CrossChief 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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.