http://java.sun.com/ http://java.sun.com/ http://java.sun.com/javaone
JavaOne - ExperiencingJava technology through education, industry, and community
2007 Conference
Home
Registration
   Conference Hotels
Schedule
   Activities
Tracks
Sessions
   General Sessions
   Business Day
   TV Day
   JavaOne Camp
Hands-on Labs
Pavilion
   Cosponsors
   Exhibitors
   Media
   How to Exhibit
Blogs
Multimedia
Java University
 
Conference Tools
Schedule Builder
Event Connect
My Registration Details
 
Conference Programs
Alumni Program
   Alumni FAQ
Eco Corner
Rock Stars
 
Related Resources
JavaOne Library
JavaOne Online
2006 Site Archive
 
Community
Forums
Sun Developer Network
 
Popular Items
Java Wear
Duke Images
 
Related Sites
java.sun.com
java.com
java.net
 
 
  Home > JRuby on Rails: Agility for the Enterprise (TS-9370)

 JRuby on Rails: Agility for the Enterprise (TS-9370)

   
By John O'Conner  

Unless you've been on another planet for the last year, you're probably aware of the clamor over scripting languages and their availability from within the Java platform. As a result of Java Specification Request (JSR) 223, which was implemented in the Java Platform, Standard Edition 6 (Java SE 6) release, developers can integrate Java technology and scripting languages. The result is that each environment benefits by being able to use the other's rich APIs.

Many scripting languages are now available to Java platform developers, and one of the most active scripting communities surrounds the Ruby language. The Ruby language is tremendously popular with developers because of the productivity gains that it delivers to its users. As a result, almost a dozen technical sessions and Birds-of-a-Feather (BOF) meetings at this year's JavaOne conference discuss Ruby.

Sun Microsystems engineers Thomas Enebo and Charles Nutter led the session "JRuby on Rails: Agility for the Enterprise" (TS-9370), which proved so popular that Conference organizers added a repeat session. With over 10 years of Java programming language experience each and long histories in the software industry, Enebo and Nutter now work full-time to make Ruby a first-class language that runs on the Java Virtual Machine (JVM).*

Their session helped attendees understand Ruby and its role on the Java platform by first describing the Ruby language itself, then its JRuby incarnation, the Rails product, and JRuby on Rails.

What Is Ruby?

Ruby is a dynamically typed, object-oriented language. Yukihiro "Matz" Matsumoto, the language's creator, thought simplicity, productivity, and even fun were important to the language's success. These goals have influenced many of the language's features, idioms, and stylistic elements.

In Ruby, everything is an object. Even plain numbers such as two and four are objects. The language offers a lot of syntactic help, and it provides easy access to regular expressions, arrays, associative arrays, and Strings.

Ruby provides mix-in support by way of modules. Mix-ins are similar to the Java language's interface. Blocks are available too, which are similar to anonymous methods that you can invoke and pass around.

Ruby allows you to dynamically create and alter classes. You modify existing classes by simply reopening a class and defining the method you need. For example, the Rails framework adds methods to the String class like this:

class String
  def blank?
    empty? || strip.empty?
  end
end

What Is JRuby?

In 2002, a group of Ruby and Java language fans began to implement the JRuby environment. JRuby is a Java platform implementation of the Ruby language. Like Ruby and now even the Java platform itself, JRuby is open source and has many active contributors. JRuby integrates with existing Java technology using JSR 223. That means that Java language applications can call in to Ruby scripts and that Ruby scripts can use Java classes.

Why Should You Use JRuby?

The next time you have to decide on a scripting technology, you might consider Ruby or even JRuby. In particular, JRuby seems more appealing than Ruby for a few great reasons:

  • JRuby may be faster than Ruby in the near future.
  • JRuby scales well with native threading.
  • It provides Unicode support.
  • JRuby integrates with Java libraries.
  • It is an easier path to getting Ruby in the enterprise.

Some of JRuby's language features seem to make it even more powerful than the Java programming language. Blocks, modules, metaprogramming, and dynamic typing all provide added productivity and functionality to the language.

What Is Ruby on Rails?

Rails is a model-view-controller (MVC) development framework for Ruby. Like Ruby alone, Ruby on Rails is open source and is written in Ruby.

Ruby on Rails is a set of libraries, APIs, and frameworks for creating web applications. Many common tasks are already available in the Rails libraries, so you don't have to rewrite functionality that is common to most applications.

Why Use Ruby on Rails?

Ruby on Rails simplifies web development. One of the biggest productivity gains of the Ruby and Ruby on Rails environments is the use of conventions. Instead of using complicated configuration scripts to tie together the various bits of a large application, Ruby on Rails uses naming conventions to automatically connect and communicate with other resources and components in the system.

This encourages developers to use common conventions and to avoid remaking solutions when solutions already exist. The amount of code you must write is significantly less when you adhere to the conventions. In the session, Enebo and Nutter claimed that some Rails applications have less code than do the XML configuration files from an equivalent traditional application written in the Java Platform, Enterprise Edition (Java EE).

Because Rails development doesn't require the typical compile, deploy, and restart cycles that have been common to Java EE development, you can see and recognize the productivity gains almost immediately. The Rails environment has lots of tools that generate application scaffolding, making it quick and easy to get an application running.

Why Use JRuby on Rails?

JRuby on Rails allows you to deploy applications to Java application servers. Production environments using Java application servers are pervasive. It's considerably easier to change just a single application framework -- JRuby on Rails -- in an existing environment than it is to switch entire architectures.

If you want to benefit from Ruby development, libraries, and community in your organization, you'll have much more success introducing Ruby if you don't have to change existing servers and infrastructures. JRuby on Rails lets you bring the Ruby language into your project without the architectural expense. You can continue to use your existing Java platform servers, libraries, and databases.

JRuby on Rails fits nicely into a Java EE environment because you can continue to use all the common enterprise resources that you've always used in your previously all-Java technology environment. You can use pooled database connections, Java Naming and Directory Interface (JNDI), Java Persistence API (JPA), Java Management Extensions (JMX), Enterprise JavaBeans (EJB), and all other libraries that exist in your enterprise applications.

How Will Ruby and JRuby Change in the Future?

Java EE platform support for Rails will definitely improve in the future. You should expect to see many of the Java EE platform APIs appear directly in Rails. Additionally, Rails does not have the same level of support for some technologies as you can find in the Java platform. Most notably, Ruby support for the current XML standards may not be equivalent to the support you find in the Java platform.

* As used in this document, the terms "Java virtual machine" or "JVM" mean a virtual machine for the Java platform.
 
For More Information

JRuby

Rate and Review
Tell us what you think of the content of this page.
Excellent   Good   Fair   Poor  
Comments:
Your email address (no reply is possible without an address):
Sun Privacy Policy

Note: We are not able to respond to all submitted comments.