This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I had the opportunity to see to Java developers at work. They had about 2 years experience.
I saw that they could troubleshoot many errors with ease. How can I become half as good as them?
Please do not say that it will come with experience. I know that part already. But is there a way to learn
troubleshooting, besides by experience ? I feel so frustrated when my work is stopped for 2-3 days due
to some common error which my experienced buddies solve in 10 minutes.
Yes, it's the experience. But you want a quick tip? Okay, here it is:
Read the error messages and believe what they say.
I find it amazing, the number of people who post their problems on internet forums with error messages which describe the problem exactly, and then ask what their problem is. Half of the battle in fixing bugs is understanding what you're looking at.
You can gain experience faster by recognizing patterns. When you see an error, write it down. That way you remember it the next time you see it. Also fiddle with something that works. Create an error, read the message and remember it. This is easier when you know the problem.
Remember the golden rule of debugging: if the problem does not make sense, it's two (or more) bugs combined.
I also like the "write it down" part of Jeanne's advice. More than once I was bugged by a persistent problem which I was not able to solve easily, but when I found the solution I didn't note it down. Sometime later I've bumped into it again. Aaaaaaargh!
no advice, just a ray of hope. after a while some will become so easy you won't believe it.
symbol not found...you misspelled it or didn't import it
array index out of bounds... usually off by one
Another technique that I found useful in the past was to try explaining my problem to my boss. It didn't matter that my boss had no idea what I was talking about and indeed wasn't even competent to read the code, what eventually happened was something like this:
Me: And then it does <whatever> and... Oh. Now I see what was wrong.
This worked even better when the boss would play along and ask stupid uninformed questions, because often one of them would undermine an assumption I had been making all along.
Troubleshooting can happen in different phases of your coding.
If it is a new one, and you dont have logs, add logs. Make your code more testable and modularized (which is what you should do anyway).
If it is an existing application and it doesnt give proper logs, or for example, the system simply hangs, add more logs. There are some scenarios like in jni where you run out of memory or something, and it just hangs giving no clue at all, but dumps something in your desktop.
Wasting 2 days on an error happens to everyone. The difference to the experienced one is, if he is already hours or too long into it, he accepts that he needs help. He can dig deeper, ask google, etc.
Some great advice there from wiser heads than mine - I'm sold on RubberDucking!
Just one tip from me: take a break and go do/think about something else. It's amazing how often, when you return to your desk after a coffee break or (even better) a relaxing weekend, you can take one look at your code and say straight away "Ah, that's where the problem is!".
Also, don't try to do it all on your own. That is what a development team is all about. If you get truly stuck, explain the problem/exception to a colleague. Chances are, they may have seen the problem before, know of a change to the application that may have introduced the bug or simply shed different light on it.
subject: How to become an expert in troubleshooting Java errors