BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Rails for Java Developers Review and Excerpt

Rails for Java Developers Review and Excerpt

Rails for Java Programmers, by Stuart Halloway and Justin Gehtland, teaches the Rails framework to Java developers. It provides an overview of Ruby, comparing and contrasting with Java and then gives a detailed look at the Ruby on Rails framework and compares each piece against the best known Java equivalent.  InfoQ is hosting an exclusive excerpt including sections on controllers, core classes, and unit testing.  InfoQ is also pleased to provide a review of the title by Java Editor Rob Thornton:

Rails for Java Developers Review

Ruby on Rails is the latest hot web framework to strike the market. Rails for Java Programmers, by Stuart Halloway and Justin Gehtland, attempts to teach the framework to Java developers by comparing Rails code to the equivalent in common Java frameworks such as Struts and Hibernate.

Ruby on Rails is a full-stack framework for web applications. Rails is written in the Ruby programming language, and is built on many ideas that Java web application developers will be familiar with. Rails for Java Programmers is split into three main sections:

  1. An introduction to Ruby: Two chapters introducing Ruby to Java programmers
  2. Rails MVC: Three chapters covering Rail’s MVC framework
  3. Everthing else: Four chapters covering Testing, automation of the development process, web services, and security

This book is intended to provide a Java developer enough information to get started building advanced web applications.

Who is this book for?

This book is targeted at Java programmers who are looking to learn Rails, and by extension, Ruby. The authors are experienced Java developers who have learned Rails and they believe that Java developers would benefit from a book tailored to their background. This book is not targeted for managers or those looking for an introduction to programming. Extensive comparisons and contrasts are drawn to Java and popular Java frameworks, so a working knowledge of Java is a must, and experience with Hibernate and Struts is expected. Acegi and Axis are also discussed in the chapters dealing with security and web services. Likewise, because of the depth the authors cover, this book was not written as a introduction where each chapter builds on a sample application.

Content Relevance

Having some Ruby experience and very limited experience with Rails, I approached this book looking to leverage the knowledge I’d gained working on Java web applications to make the transition to Rails quicker. This book exceeded my expectations by providing depth on the topics of testing, web services, and security. The introduction to Ruby chapters were well thought out and provided a quick way to jump into a new language from Java by comparing core language features (objects, methods, polymorphism, etc) in Ruby to those from Java. After reading those two chapters you’ll be ready to explore further, but don’t expect to know everything about Ruby. These two chapters cover the equivalent of the core of Java plus the java.util package. The rest of Ruby and its standard library is a whole book unto itself.

Java developers who have followed the rise of Ruby on Rails will fear that this book will be the latest entry into the flamewar of “Ruby Rocks and Java Sucks!”. However, this is not the case. The authors are experienced Java developers and take care to point out places where each tool fits best. In general they advocate Rails for the typical use case, pointing out how the expressiveness of the syntax and the ideas of convention over configuration speed up development time. They are quick to point out where Rails falls short, for instance when discussing distributed transactions they say: “Rails is currently unsuitable for systems that must enforce transactional semantics across different databases.”

As I read the book, one of the concerns that I had is that the versions of the Java libraries used in the book are a bit out-dated. The authors sought to find the best baseline for the average Java developer. For instance, they base their ORM examples on Hibernate 2. This is not explicitly written, but they use mapping files instead of annotations in their example of mapping Hibernate objects to a database. They make a note that inline configuration is becoming more common, but they proceed to demonstrate the XML technique. My first impression of this was that they were taking some license to boraden the advantage of ActiveRecord over Hibernate, but after reflecting on the state of the average Java developer, I believe it is appropriate. There are many companies who are still on Java 1.4 and while they may be looking at Hibernate 3, the average developer will be more familiar with the mapping file approach.

The use of Java examples alongside Ruby and Rails examples allows the authors to discuss how the two technologies complement each other. For instance, they note that they make use of the schema migration tool that is built into Rails in all of their Java projects.

The core MVC chapters are well laid out and cover a lot of ground quickly. For instance, the chapter on Data Access shows everything from connecting to the database to CRUD, validation, lifecycle callbacks, transactions and connection pooling. Similarly, they cover advanced topics such as routing, benchmarking, page caching, Ajax and RJS, and testing with Selenium in the ActionController and ActionView chapters.

If you’ve already dabbled in Rails, some of the best material will come in the last third of the book where you’ll find excellent chapters on testing, web services, and security. The testing chapter shows how not only is unit testing built into Ruby, but how Rails comes with deep support for integration testing and how to use code coverage tools and mock objects to beef up your testing strategy.

An important point to remember is that this book does not leave you with a single, fleshed out sample application. Code examples are provided, but they are built to demonstrate a single point and are not wrapped up in a typical application. The reader is expected to know enough about web application development that, after reading and seeing how to do something in an isolated environment, the lesson can be applied to whatever application is being developed.

Readability

I found the book very readable, written in the approachable tone, common to other Pragmatic Programmer titles. The resource sections at the end of most chapters provide links to many technologies or tools that they only mention in passing or in footnotes.

Code Examples

The code examples are separated into two applications. The first is a simple application on top of one database table that shows how easy it is to get a Rails application running from scratch. The second, Rails XT, stands for Rails Exploratory Testing and is a place to put all of the different pieces the authors use to demonstrate Rails’ capabilities.

Summary

Overall, Rails for Java Developers is an excellent bridge for Java developers looking to jump into Rails. Basing the book on technology that you are likely to know allows the authors to cover a lot of material quickly. Similarly, their honesty in pointing out where each technology is strongest is refreshing.

Rate this Article

Adoption
Style

BT