An Oracle JDeveloper How To Document
Written by Shay Shmeltzer, Oracle Corporation
October, 2004
Introduction
Debugging is probably the activity that Java developers spend the most time on (right after coding and drinking coffee/cola). While there are many Java debugger out there, JDeveloper's debugger isn't "just another debugger". In fact the debugger in JDeveloper has some tricks up-its-sleeve that you won't find in other debuggers.
In this article will look at some of these and guide you through using them.
1. Track only variables that matter
A Java program can have hundreds of variables and parameters. When debugging
your code, however, you are usually interested in just some of these variables.
This is what the "smart-data" window automatically does for you. It
analyzes the source code at the point where you are and finds the variables,
fields and expressions that are used at this area. You can always see the full
list of variables in the Data tab. You can set the scope that smart data analyzes
in the code debugger preferences entry.
In the screenshot you can see that while in the loop only the i,a, and my_str
variables are shown. The other strings and the arguments to the method are not
shown.
2. Setting Next Execution Point
Don't you whish sometimes you could turn back time? Well the JDeveloper debugger
let you do just that. No matter where you are in the code while debugging, if
you want to go back to a statement you already passed, just place the cursor
there, right click and choose "Set Next Statement".
Another sample of when this feature can become useful is if you did a step-over
and you actually wanted to do step into. Just set the next statement to be the
method call and do "step-in". By the way, you can also skip code execution
by placing the curser after that code section.
3. Advanced Breakpoints.
In JDeveloper a breakpoint doesn't have to mean you are stopping execution,
you can tell a breakpoint to do something else. For example one breakpoint can
enable another breakpoint. An example of when such a thing will be useful is
when you only want to break in one area (will call this B) if another area (we'll
call this A) was executed first. To do this show your breakpoint window (CTRL+Shift+R).
Right click on the B breakpoint and set the "Breakpoint Group Name"
for it.
Then edit the A breakpoint - in the action-tab uncheck the "Halt Execution"
checkbox, and set the "Enable a Group of Breakpoints" to the name
you specified for B.
4. Monitor Your Memory Allocations
Sometime you want to know what is going on in your Java Heap, this is helpful
utility when you are looking to find out if you have memory leaks. The debugger's
classes window (View->Debugger->classes menu option) gives you a look
into the heap, showing you which classes (and how many instances of each one)
are currently in the heap. If you are noticing too many instances you might
want to force a garbage collection action. To do this simply choose the Debug->Garbage
Collect menu option.
If you need a deeper look into what is the source of each instance, right click
on the class and choose Display in Heap. The heap window that comes up shows
you all the objects of this specific class. When you have identified a problematic
object in this window you can right click on it and choose Show Reference Paths,
this will show you the roots of the object.
Conclusion
The Debugger in Oracle JDeveloper offers many utilities that can make your
development experience easier. To learn more about the powerful Oracle JDeveloper
Debugger check out the online help section : Working with Application Design
Tools >
Building and Tuning Applications > Debugging
in JDeveloper.