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.
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.
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.
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.
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.
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.
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.
Instead of going to System properties to add an environment variable, we can conveniently add it through Edit Configuration dialog box.
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!
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.
I kept this as the last point as this is the first thing to learn in debugging :-)
Comments are closed for "Top 10 Java Debugging Tips with Eclipse".
Very useful Indeed!
Thank you very much.
thanx,
joe
Sir, keep writing such wonderfull tutorials.
Nice one.
Can you write a IDEA version?
thanks you for detail inforamation in one place
This is what looking what long time, it’s really very good tutorial..
Please explain servlet and jsp’s debbuging using live example as above.
Thanks Joe…
Very useful , every developer should know these things.
justt…..awesome
could u explain clearly about API and Package
Very well written
You are simply Superb
Super…..Jeo
thanks joe…very well written.. your passion helps us..
Respected Sir,
First I Thank you so much sir your website very useful to me.
I am asking my doubts but i don’t know how to tell to you. Q1)How to input more than value at a time?. please give me example.
Good work Joe.. Please keep it up.
Thanks JoeSir,
it,s very useful and easy to understand like it
Nice Job. Keep going
Very useful information.. Nice keep send more information’s
Thanks,
Anandan R
Awesome , Whenever I read your articles I really learn new thing, great…
Very use full information send me more information
thank u
Sankar svs
Great information, thank you
Nice post and Well Explained.Thank You
Getting more information. Please keep post such information. Thanks
Really Helpful…Thanks
really use full, and simple
Thank you very much…
serious gud one
very interesting post. As a developer should know these techniques of debugging.
Really cool tips….
Really good one…
nice article
Hi Joe,
Thanks for your valuable input on the Eclipse IDE.
It is really good.
keep the good work.
Useful tips.
Have you ever tried debugging xqueries in eclipse?
Please write something if you know something related.
thanks man…. i dont know 8 out of 10 you posts. must catch up on my eclipse skills
superb Joe…
great work .. thanks for the much needed help in eclipse debugging
thanks! Just what I was looking for.
Brilliant! Thanks a lot…
thanks
Thank You Joe. Very useful, concise and to the point.
Nice one, i liked it so much…..keep writing…
very useful information at one place for software developers ..
Great collection
Hi Joe,
I was trying to launch Eclipse Juno in my laptop which is installed with jdk1.7.0_01 with update 7. But Eclipse is getting terminated every time with the error message that failed to load JNI Shared library from the source. I dont understand that message and I have checked my PATH and CLASSPATH env variables and are fine. More over I am running my Netbeans IDE it is not complaining with the same error and also I am able to run java programme from the command prompt. This problem is only with eclipse. please guide me to settle this problem
Thanks
@Padmanaban,
if you can share the exact error trace, I can attempt to solve it.
Recently with Juno I face some similar error message. It was the first time when I was setting up Juno. Then I doubted about the downloaded zip file and I removed the whole setup, downloaded it fresh again and it worked nicely.
My guess is some files may be missing or corrupted.
You are doing an awesome job here!!… I think your site is one of the best ones to deliver a clear knowledge of Java which is really helpful!!!.. Keep up the good work
you are super in explaining.. really very good articles all of them ..
good info!!
Hi Joe,
your site is too good to read and it is very useful article for java guys.
kiran G.
thank you sir loved article alot
Thanks a lot sir
Thank you very much
Very good Info..
may god bless you with whatever you want.. :)
Congrats for the article.
One question. You say “Use a log analyzer to read logs”. Could you please give an example of such a log analyser?
I use basic Unix commands to go through the logs. I would be interested in taking a look at such a log analyser. What would the key features be?
Cheers
Which is the ‘first best feature’ you love?
very useful thanks!
Thanks Joe; Very useful!
nice and useful article
Look of ur website/blog is very attractive, I wish all the success. I got lot of in depth information from this about java.Thanks, I wish u all the success.
Very nice blog
Sir, i want you to post on remote debugging with eclipse, have been trying hard to find simple way of doing.Hope,you can really explain in better way.
Sir, i want you to post on remote debugging with eclipse, have been trying hard to find simple way of doing.Hope,you can really explain in better way.
Good Website….
could you help me…..
how to edit falsh template…..
please help me out…..
great tutorial. very useful
thanks alot
awesome Thanks
when I use Expression to variable inside object I face the error (error during the evaluation)
Woah! I’m really loving the template/theme of this website. It’s simple, yet effective.
A lot of times it’s hard to get that “perfect balance” between user friendliness and visual appearance. I must say that you’ve done
a very good job with this. Additionally, the blog loads extremely quick for me on Chrome.
Excellent Blog!
Thanks for explaining it in very simple and effective way
It’s very good tutorial,very useful….
thanx Joe..
well concepts. really thanks …….
well documented
This is Great!
display is also a great debugging tool in eclipse that you should talk about.
Great, I ve learned new useful features (4+5+9)
Great, I ve learned new useful features
joe sir..
awesome job… very useful
[…] you will blame me, saying you didn’t expect a so basic article from me. If you are looking for Eclipse debugging tips in general, you can refer to this earlier written super hit […]
Thanks Joe!
Hi ,
Nice artical. Joe actuallu i am working on one tool where i can’t use eclipse or any advanced tool for debugging. Only solution is we can debug by entering System.out.println() in a code. actuallly i want to know that is there any tool which add this System.out.println automatically in java file for every posiible variables . Waiting for your replay. Thank you in advance.
Very nice explaination, keep writing….Hurray!!!!!!!!
Thanks for sharing ur knowledge.. Appreciated!!
Very concise and well written. Thanks.
nice…useful
Sir,
Could you tell me how to add multi Conditional Breakpoint. I tried to do something like: nName.equals(“A”) && mAge == 12
But it didn’t work.
good sir your tutarials
Hi guys,
I Debug a one program successfully.
After that when i am doing debugging another program the error message has been displayed like source not found…
please help me
Nice~
Nice way of explanations
This is great. Thanks.