Java Development News:
Java Open Source Programming
By Dion Almaer
01 Nov 2003 | TheServerSide.com
There are always a few books that you know are in the works... but aren't due for completion for a long time. Sometimes you are really looking forward to getting them in your hands, and this book was one of these. "Java Open Source Programming" is an interesting title as it could mean so many things. I think this book is two things:
- A look at many great open source technologies that developers should have in their toolboxes such as:
- Mock Objects
- A chance to watch some good programmers walk through a project with these tools, and see how they all come together.
So you end up getting different things out of the book. It is nice to look at the technology in isolation when you really want to learn that one technology. It is also very helpful to see how these technologies integrate, and how you go about actually building something real (which is after all what we all want to do).
Since so many technologies are covered in the book, the authors have to really think about what they want to get across. If they documented every XML tag, for every possible configuration, you would end up with a tomb of information, and it would be pretty dry reading too. :) I think the authors do a good job of giving you the information that you really want. However, if you are an expert in one of the technologies then you may have wished for more... but for that you will have to wait for a book just on that technology.
I am a big fan (and user) of most of the technologies that are used in this book. Some of them have good documentation via their website, and some of them have NOT so good documentation. It is definitely worth having some high quality docs in one book that I can reference, instead of having to curse at the website.
I have to admit to one moment where I let out a groan. That was when I saw that the sample project would be another PetStore. I think a lot of people are probably tired of the PetStore, but here at TheServerSide that is probably doubly so! :) To be fair to the authors, they do have a section called "Looking at Yet Another PetStore" where they explain their reasons for it, and there are some valid reasons; but I still had to cry a little.
Let's look at the structure of the book:
PART ONE: Introduction
1. Overview of the book
2. Application Overview
PART TWO: Building Your Open Source Toolbox
3. Unit Testing with JUnit
4. Testing Object Interactions with Mocks
5. Storing Objects with Hibernate
6. Model View Controller with WebWork
7. Simplifying Layout with SiteMesh
8. Adding Search Capabilities with Lucene
9. Generating Configuration Files with XDoclet
10. Communication and Tools
11. Time-Saving Tools
PART THREE: Developing the Application
12. Setting Up the Development Environment
13. Understanding Test Driven Development
14. Managing Lifecycles and Dependencies of Components
15. Defining the Domain Model
16. Creating a Web-Based Interface
17. Defining Navigation, Layout, Look , and Feel
18. Implementing Browse and Search Capabilities
19. Adding a Shopping Cart
20. Securing the Application
Let's look at these sections in detail.
Part One: Introduction
The book starts out by simply letting you know what you are going to learn, both from a technology, and from a philosophy standpoint (Chapter One). This book isn't just about the technology, but you really get a feel for how the authors like to develop software. This is what I look for, the gems of information that come from past experience. This is probably why I have never been a fan of the "Learn X in 24 hours" books, as they are purely a quick reference with no real meat.
Chapter Two takes you on a tour of the application that will be built throughout part three.
But anyway, let's get to the meat.
Part Two: Building your Open Source Toolbox
Now we get rolling into the myriad of technologies that we have the pleasure of playing with in J2EE. We start off with good old JUnit. A fine job was done here, but I glossed over it a little since I just read (and reviewed) the JUnit In Action book by Vincent Massol and Ted Husted.
I really liked how they tackled Mock Objects. Instead of starting with "these are Mock Objects... and this is how you can use them", they really explained the reasoning behind Mocks. Testing a solitary class which has a getName() method is very easy. It gets difficult when you move into the real world and you have interactions between your classes. There are many pitfalls here, and they explained them, and how to help get around them with Mocks.
Hibernate was next to show up. This seems to be one of the latest Open Source poster boys (and for good reason). If you haven't delved into Hibernate yet, this chapter will take you through the roller coaster ride of how it all works, and you should feel comfortable putting your own toe in the water.
From persistence we move to the web tier. Were you hoping to see a chapter on Struts here? I wasn't! Not only am I not a huge fan of Struts, but there are already plenty of books out there for that market (which is large!). Are you ready for something a little different? A little simpler? WebWork could well be just what the doctor ordered. This chapter discusses WebWork 2, and the XWork framework that it sits on (XWork is the generic command pattern framework). This is a very in-depth and thorough chapter which will hold you in good stead if you are either:
a) Looking at playing with WebWork 2
b) Looking to migrate from WebWork 1.x to 2
There is even a small comparison to Struts, and I was surprised at how tame they were. I wonder if the editor took out a red pen to that section a little?
SiteMesh has always been a hidden gem in the Open Source world. It is one of those components that just does its job, and does it very well. You can think of it as the Decorator pattern for the web. If you are a Struts person, then it is closest to Tiles. It does differ though, in that it isn't tied to ANY framework at all. It cleverly decorates any HTML source, so you could wrap plain HTML, a Perl CGI, or anything else that produces HTML. Since the majority of web projects I have worked on need a decorated structure (top bar, left bar, right bar etc) I have always been surprised that more projects don't seem to be using SiteMesh. If you use <%@ include file='header.html' %> to put structure in your JSPs, step away from your code, and look at SiteMesh now.
Lucene is another gem. If you wish you could have Google searching away in your application (but don't want to buy Google services) then check out Lucene. Chapter 8 will walk you through the issues with searching, including how to build and search Lucene indexes of your content. It is very flexible, powerful, and extremely fast.
XDoclet steps up to the plate in Chapter 10. Ara Abrahamian starts off by discussing attribute oriented programming in general, and then you get to the nitty gritty of XDoclet itself. The chapter delves into the different realms where XDoclet applies; from where it started (EJB) to the Web tier (Struts, WebWork), JMX, JDO, Hibernate, and more. You also get to read about how to use the tool effectively. This is important, as we have all seen people go a little bit too hog wild, and your Java source is 99% /** @tags **/. Learn where and when it makes sense to use metadata!
Thelast two chapters give you a chance to look at some of the smaller tools out there. Communication and Project management tools are discussed here (CVS, Wiki) and Mike even gets a chance to plug JIRA, his company's bug tracking tool. Some Jakarta Commons libraries are discussed, as well as some great pieces of code like OSCache (which we use on TheServerSide).
Phew, what a circus of technology!
Part Three: Developing the Application
Now that all of the technology has been introduced, the third part of the book takes you down the path of creating PetSoar, that Yet Another PetStore.
We start off by setting up our project's environment. This includes our build system (Ant) and our IDEs. There is an interesting discussion on how much you should use your IDE versus Ant for various tasks. There are a million ways to setup your build environment and directory structure. Here they actually talk through some of the options, and discuss how to make a particular choice. I always feel that items such as "Setting up your build environment" aren't talked about enough. It is one of those things that all projects have to do, yet you often feel like you are reinventing the wheel. I was glad to see a topic such as this in the book.
I also really enjoyed Chapter 14, Managing Lifecycles and Dependencies of Components. There is a movement towards lightweight containers, and the Inversion of Control pattern ("Don't call us, we'll call you" - Hollywood Principle). This chapter will show you how we have got to this stage by detailing the issues of component dependencies. Look at the pro's and con's and then finally see how it all works in practice via XWork's IoC implementation. Great stuff!
Chapter 15 moves us to the Domain Model, and architecting our application with Hibernate. Here you will feel like you are watching one of these guys at their computer, as they explain to you their thought process as they build the domain model. They practice what they preach and use Test Driven Design and Mock Objects as they build it up, and explain the various approaches (Top Down, Bottom Up, Middle Out).
Now that the data tier is done, they move onto the web tier. They build this tier using WebWork and SiteMesh, so again you not only see how the individual technologies work, but how they all integrate. They refactor their application as they go through, which shows you WHY they do certain things. When you see some final code, you don't know what process took that team of developers to that point. Here we get to see part of that thought process.
The last chapter touches on how to secure the application. It gives a good account of J2EE security in general and also delves into work-a-rounds for the common issues that we run into. There is one paragraph which mentions OSUser, another OpenSymphony component which has modules for various security systems on one side (Unix, LDAP, NT, etc), and application support on the other (WebLogic, WebSphere, etc). I would have really liked to have seen some examples of using OSUser, but I also know that we may be hitting New Technology overload already.
Anyone who is building J2EE applications should take a look at this book. It will delve you into some new open source technologies which will at least make you think. There was a definite hole in the books that were out there with respect to some of these great tools. I am really happy to see that hole being filled.
I really liked the fact that due to the separation of the book, you get both a technical reference and a case study in one book. From time to time I wish there was more information about a particular area, but had to remind myself that this is a book that has a lot of breadth, and I think they do a good job by keeping it at a manageable level.
Great job guys.
Here are links to areas that I mention in the book report:
Java Open Source Programming book home page: http://www.wiley.com/compbooks/walnes
Java Open Source Programming on Amazon: http://www.amazon.com/exec/obidos/tg/detail/-/0471463620/102-2820143-0413763
Joe Walnes: http://joe.truemesh.com/blog
Ara Abrahamian: http://www.jroller.com/page/ara_e
Mike Cannon-Brookes: http://blogs.atlassian.com/rebelutionary
Patrick Lightbody: http://www.lightbody.net/~plightbo
About the Author
Dion Almaer (firstname.lastname@example.org) is a Principal Technologist for The Middleware Company (www.middleware-company.com), one of the nation's leading training companies in EJB/J2EE and B2B technology training. TheServerSide.Com J2EE Community is a service of The Middleware Company.