behind the gist

thoughts on code, analysis and craft

Introductory Java tutorial

My son took an introductory object-oriented programming class in high school this last semester. He kept having to ask the teacher for other project ideas because he was finishing the assignments so quickly. At the time, they were doing simple graphical stuff (like making bouncing balls) and some Project Euler kind of stuff.

I was trying to find some examples that would be a little more like real programming work, in particular, something that was more project-based and test-driven. In the end, I built my own tutorial for him to try.

I made a simplified, stand-alone version of the Base64 manipulation code from my polybuf-java project and wrote a set of unit tests to go along with it. I then stripped out the implementation of all the methods so I was left with a code skeleton, a set of documented APIs and a set of working (but failing) unit tests. It touched on a number of different areas of Java

  • unit testing
  • javadoc
  • various control structures
  • binary vs. character IO
  • binary operators
  • exceptions
  • static initializers
  • inner classes

I told him if he got all the tests to pass, I would share my version of the implementation. In the end, I don’t think he ever bothered to work through the tutorial. No big deal, I had fun making it anyway. It is available to fork and try yourself.

One takeaway is that new developers probably don’t get the same satisfaction out of seeing a set of unit tests pass. For me, it is great to know that everything is working as it should. But I can see how a novice would prefer to have more “hands-on” feedback which is probably why the courses focus so much on graphical code. Project Euler adds an aspect of discovery and puzzle solving that is also more satisfying than a successful test run. But I still think that some pre-existing structure, with a focus on documentation and unit testing would give new programmers a great foundation.