[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do I monitor a variable when running a program?

Posted on 2008-11-06
7
Medium Priority
?
237 Views
Last Modified: 2013-12-14
Hi,
 
   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?

Thanks!
0
Comment
Question by:pbenito
  • 4
  • 3
7 Comments
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22901983
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,

mwvisa1
0
 

Author Comment

by:pbenito
ID: 22904004
Thanks - I am looking for a way to monitor the variable or object without establishing breakpoint(s).  Is there anyway to do this?
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22904204
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.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:pbenito
ID: 22904239
Thanks - pardon my ignorance, but how do I add a verbose switch?
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22904879
:) 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
}
0
 

Author Comment

by:pbenito
ID: 22922928
Thanks - is there another way to do this without introducing code into my baseline using NetBeans?
0
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 1500 total points
ID: 22923429
You mean aside from adding breakpoints and using the debug view?  Think you can profile the code: http://profiler.netbeans.org/.  Not sure that is what you are looking for, but those are the options I know of in NetBeans.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question