1

Is there a way in NetBeans that while you are debugging a Java program to modify or check the value that a function or variable returns. The same way you can use the console in Matlab.

I'm not speaking about the usual debugging tools variable windows etc.

Example I want to break at a method in car class and input

>car.getMileage()

and get..

>car.getMileage()
>2500

or

>car.setMileage(100)
>car.getMileage()
>100
4
  • 1
    Other than doing System.out.println(...); at that moment? Commented May 1, 2014 at 20:27
  • Yeah, I want it dynamic. Commented May 1, 2014 at 20:28
  • @user758114 try a Logger or a debugger. Commented May 1, 2014 at 20:30
  • 1
    Java is not entirely an interpreted language so this probably doesn't exist. Commented May 1, 2014 at 20:32

2 Answers 2

5

In Netbeans there is a tab under your source code window (there by default I think) called Variables. In that window you can edit the Value field of any variable that is in scope while suspended at a breakpoint. This value should update for the java application as you change it in real time. You can invoke methods the same way, by adding a watch. Like say you had a static method getInt(); which returns some value. Just make a watch for getInt(), and the Value column will show you the return value. So for your example, make a watch for car.setMileage(100) after your breakpoint is hit. The value column will likely be 'void'. Then make another watch for car.getMileage(). 100 should be returned.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 I use it as well. But general demand is in a more convenient way - like Chrome Javascript Console. Netbeans Console unfortunately allows typing, not code execution.
1

Use an IDE such as Eclipse. You can set breakpoints, set statements and execute them. This is a feature of most modern IDEs actually.

More info on the display view can be found here : http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.jdt.doc.user/reference/views/debug/ref-debug_view.htm

For a nice overview of the debugging features of Eclipse, check out this post : http://www.cavdar.net/2008/09/13/5-tips-for-debugging-java-code-in-eclipse/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.