This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Learning by debugging...

Posts: 4012
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...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.
village idiot
Posts: 1214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
Posts: 9099
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
All of life is a contant education - Eleanor Roosevelt. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!