Book review: Beginning Java SE 6 Game Programming, Third Edition
Z Jacek Laskowski - Wiki Projektanta Java EE
Beginning Java SE 6 Game Programming, Third Edition by Jonathan S. Harbour (Course Technology PTR, January 18, 2011)
Java SE 6 Game Programming is a mystery no more
I'd never been engaged in any game development affair, but I kept remembering the days when I was thinking what it'd take to develop a game in Java.
A few weeks before a conference where I'm showing up with Clojure with the aim to highlight it as "a Java library for some concurrency improvements" (from "What is your opinion on Clojure?" at StackOverflow), the idea of performing game development with Clojure on stage crossed my mind. At that time I considered game development as a tough exercise, mostly for its heavy use of threads and concurrency, and I didn't feel well-prepared to tackle it (which was the reason to pick up Clojure in the first place). That's when I stumbled upon "Beginning Java SE 6 Game Programming, Third Edition" by Jonathan S. Harbour. It quickly caught my attention and I spent the whole weekend to have read the book.
After a glimpse at the table of contents, I crossed out the first two chapters (which seemed more concerned with introduction to Java programming language than anything else, not to mention game programming) and begun reading the Chapter 3: Creating Your First Java Game. As it turned out, the Chapter 16: Galactic War: Web Deployment wasn't worth my reading either where "Packaging an Applet in a Java Archive (JAR)" and "Creating an HTML Host File for Your Applet" were discussed.
The writing style was concise, engaging and easy to follow. Each and every chapter didn't take too long to finish and comprehend the content.
The Chapter 3: Creating Your First Java Game went very smoothly and was the first to let me feel empowered to develop a very first game in Java. It showed exactly what I was after meaning I could read about what Java SE classes I should use for a very simple yet complete, vector graphics game. I even wrote my very first AWT application. The others were as much valuable. The chapters were usually quite short and smooth my thinking about Java game development. By the Part III I knew everything I should to develop a game in Java SE myself. The Chapter 12: Galactic War: Sprites and Collision Boxes was crucial for the entire game project so once I was done with its understanding, the rest just let the knowledge settle down. There was the chapter 14 that was one of the most tough in the reading, and the "Enhancing Galactic War" section was one of the longest ones - the code discussed no new Java classes for game development, but merely the algorithms for power-ups, game states and such.
The book "highlighted all key lines of code in bold text so they will stand out." that greatly helped to comprehend the code and its changes. The explanation was occasionally a kind of discussion - "You might wonder, then, how is this any better than just using the listeners directly in the game’s source code file? That’s a good question!" ("Keyboard and Mouse Events" of "Exploring the New Galactic War Source Code" in the Chapter 14).
It's clear that the author made all the steps to provide as much valuable information about game development as possible, but I didn't manage to refuse to think that he lacked experience with Java and OO development.
I disagreed or was surprised at the very least to have read the statements about Java OO design in the book like "Whenever possible, we will forego good object-oriented design in favor of simpler source code. This is especially helpful for beginners who may have never seen a truly huge source code listing, and thus would not understand why such things are important." ("Programming Simple Sprites"). More importantly, the code like this: "public class BaseGameEntity extends Object", "(boolean)(sample != null)" ("The SoundClip Class"), "(The default, if you do not specify it, is public.)" that referred to the package protected qualifier ("Getting Started with Java Sound") or "The Random class is located in the java.awt.util" ("A Simple Loop") turned up in the book. That doesn't help beginners to learn Java when consistency is more important than a good OO design. There were more such places - "I am not a big fan of inheritance, preferring to build core functionality into each class I use." ("Creating a Reusable Sprite Class") or "Inheritance is a beautiful concept, but in practice too much of it can make a program too complicated." ("Sprite Class Source Code"), "In a game project, often those get and set methods just hurt productivity." ("Encapsulating Sprite Animation in a Class"), "This is not pure object-oriented programming (OOP) by any means—we give up some security for versatility and just count on programmers who use the class to know what they're doing. Getting the job done while writing good, clean code is often the rule in a programming team!" I could understand the reasons behind these decisions, but I think it's unacceptable when the book's purpose is to learn Java programming too. There were more similar examples.
What turned out to be the main deficiency of the book was that the author didn't resist describing rudimentary object-oriented constructs like inheritance or composition. The author couldn't present all the Java and object-oriented programming aspects in those first two chapters and let them be scattered throughout the entire book. It was really annoying.
In the Chapter 6: Simple Sprites I had to go over the classes to be able to learn how to develop a game in Java SE, even though the "What You Have Learned" sections highlighted these topics. I'd wished it'd have been examined in the text along the code. Nothing about "How to detect sprite collision" - the code contained the answers and one could overlook it easily unless paid attention to detail.
I appreciated when the author provided his insights on different aspects of game design, e.g. "Over the years I have seen many techniques for sprite animation." ("Sprite Animation") and "I experimented with quite a few different ways to do this, and I came up with a solution that is versatile but not totally internal to the Game class." (Chapter 14: "Galactic War: Entity Management") or Java itself, e.g. "I've used several threading libraries[...]and it's not very easy to use at all compared to Java's built-in support for threads." ("Examining Multithreading").
It really helped to grasp the concept of an animation strip when the author went as far as to develop a self-contained class with the main method to run a sample before he enhanced the game classes - "While learning how to do animation, a single, self-contained example is helpful before we get into a class." The author greatly enhanced the way of explaining how to develop a game in Java in the Chapter 13: Galactic War: Squashed by Space Rocks with a series of a part of the code with description. Likewise, the Chapter 15: Galactic War: Finishing the Game's "Let’s Talk about Power-Ups" was a series of screenshots and their explanations.
I was about to have skipped the Chapter 8: Keyboard and Mouse Input, but decided not to having hoped for a few useful tips. I found none. Neither did I find in the Chapter 9: Sound Effects and Music's "Getting Started with Java Sound".
In the "Epilogue" the author wrote: "There are so many advanced topics that we didn't have time to cover in this book, the likes of which a diehard Java programmer would have liked to see." I wish the author had discussed these advanced topics, albeit having read the book Java SE 6 Game Programming is a mystery no more. It's a book I would surely recommend.
