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
相关推荐
### Java Debug技巧:Eclipse高级调试指南 #### 一、引言 在软件开发过程中,调试是必不可少的一个环节。良好的调试技巧能够显著提高问题定位的速度和准确性,从而提升整体的开发效率。Eclipse作为一款非常受欢迎...
### Java使用Debug及开发者工具快速定位系统Bug #### 前言 在软件开发过程中,无论是维护自身构建的系统还是接手前人遗留的项目,都不可避免地会遇到各种Bug。对于初学者而言,掌握如何有效地定位和修复这些Bug至...
### Eclipse的Debug介绍与技巧 #### 一、Eclipse调试介绍 在软件开发的过程中,调试是必不可少的一个环节。几乎所有的程序开发都会面临错误排查的问题,因此掌握高效的调试技巧至关重要。Eclipse作为一款广泛使用...
在编程世界中,Eclipse是一款广泛使用的开源集成开发环境(IDE),尤其对于Java开发者来说,它提供了丰富的功能和工具。本文将深入探讨Eclipse的调试技巧,帮助您从入门到熟练掌握Eclipse的Debug功能。 首先,让...
1. **JDK Debug工具**:Java Development Kit(JDK)内含强大的Java调试工具集(JDB),它是命令行工具,适用于基础的远程和本地调试。学习如何配置JDB,并使用其基本命令如`step`、`next`、`print`等进行单步执行、...
9. 分析内存和性能:Eclipse的debug工具还包括了对内存使用的分析,可以通过“Memory”视图来检查和分析对象的内存使用情况,这有助于发现内存泄漏等问题。 10. 快捷键的使用:Eclipse提供了一系列快捷键以简化...
通过使用Eclipse的Debug工具,开发者可以更加高效地定位问题所在,并进行修复。 #### 二、使用Debug模式启动Web Server 1. **准备工作**:首先确保你的项目已经正确配置在Eclipse环境中,并且具备运行条件。对于...
【Eclipse Debug调试技巧详解】 Eclipse作为一款强大的Java集成开发环境,其强大的调试功能是开发者不可或缺的工具。本文将详细介绍Eclipse中的调试视图及其常用功能,帮助开发者提升调试效率。 1. **Debug视图** ...
**使用Java Debug Interface (JDI)** 对于更复杂的调试需求,可以利用Java Debug Interface (JDI)。JDI是Java虚拟机工具接口的一部分,允许开发者创建自己的调试工具。通过JDI,你可以设置断点、检查变量、控制程序...
Java提供了多种内置的调试机制和工具,如JDB(Java Debugger)、JDWP(Java Debug Wire Protocol)等,使得开发者能够轻松地对程序进行调试。 #### 调试的重要性 1. **错误定位**:帮助快速定位代码中的错误。 2. *...
- 使用`Debug As > Java Application`选项来启动调试会话。 **2. 基本调试命令:** - **F5 (Step Into)**:此命令用于进入当前执行的方法内部,如果该方法是一个调用,则会进入被调用方法的内部。 - **F6 (Step...
本文将详细讲解Eclipse中Debug视图的功能及其使用技巧。 #### 二、常用调试视图 ##### 1. Debug View(线程堆栈视图) Debug视图是Eclipse调试功能的核心,它提供了对正在运行和调试的程序的全面管理。在Debug...
Eclipse允许在Debug视图的Variables面板中,通过右键点击变量并选择“Change Value...”,来修改变量的值并立即应用。这使得开发者可以测试代码在不同情况下的行为。 有时候,开发者可能需要回退到程序执行的某个...
以下是一些从博客文章"Java实际开发中的小技巧汇总"中可能涵盖的知识点,结合“源码”和“工具”的标签,我们可以探讨以下几个方面: 1. **异常处理**:在Java中,正确地捕获和处理异常是非常关键的。避免在catch块...
然而,开发过程中有时需要对WAR包中的代码进行调试,这就涉及到一些特定的技巧和工具。 首先,理解WAR包的结构至关重要。WAR文件是ZIP格式的压缩包,包含了一个完整的Web应用程序的所有资源,如Java类、JSP页面、...
总之,掌握有效的JavaScript调试技巧和工具,是成为一名高效、专业的前端开发者的关键。通过深入理解"Microsoft Script Debugger"以及类似的调试工具,开发者能够更好地排查问题,提高代码质量和开发效率。
- 打开 `Window > Preferences > Java > Debug > Step Filtering` - 在列表中添加不希望单步执行的类或包名称。 - 设置完成后,当进行单步调试时,Eclipse会自动跳过这些类或方法。 **2. Resume (resume)** Resume...
### Android Studio (IDEA) Debug技巧详解 #### 一、概览 在软件开发过程中,调试是必不可少的一个环节。良好的调试技巧能够显著提高开发效率,帮助开发者更快地定位并解决问题。本文将详细介绍Android Studio...