Results 1 to 7 of 7

Thread: Debugging Java

  1. #1
    pifrely is offline Member
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default 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?

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default 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?

  3. #3
    pifrely is offline Member
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default 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.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,225
    Rep Power
    20

    Default 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 **

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default 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.

  6. #6
    pifrely is offline Member
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default 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)?

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,225
    Rep Power
    20

    Default Re: Debugging Java

    I wouldn't worry too much about profiling at the moment of you're new.
    But if you want to dabble then just pick the one with the prettier interface...:)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Java Debugging Help
    By whitedragon551 in forum New To Java
    Replies: 3
    Last Post: 11-19-2012, 12:58 AM
  2. Replies: 1
    Last Post: 07-31-2007, 01:39 PM
  3. Debugging Java Application in Eclipse IDE
    By JavaForums in forum Eclipse
    Replies: 0
    Last Post: 05-22-2007, 10:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •