Monday, June 30, 2008

Mini-Review: Head First Java, 2nd ed. by Kathy Sierra and Bert Bates

Head First Java by Kathy Sierra and Bert Bates, cover image.
Head First Java, 2nd Edition
Head First Java is a great book for describing many of the confusing aspects of the Java language. It is easy to read, written in a light style, and it uses lots of graphics to break up long runs of text. Many of the graphics in the book illustrate key concepts of Java.

Not For Raw Beginners, But Close to It

For an experienced programmer new to Java, it can be used to learn enough about Java to get a strong basis in the language. It covers a lot of the language, enough to get someone from just starting out to the point where they're capable of carrying on learning with the official documentation or books on specific programming subjects within Java. It starts out at a point that will probably not be basic enough for non-programmers to start learning, but if the non-programmer has a mentor, or another book specifically intended for non-programmers, it will make an excellent supplement.

The Best

The most valuable parts of the book are the places where it takes concepts of object oriented programming, design patterns, and how Java works and breaks them down into bite-size pieces for the reader. It uses a number of different approaches for explaining the concepts it
covers, so the material is varied enough that it doesn't get stale with reading.

Fun Exercises

It also includes a variety of exercises so that the reader can test their knowledge. Since these take the form of puzzles, it makes it easier and more fun to do them than the standard numbered list of exercises at the end of a chapter that you get in most textbooks.

Planned Obsolescence

The book has its shortcomings, of course. One thing that I found annoying was that many of the programming examples started out flawed, purposefully, to illustrate points of features of the language. In some cases this worked, but in others the shortcomings of the initial flawed solution were so obvious at the outset that it was frustrating to keep following along with the text (even for beginners, not just for me.) In other cases, too much space was given to the bad solution before the shortcomings were described and a better approach was taken.

OO Jingoism

Also, the attempts at explaining the advantages of object oriented programming versus procedural programming are strained, and somewhat unclear in the later stages. Realistically, this is a hard argument to make since the difference between good procedural programming and object oriented programming is diminishingly small. Likewise, many procedural languages have many of the features of object-oriented languages. At any rate, the point seems somewhat forced and belabored in this book.

Clarification Unclear

Another fault is that some of the exercises are unclear as to what is expected in the way of answers. The student is left to flounder, and what looks like an attractive and fun puzzle turns into a source of frustration. In these (infrequent) instances it's best to just move on.

Artistic Annoyances

The art also falls short in places. It falls just short of being sufficiently varied. The faux-retro look slips in some places. There are thought balloons in places where speech balloons belong. These are minor niggles, but they add an edge of abrasiveness to the book and its style, particularly in the latter portions of the book.

Final Grade: 93/100, A

The book's flaws are minor in comparison to its strengths. It's a book I can heartily recommend to someone learning Java. It is usable either as a main text, or as a supplemental book where you can read clearer and more verbose descriptions of what's going on when something about Java leaves you wondering what the heck is going on.

  • Easy to read.

  • Excellent clarifications of many concepts.

  • Fun exercises.

  • Some presentations follow poorly laid 'false trails.'

  • Some exercises unclear.

  • Some art needs a tune-up.

