Reputation: 129
What's the difference between the debug button and the run button in eclipse? I'm currently working on 2D games with java, but I realized that I'm not entirely sure whether I should click debug or run. Is there an advantage to using one over the other?
Thanks!
Upvotes: 0
Views: 1183
Reputation: 6980
Run and debug are two totally different animals. If you do not know what the debug button does then you should be hitting the run button as debug will drastically slow down your program testing.
Now you might ask, but I want to use the debugger. Okay here is a simple way to demonstrate the usefulness of the debugger. Place this code in a new project in Eclipse.
int n = 0;
for(int i = 0; i<10;i++)
{
System.out.println("I am printing "+n++);
}
Click on the int = 0; line and press CTRL+SHIFT+B you will notice a small dot will appear to the left of the line. Then run as debug and it will stop your program at this point. From here you can keep pressing f6 to "step through" your program. You can toggle breakpoints wherever you want.
Then press Window > Show View > Other and type Variables, select that. In the new box that pops up you will see buttons on the top click the one that says Open New View when you highlight it
This will open up a variable window that will show you the variables in the part of the program you are stepping through After you press f6 two or three times with my example above you should get this.. Not only can you see the variables change as you press f6 but you can actually double click on the value column and change the values in run-time to ask what if questions.
Upvotes: 2
Reputation: 3797
Debug will execute a lot slower than a regular Run. Eclipse will only recognize breakpoints when you are running in Debug. You should use Debug when you are testing your game.
You can also look at variables in real time while you are debugging. You can pause execution and you can look at all running threads, it is really quite useful when it is used properly.
Here is a pretty good tutorial on debugging if you are interested:
Upvotes: 4