This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Cattle Drive and the fly likes Learning by debugging... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Learning by debugging..." Watch "Learning by debugging..." New topic
Author

Learning by debugging...

Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
...and by digging into someone else's code. That Aha! feeling is so nice.

I've recently dusted off the jdbc-4 assignment, which got me delving into a bunch of other stuff that I'd long forgotten (not the least of which is simply installing and configuring stuff). Last night I was still working on getting the jdbc-3 instructor's solution working.

Being the plodder that I am, I had retyped most of the classes, just to force me to look more closely at them and get back into the java syntax mode. That of course opens me up to all kinds of stupid little mistakes. Fortunately the compiler saved me from most of those.

But then there was something not working (an SQL INSERT didn't seem to be taking hold) and I was running out of ways of tracking what value was where. That's because the exception messages weren't showing up right in the app like before, there was a Nifty New Way in the instructor's solution. Or maybe it wasn't new, but I hadn't bothered to look into it before. So I went off on the sidetrack of finding this mysterious log with those all important hints about what was going wrong.

First I went to the com.javaranch.common docs. Got a nice description of what the mystery method was doing, but not all the gory details of how it worked. Time to dive into the source.

And such nice source it is. Paul's code and comments give you the picture quick - you see what's going on and how it works right away, no need to decrypt secret codes. So I found out there's a little switch you have to turn on. First I tried turning it on in the wrong place. Then I thought a little harder about what the comment was telling me. The second try worked and bingo, I had the caught exception displaying it's clue. Actually, it spelled it out really clearly and took only a minute to fix.

Yeeha! I'd found and fixed the problem! And it won't be a process that I'll forget anytime soon. That's the cool thing I guess I've been getting at. Debugging is a great way to learn. Not to mention working with code written by someone else. Especially if that code is com.javaranch.common.

Oh, almost forgot. The problem was a misplaced ' in the sql statement. Which proves that choosing to type instead of copying and pasting was *not* a bad idea: without that typo, I'd have missed out on all the other fun.
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1195
Pauline, I totally agree with you. Knowledge sticks better when I really have to take something apart to figure out how it works. (Or doesn't work, typically!)
So, since the assignments have been re-worked, are they really different?
Maybe if I find time I should go back and re-do some just to see if I can!
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
I have learned a lot by looking at other people's code in detail.

I think the new version of the servlets/jdbc assignments are significantly different.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
 
subject: Learning by debugging...