Top 10 Java Debugging Tips with Eclipse
In this tutorial we will see about debugging java applications using Eclipse. Debugging helps us to identify and fix defects in the application. We will focus on run-time issues and not compile time errors. There are command line debuggers like gdb available. In this tutorial we will focus on GUI based debugger and we take our favourite IDE Eclipse to run through the tutorial. Though we say Eclipse, the points are mostly generic and is suitable for debugging using most of the IDEs like NetBeans too.
Before going through this tutorial, I recommend you to have a look at Eclipse shortcuts and it will really help. My Eclipse version is Juno as of writing this tutorial.
- Do not use System.out.println as a tool to debug.
- Enable detailed log level of all the components involved.
- Use a log analyzer to read logs.
1. Conditional Breakpoint
Hope we know how to add a breakpoint. If not, just click on the left pane (just before the line number) and a breakpoint will be created. In debug perspective, ‘Breakpoints’ view will list the breakpoint created. We can add a boolean condition to it. That is, the breakpoint will be activated and execution will hold only if the boolean condition is met otherwise this breakpoint will be skipped.

2. Exception Breakpoint
In Breakpoints view there is a button labeled as J! We can use that button to add a java exception based breakpoint. For example we want the program to halt and allow to debug when a NullPointerException is thrown we can add a breakpoint using this.

3. Watch Point
This is one nice feature I love. When a chosen attribute is accessed or modified program execution will halt and allow to debug. Select a class variable in Outline view and from its context menu select Toggle Watchpoint. This will create a watch point for that attribute and it will be listed in Breakpoints view.

4. Evaluation (Display or Inspect or Watch)
Ctrl+Shift+d or Ctrl+Shift+i on a selected variable or expression
will show the value. We can also add a permanent watch on an
expression/variable which will be shown in Expressions view when debug
is on.

5. Change Variable Values
We can change the value of a variable on the fly during debug. Choose
a variable and go to Variables view and select the value, type and
enter.

6. Stop in Main
In Run/Debug Settings, Edit Configuration we can enable a check box
that says Stop in main. If enabled when we debug a java program that
launches with a main method, the execution halts at first line of main
method.

7. Environment Variables
Instead of going to System properties to add an environment variable,
we can conveniently add it through Edit Configuration dialog box.

8. Drop to Frame
This is the second best feature I love. We can just return the
control to any frame in the call stack during debug. Changes made to
variables will not be reset. Choose the stack level which you want to go
back and restart debug from there and click the drop to frame button
from debug toolbar. Eclipse is cool!

9. Step Filter
When we Step Into (F5) a method we may go into external libraries
(like java) and we may not need it. We can add a filter in preferences
and exclude packages.

10. Step Into, Over and Return
I kept this as the last point as this is the first thing to learn in debugging :-)
- F5 – Step Into: moves to next step and if the current line has a
method call the control will go into the first line of the called
method. - F6 – Step Over: moves the control to next line. If there is a method
call in the current line, it executes the method call internally and
just moves the control to next line. - F7 – Step Return: When done from inside a method the control will
move to the calling line from where the current method is invoked. - F8 – Move to next breakpoint.

This Core Java tutorial was added on 30/08/2012.
Top 10 Java Debugging Tips with Eclipse的更多相关文章
- Top 10 Methods for Java Arrays
作者:X Wang 出处:http://www.programcreek.com/2013/09/top-10-methods-for-java-arrays/ 转载文章,转载请注明作者和出处 The ...
- Top 10 Questions about Java Exceptions--reference
reference from:http://www.programcreek.com/2013/10/top-10-questions-about-java-exceptions/ This arti ...
- Top 10 Mistakes Java Developers Make--reference
This list summarizes the top 10 mistakes that Java developers frequently make. #1. Convert Array to ...
- Top 10 Mistakes Java Developers Make(转)
文章列出了Java开发者最常犯的是个错误. 1.将数组转换为ArrayList 为了将数组转换为ArrayList,开发者经常会这样做: ? 1 List<String> list = A ...
- Java Debugging with Eclipse - Tutorial
1.1. What is debugging? Debugging allows you to run a program interactively while watching the sourc ...
- 【翻译】Java Array的排名前十方法(Top 10 Methods for Java Arrays)
这里列举了Java Array 的前十的方法.他们在stackoverflow最大投票的问题. The following are top 10 methods for Java Array. The ...
- TOP 10 ONLINE COMPILER
Top 10 Online Compilers +1338 Tweet Share106 Share Pin 444 Shares Online compilers are one type of t ...
- TOP 10开源的推荐系统简介
最近这两年推荐系统特别火,本文搜集整理了一些比较好的开源推荐系统,即有轻量级的适用于做研究的SVDFeature.LibMF.LibFM等,也有重量级的适用于工业系统的 Mahout.Oryx.Eas ...
- Top 10 Algorithms for Coding Interview--reference
By X Wang Update History:Web Version latest update: 4/6/2014PDF Version latest update: 1/16/2014 The ...
随机推荐
- 如何改app图标名称
InfoPlist.strings文件里写上: CFBundleDisplayName="中文名字";
- 设置appicon和启动图
设置appicon General – App Icon Source 设置AppIcon 图片大小 iphone 6P(@3x) 180x180 iphone 6(@2x) iphone5/5s ( ...
- jQuery分析(1) - 介绍
前言 web技术高速发展到现在已经出了现非常多的库或框架,库或框架实现方法也是五花八门.现在要实现一个web站点只需要根据自己的业务需求选择js框架即可快速完成.有些框架可以快速满足业务需求,但是有些 ...
- cell的循环使用
cell的循环利用:(对cell的简单优化) 1.创建一个标示(Identifier),用于区分缓存池里的不同cell. 2.去缓存池里拿自己对应的cell,用到dequeueReusableCell ...
- USACO 2.2 Subset Sums 集合(subset)
Description 对于从1到N的连续整集合,能划分成两个子集合,且保证每个集合的数字和是相等的.举个例子,如果N=3,对于{1,2,3}能划分成两个子集合,他们每个的所有数字和是相等的: {3} ...
- CSS鼠标点击式变化图片透明度
今天分享前端代码主题:jequery控制css图片透明度 很多时候在网站图片处理上需要实现一些辅助效果,比如鼠标在图片上滑动时或点击时改变图片颜色(变灰或者其他),其实一个简单的办法就是改变图片css ...
- js 中的流程控制—while和do while
while语句: while(exp){ }如果为true ,执行代码块里的语句,如果为false,跳出循环 <script> var i =1 ; while (i<10){ / ...
- 把AS代码链接到fla文件
在属性里找到类,输入AS脚本的文件名然后点击右边的编辑就可以打开编辑AS脚本的界面,下面为链接代码. package { import flash.display.MovieClip; public ...
- php生成二维码
<?php $urlToEncode="163.com"; generateQRfromGoogle($urlToEncode); function generate ...
- PHP代码分离
所谓的代码分离 其实只是一种思路,既然是一种思路 那就意味着他是有需求的 没有需求就没有解决方案 没有方案就不存在思路. 在这之前,我们制作 PHP 程序页面的时候.都是 HTML 和 PHP 混合写 ...