Buy, either for a main learning book (for experienced programmers), supplemental book (newbies or experienced), or as a backup reference for Java concepts (it's a must-have for this).

2010; Edited to Add:
This book is still one of the best out there. It's starting to get a little outdated. I can only hope that O'Reilly decides to fill a couple of trucks with cash and back them up to the homes of Kathy and Bert to induce them to produce an update for this book. It would be a shame to see such a useful and valuable book be lost due to the ongoing changes in Java.

There are other Java resources that have developed in the meanwhile, but none really take the place of this book.

Thursday, June 26, 2008

Trying Out LiveCDs

I'm still looking for a Linux or FreeBSD LiveCD for my high school computer class. I've had some success, but there's more to do. The idea is to have an OS disk that we'd run off of during class with the tools we need all there, ready to go.

No Room, No Room!

The computers in our lab at school have very limited disk space. Windows XP is installed on them, along with programs needed for other classes. That doesn't leave much room for graphics programs and development systems that I'd like to use for my classes, both the middle school and high school classes. So I thought I could use LiveCDs to solve the problem. Only the student's data files would need to be stored on the hard disk.


I downloaded the Belenix 0.7 LiveCD the other day, because the list of packages appeared to suggest that it includes the JDK, though actually it doesn't--it was my mistake. I got impatient with scrolling through the unalphabetized list and used my browser's "find in page" function. What I missed is that there was a break in the list, between items that are on the LiveCD and packages that aren't there, but are available. So, after downloading the .iso file, burning it onto a disk, and spelunking around I find it isn't there.


I also took another look at my OpenSolaris 2008.05 disk to make sure it wasn't there. I'd seen a comment on somebody's website somewhere during my search for a LiveCD with the JDK on it (I've lost the link, I'm afraid--it was someone who used to have their own LiveCD distro with JDK that gave it up with a comment along the lines of "I'm just going with OpenSolaris, it has the JDK.")


In spite of my slip-up on Belenix, I managed to locate a LiveCD that does have the JDK on it. In fact, it's got a heap of development tools on it. It's the iloog 8.02 LiveCD. It's based on Gentoo and while it doesn't want to start up X on my newer iMac, it runs well on my older MacBook. It does very well on the MacBook, so far as I've tested it (only briefly, so far. I spent too much time on OpenSolaris and Belenix today.) It supports the MacBook's built-in mousepad (unlike OpenSolaris and Belenix) and it actually boots quickly compared to the two OpenSolaris distros. I haven't tried any networking yet, but everything else seems to function.

System Dependencies and Finally, Sabayon

Given that the Macs in the school lab are about the same age as my MacBook (Core Duos) I'm hoping that it runs as well on them. If I'm lucky I'll have a chance to try it out this week, if not, then next week. The PCs in the school lab are pretty plain-vanilla hardware-wise, so I'm less concerned about them. (If the PCs in the lab had DVD readers in them, I'd probably have just gone with Sabayon's LiveDVD and called it a day a couple of months ago.)

Tailor Made?

There's still the open possibility of making up a custom LiveCD for the class. My time is such that I don't have much opportunity for a lot of tweaking, though. Installing some apps is within reason, dinking with hardware detection and drivers is getting deeper into things than I can afford. I'll probably look at Morphix in this regard.

However, at this point iloog is looking promising. Beside Java, it has Common Lisp on board, as well as ruby and python. I think I also saw Haskell when I was poking around. There's no way I could properly cover all these in class, but if time permits I could potentially spend a class (90 minutes) on each of 2 or 3 of the non-Java languages before we start Java.

Not Groovy, Dude.

Groovy, unfortunately, was not among the represented languages on the iloog disk. As I've mentioned before, the chances of me being able to prepare a full semester of classes on Groovy for this year is pretty slim.

Edited in 2010 to add:

I ended up making very good use of a variety of LiveCDs by having my class try out the different OSes on the school systems. And Java worked out well in spite of its complexities and niggling demands for exactitude. Though a well rounded scripting language would be better. If Sun had ever really sorted out JavaFX, rather than going halfway and stopping, that might have served. But when they write half a language then tell you to fill in the rest with the hooks to Java, that's no solution for a classroom.

Thursday, June 19, 2008

The Groovy Language

I've had a chance to play with the Groovy programming language just a little now, and I have to say it looks great for my needs as a teacher. It provides enough access to the system to allow the students to make nice GUIfied applications. The syntax is clean and simple--I wouldn't have to spend a lot of class time explaining purely "structural" code.

It's also got the strong real-world presence I'm looking for in a language. The Grails element has made Groovy a popular web-development language. This is great for the students in my class who will want to expand on what we do in class.

What I've done so far isn't enough to teach with it, not by a long shot. But it's pretty darn promising. I haven't seen a book on Groovy for non-programmers, yet, so no textbook. So I'd have to develop a lot of my own lesson materials between now and January if I'm going to start teaching it this year.

LiveCDs with Groovy Included?

I doubt I'm going to find a LiveCD that includes Groovy. Though it's looking like I'm not going to find one that meets my needs as-is anyway. So I'm going to have to look into:
  • Finding a LiveCD distro that works on all the school's lab computers and is likely to work on most student's home hardware.
  • Figuring out how to modify the content of the LiveCD distro to add the elements I want.
Whether I can manage to put together 32-36 lessons in Groovy as well between now and January while meeting all my other commitments remains to be seen. On the other hand, I can expect to throw it in at the end of the year as an extra with maybe a half dozen lessons or so, then expand that to a full semester the following year.


My OpenSolaris LiveCD arrived yesterday and I've had a chance to get a first brief look at it. I ordered it as part of my search for a LiveCD that I can use as a development environment for my high school computer class. I chose OpenSolaris in part because it's not already represented in the school's computer lab (I try to expose my students to as many different OSes as I can), I like Solaris in general (ever since it got over its teething pains after the change from SunOS), and I figured there'd be a high likelihood of the JDK being pre-installed on it.

It started up fine on my iMac (Core2Duo), and presented me with a very nice desktop. It's got some nice apps installed. The audio didn't work, even though it claimed to have a driver for it, and neither the ethernet or wireless networks had compatible drivers, which was disappointing.

No JDK? On a Sun OS? Really?

A bigger disappointment was the lack of a JDK. The JRE was there, but no JDK. In fact, I didn't find any development tools on the disk at all, except for python.

I realize that the space on a CD is pretty limited when delivering a modern OS, but it seems to me that if there's room for lots of media-related apps and sample media for them on a disk, there's room for some developer tools, too.

Certainly you'd think Sun would want to make the Java SE's JDK the 21st-century's equivalent to BASIC or K&R C? I guess python's got that role, it's just a shame that python doesn't address more of the system without having to use platform-specific APIs.

Keep Looking

Well, OpenSolaris isn't entirely out of the running for my class. This particular LiveCD is, but after some searching for a LiveCD that contains the JDK I turned up BeleniX. I downloaded the latest ISO last night, hopefully I'll have time to burn it and give it a spin soon. The list of packages claims that it has the JDK version 5 (presumably 1.5), which is good enough for a beginner's class, though I'd prefer 1.6. At least I'll have the Scanner class.

Wednesday, June 18, 2008

Why I Taught Programming with Java

I teach a high school computer class, and this last year we spent a semester learning programming. Picking the computer language we'd use was a lot tougher than I expected it to be. I looked at a lot of languages, and a lot of implementations of those languages. I ended up using Java.

I wanted a language that the students could use on their own, outside of class, to do real things. The language also had to be supported on multiple platforms, with the same syntax and libraries/classes on at least the major desktop OSes. It also had to be free, in the sense that there'd be no license fees for the school

On top of that, I wanted it to be fun, something that would let the students play with graphics and sound. Console-mode text just didn't cut it.

Now, in this day and age you wouldn't think it's expecting too much to have a programming language support features like graphics and sound, right? Apparently the language developers think it is. They rely on hooks to proprietary APIs, mostly, meaning that the code to open a window on platform A is completely different than that on platform B.

I'm not talking implementing keywords for controlling specular reflections and bitplane operations, here. I'm just looking for windows and some basic drawing primitives in the way of graphics. For sound, the ability to play a tone or a simple audio file would be plenty.

I was hoping to use a language with a clean, simple syntax like ruby or python. But I didn't find an implementation of either that met my needs. Jython came close, but the hurdle of jumping the Java API barrier to get the graphics and sound undid all the good that the core python would do--it would be easier to just teach Java from the outset.

I also considered going with Berkeley Logo. I like Logo a lot, basically it's LISP with some of the historically-established keywords cleaned up. I may use it this upcoming year with my middle school class. But for my high schoolers, I wanted something with more of a real world presence. Something they could keep moving forward with without having to change horses. Honestly, an open LISP implementation with platform-independent graphics and sound capabilities would fit the bill. One look at Y Combinator is all it takes to see that LISP is alive in the real world. I looked at some LISP implementations, I'll be looking at some more, but in the time I had I didn't find something that did what I was looking for.

Less Than Perfect
There were still some snags with Java, though. Installing the SDK on the school's Windows systems was a pain. The extra step of changing the command path was annoying for me, and for my students who went to install it on their home systems it became an insurmountable obstacle in about half the cases. OK, to tech-heads this probably seems like foolishness. Some may say that if they're stopped by this they have no business programming. I don't see it that way, and I don't take kindly to folks who think unnecessary complications in installing and using software ought to be used as a worthiness test for beginners. Beginners are beginners, and they ought to be able to focus on the one thing they're working on learning at any one time.

And, face it, as Windows users they're not used to install procedures any more complex than spinning a disk and clicking on a button. It's a shame users of all platforms couldn't have it that good.

As the aficionados of the scripting languages point out, Java's syntax isn't a simple and straightforward as it could be. To new programmers its insistence on certain forms of capitalization make it seem pretty fussy, for example, and dots meaning one thing in an import statement and another with invoking methods and members is more class time lost.

I used a Java textbook for non-programmers in an attempt to make my life a bit easier. I wasn't entirely satisfied with the any of the available Java programming books I was able to review before we got started with Java in class. As basic Computer Science books, I think they were fine. As introductions to casual programming, there were none that fit the bill. I'll try to do mini-reviews of the books I looked at and used in some future post. But my main concern was that the fun stuff--graphics and sound--was all left till late in the books. I had expected to find something that presents some basics like a JFrame and paintComponent early on, then plays with flow control constructs and such by using graphics within them. Unfortunately, I didn't find any such Java books for non-programmers (or for programmers but basic enough that I could make up the difference.)

Looking Forward

I'm planning on spending a semester on programming again in this upcoming school year. I haven't decided if I'm going to stick with Java, though the default will be doing so. If I do stick with Java, I may create a LiveCD of some sort with the SDK and a basic IDE on it, and distribute it to the class. This could get rid of some problems I had last year, like dealing with some of Window's programmer-hostile features in class while neglecting the students on other OSes, as well as installation of the SDK on the computers in the school's lab (the non-Mac OS ones, that is.) It'll also mean that the student can take the CD home and have the same development environment there as in class.

I'm also still looking at other options. Because I still think it's worthwhile to have some graphics and sound in an introductory class, and because I still want the students to be producing portable programs, I'm concentrating on the language implementations that compile to Java bytecode. If I find a language that doesn't have some of Java's gotchas for beginners, it won't be any worst to install its compiler (except that I'll have to add it to the OS X systems as well as the others, unlike the Java SDK.)

Groovy is one possibility I've found so far. JavaFX may be another. Whatever language I choose, I may still go with using a LiveCD of a BSD, Linux, or maybe even OpenSolaris depending on what I can find that works well with the lab's computers and is likely to work well with most students' home systems.

I can tell you this, though. As "bad" as it was, it's times like this that I really, really miss those old 8-bit computers with BASIC on them.

An Infinite Number of Cats on an Infinite Number of Keyboards and the Works of John Carmack

If we place an infinite number of cats on an infinite number of keyboards how long will it take them to reproduce the works of John Carmack?*

How long before the cats have reproduced Doom and Quake? Will some lively Russian Blue turn out Spear of Destiny in just a few short years?

With the time it will take the cats to get their programming tools in order, the cats have zero chance of even managing Commander Keen. I like cats, but faced with the uphill battle of going from non-programmer to programmer I'd say the cats are toast. Heck, I'd give them over a century to get as far as "Hello, World!" from K&R C.

What chance does that give a human non-programmer? Assuming they manipulate a mouse and keyboard with more control than a cat, not quiteso bad.

10% Inspiration, 270% Perspiration

The most important characteristic is perseverance. Perseverance in the face of confusing messages, obscure software failures, oblique semantics, and I'm not even talking about the programmer's own programs! I'm talking about getting the development tools installed. Once they start doing their own programs they'll need even more sticktoitiveness.

The Cat's Advantage

The cat's advantage is that it does not allow its mood to be affected by strange error messages. It also does not allow a long list of errors to faze it. Humans on keyboards tend to take these personally, however, as if the computer is commenting on their personal grooming or appearance. "Undeclared identifier error in line 46. And is that your feet or did a fish die under the table?"

Cats are unflappable. There are no errors. Either they meant to do that, or it never happened.

"Of course I misspelled that keyword. It was a statement. If you're not mature enough to understand why I did it, there's nothing I can do about it."

(Edit, recompile.)

"What error? There's no error. See? The compiler log shows 0 errors, 0 warnings. I don't know what you're talking about."

Be The Cat

That's a lesson in programming for humans.

* (An oeuvre which, thankfully, continues to grow.)