InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Rails for Java Developers Review and Excerpt

Posted by Scott Delap on Feb 13, 2007

Sections
Development
Topics
Web Frameworks ,
Ruby on Rails ,
Java ,
Ruby ,
JRuby
Tags
Rails ,
JRuby
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.

No comments

Watch Thread Reply

Educational Content

New-age Transactional Systems - Not Your Grandpa's OLTP

John Hugg discusses high volume transaction processing applications with high and low frequency profiles, and how VoltDB can be used for that purpose.

Cool Code

Kevlin Henney examines code samples to see what can be learned from them starting from the premise that one won’t write great code unless he knows how to read it.

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.

Interview: Software Systems Architecture: Working With Stakeholders Using Viewpoints and Perspectives

InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.