user758114
user758114

Reputation: 354

Debugging console input using NetBeans

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

Upvotes: 1

Views: 2794

Answers (2)

Mark W
Mark W

Reputation: 2803

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.

Upvotes: 5

user2591612
user2591612

Reputation:

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/

Upvotes: 1

Related Questions