Results 1 to 7 of 7
Thread: Debugging Java
- 01-19-2013, 01:54 AM #1
Member
- Join Date
- Jan 2013
- Posts
- 10
- Rep Power
- 0
Debugging Java
Hi, I know that System.out.println and IDEs can help with debugging. But I'm wondering if there's also another way to debug my programs...
Having used AutoHotkey before in the past, I know that there's a command you can use (OutputDebug) where you can output a line to a debugger like DebugView, and that line shows up in the debugger program, along with other data like timestamp and which program sent the line. Is there any such way to do this in Java?
- 01-20-2013, 08:53 PM #2
Re: Debugging Java
You can hook into a running JVM and do remote debugging - but if you have access to the running code locally, using an IDE's line by line debugger really is the simplest and most useful tool. You can get the contents of variables at runtime - most IDEs even support hot code changes.
What exactly are you trying to do that an IDE debugger doesn't?
- 01-22-2013, 06:46 PM #3
Member
- Join Date
- Jan 2013
- Posts
- 10
- Rep Power
- 0
Re: Debugging Java
I'm trying to make a small game that runs in real time. I'm afraid that because it runs like that, it might be more difficult to debug using the line-by-line debugger. So the next best thing (if I encounter such a problem) would then be to print out a log of events that occurred, I suppose.
- 01-22-2013, 07:12 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: Debugging Java
You'll want to do both.
Log stuff using a logging framework (Java comes with one, see LogManager).
The logging will point you to problems in narrower areas of your code...debugging then lets you step through the relevant bits to see exactly what's happening.
You can also set the logging level to increase the detail logged, but you do actually need the logging lines in the code in the first place.Please do not ask for code as refusal often offends.
** This space for rent **
- 01-22-2013, 08:33 PM #5
Re: Debugging Java
You can also collect real time JVM statistics - most IDE's have easy 1 click profiling built in. The java profiling tools are great for real time games - they won't tell you why something doesn't work, but they will tell you which method is eating up 300ms on every frame redraw. When I wrote a duck hunt clone in college (which supported hundreds of ducks, collision detection, and guns that spray bullets and decals everywhere) this profiling was essential to getting my frame rates up to acceptable levels.
Using an IDE debugger (even with real time input) can be great - for instance, lets say you want to see what happens when you click a character on your play field. You toss in a break statement in your event handler, and as soon as you click, your game execution will freeze, and your IDE will give you line by line code inspection. When you're done with your inspection, you can clear your break point and game execution returns to full speed.
I used this technique extensively when making particle simulations and developing a quad tree data structure to handle the collision detection - I needed to debug the behavior of the tree for a real time sim, the break points 'paused' the real time execution so I could inspect at my leisure and then jump right back into the action action when I was done.
- 01-22-2013, 10:03 PM #6
Member
- Join Date
- Jan 2013
- Posts
- 10
- Rep Power
- 0
Re: Debugging Java
Hmm, I see. Then I'll use LogManager as well as the break points whenever it seems most appropriate. Profiling also seems interesting too; I'm always worried about how well my program will perform. However, upon googling "Eclipse profiling", I found that there's a bunch of different ones I can use like TPTP or jvisualvm. Which one would be good for a first-timer (or perhaps, just good in general)?
- 01-23-2013, 10:47 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Similar Threads
-
Java Debugging Help
By whitedragon551 in forum New To JavaReplies: 3Last Post: 11-19-2012, 12:58 AM -
Could anyone help me in debugging my Java Program.
By zoe in forum New To JavaReplies: 1Last Post: 07-31-2007, 01:39 PM -
Debugging Java Application in Eclipse IDE
By JavaForums in forum EclipseReplies: 0Last Post: 05-22-2007, 10:34 PM
Bookmarks