Java 这种半解释半编译语言,他的调试工具应该是不比强大的,做成Javaer 应该精通使用它。
http://javarevisited.blogspot.com/2011/07/java-debugging-tutorial-example-tips.html
1) Use conditional breakpoint
Eclipse allows you to setup conditional break point for debugging java program, which is a breakpoint with condition and your thread will only stop at specified line if condition matches instead of just stopping on that line like in case of line breakpoint. To setup a conditional breakpoint just double click on any line where you want to setup a breakpoint and then right click --> properties and then insert the condition. Now program will only stop when that particular condition is true and program is running on debug mode.
2) Use Exception breakpoint
How many times you have frustrated with a NullPointerException and you don't know the source from where the exception is coming. Exception breakpoints are just made for such situation. Both Eclipse and Netbeans allows you to setup Exception breakpoint. You can setup Exception breakpoint based on java exception like NullPointerException or ArrayIndexOutOfBoundException. You can setup Exception breakpoint from breakpoint window and your program will stop when you start it on debug mode and exception occurs.
3) Step over, Step Into
These are simply great debugging options available in any Java IDE, extremely useful if you are debugging multi-threaded application and want to navigate step by step.
4) Stopping for a particular Thread
This is my own custom made java debugging tips which I made using conditional breakpoints. since most of my projects are multi-threaded java programs and I want only a particular thread to stop on a particular line, for doing that I setup a conditional breakpoint on that line and put Thread.currentThread().getName().equals("TestingThread") and it works fantastically.
5) Inspect and Watch
These are two menu options which I use to see the value of expression during debugging java program. I just select the statement, right click and inspect and it will show you the value of that statement at debugging time. You can also put watch on that and that condition and its value will appear on watch window.
6) Suspending and resuming thread
You can suspend and resume any thread while debugging java program from debug window. Just right click on any thread and select either suspends or resume. This is also very useful while debugging multi-threading program and simulating race conditions.
7) Using logical structure
Logical structure option is very useful for examining contents inside java collection classes like java hasmap or Java Arraylist during java debugging. Logical view will show the contents like key and value of hashmap instead of showing full details of hashmap which we may not be interested, you can enable and disable logical view from variables window.
8) Step filtering
When we do Step Into on process debugging java program control goes form one class to other and it eventually go to JDK classes like System or String. Some time we just to remain in our application and don't want to navigate into JDK System classes in that case Step filtering is great you can just filter out JDK class from Step into. You can setup step filtering from preferences àJavaàDebugàStep Filtering and enable and disable it from Debug window.
9) Copy Stack
While debugging java program if you want to copy the stack of a thread which hit the breakpoint and suspended you do so by "Copy Stack" option. Just right click on Thread on Debug Window and select "Copy Stack".
10) Last tip is use java debugging as last option and not the first option because it’s very time consuming, especially remote java debugging which takes a lot of time if network latency is very high between local and remote host. Try to identify problem by looking at code it would be very handy and quick.
Read more: http://javarevisited.blogspot.com/2011/07/java-debugging-tutorial-example-tips.html#ixzz2UjfGhnT1