JRUBY
'JRuby' is a Java implementation of the Ruby interpreter, being developed by the JRuby team.
JRuby is free software released under a three-way CPL/GPL/LGPL license.
JRuby is tightly integrated with Java to allow the embedding of the interpreter into any Java application with full two-way access between the Java and the Ruby code. (Compare Jython for the Python language.)
JRuby's lead developers are Charles Nutter [1], Thomas Enebo [2] Ola Bini [3] and Nick Sieger [4]. In September 2006, Sun Microsystems hired Enebo and Nutter to work on JRuby full time.[1]
| Contents |
| History |
| Rails |
| Design |
| Installation |
| JRuby Programming |
| Ruby meets Java |
| Calling Java from JRuby |
| Calling JRuby from Java |
| Performance |
| See also |
| References |
| External links |
History
JRuby was originally created by Jan Arne Petersen, in 2001. At the time and for several years following, the code was a direct port of the Ruby 1.6 C code. With the release of Ruby 1.8, an effort began to update JRuby to 1.8 features and semantics. Since 2001, several contributors have assisted the project, leading to the current (2007) core team of four members.
The upcoming Netbeans Ruby Pack, will allow IDE development with Ruby and JRuby, as well as Rails for the two implementations of Ruby [5] [6]. A NetBeans Ruby Pack preview is available since Milestone 7 release of NetBeans 6.
Rails
JRuby supports Rails since version 0.9 (May 2006) [7] [8], with the ability to execute RubyGems and WEBrick. Since the hiring of the two lead developers by Sun, Rails support (in the areas of compatibility with the reference implementation and speed) has improved greatly. Tests of version 1.0 of JRuby execute successfully almost 100% of Rails own specific test cases[2] [3].
Design
Since early 2006, the current JRuby core team has endeavored to move JRuby beyond being a simple C port, to support better performance and to aid eventual compilation to Java bytecode. To support this end, the team set an ambitious goal: to be able to run Ruby on Rails unmodified using JRuby. In the process of achieving this goal, the JRuby test suite expanded to such extent that the team gained confidence in the "correctness" of JRuby. As a result, toward the end of 2006 and in the beginning of 2007, they began to commit much more complicated redesigns and refactorings of JRuby's core subsystems.
JRuby is designed to work as a mixed-mode virtual machine for Ruby, where code can be either interpreted directly, just-in-time compiled at runtime to Java bytecode, or ahead-of-time compiled to Java bytecode before execution. At present (Jan 2007) only the interpreted mode supports all Ruby's constructs, but a partial AOT/JIT compiler is available and improving. The compiler design allows for interpreted and compiled code to run side-by-side, as well as decompilation to reoptimize and outputting generated bytecode as Java class files.
Installation
JRuby can be installed as a standalone interpreter:
★ The user must download the binary package from JRuby's CodeHaus page.
★ The user must unzip it, and run the jruby batch.shell file from the bin directory, passing the name of a Ruby (
★ .rb) file as a command line argument.
★ The user may need to set environment variables such as JAVA_HOME and JRUBY_HOME, but if so, the batch/script file will give appropriate error messages.
JRuby can be embedded as a scripting engine in a Java application:
★ Decompress the download file.
★ Copy jruby.jar into the directory
JRuby Programming
Ruby meets Java
JRuby is essentially the Ruby interpreter, except this version is written entirely in Java. JRuby features some of the same concepts, including object-oriented programming, and duck-typing as Ruby. The key difference is that JRuby is tightly integrated with Java, and can be called directly from Java programs.
Calling Java from JRuby
One powerful feature of JRuby is its ability to invoke the classes of the Java Platform. To do this, one must first load JRuby's Java support, by calling "require 'java'". The following example creates a Java '' with a '' using "include_class":
require 'java'
include_class "javax.swing.JFrame"
include_class "javax.swing.JLabel"
frame = JFrame.new()
frame.getContentPane().add(JLabel.new("This is an example."))
frame.pack()
frame.setVisible(true)
As of JRuby 0.9.1 it is also possible to forgo "include_class":
require 'java'
frame = javax.swing.JFrame.new()
frame.getContentPane().add(javax.swing.JLabel.new("This is an example."))
frame.pack()
frame.set_visible(true)
JRuby also allows you to call Java code using the more Ruby-like underscore_method_naming and to refer to JavaBean properties as attributes:
frame.content_pane.add(label)
frame.visible = true
Calling JRuby from Java
JRuby can just as easily be called from Java, using either the JSR 223[4] Scripting for Java 6 or the Apache Bean Scripting framework. More information on this is available in the JRuby Wiki.
Performance
JRuby is still slower than the C Ruby Reference implementation [9].
For example, serving up Rails requests in the standard interpreted mode, JRuby is 50% to 70% slower than C Ruby 1.8.
When using Ruby 1.9 (YARV) benchmarks on Java 6, JRuby is 4 times slower than Ruby (including startup time), but when removing a few specific test cases, it is only 50% slower than Ruby 1.8[5].
In the upcoming JIT mode (also including startup time), JRuby achieves 93% of Ruby speed [6].
See also
★ Ruby
★ Ruby on Rails
★ BeanShell (interprets Java directly)
★ Groovy
★ JACL
★ Jython
★ YARV
References
1. Sun Welcomes JRuby Developers Jacki
2. 98,6% of the 2807 Rails specific test cases execute successfully, see JRuby Rails support
3. JRuby 0.9.8 Released
4. JSR 223: Scripting for the Java Platform Specification Request
5. thread_create_join, sieve, count_words, mandelbrot, and answer, 5 tests out of 39
6. Also after removing a few specific tests : factorial, mandelbrot, and thread_create_join, 3 tests out of 25.
External links
★ The JRuby home page
★ The JRuby Wiki
★ JRuby Roadmap for 2007
★ Roumen's Ruby Flash Demo (Part One): JRuby on Rails in NetBeans
★ Roumen's Ruby Flash Demo (Part Two): Advanced JRuby editing features in NetBeans
★ Article on JRuby at IBM DeveloperWorks
★ JavaOne 2007 Exploiting JRuby
★ JavaOne 2007 JRuby on Rails
★ [Joshua Fox, http://www.javaworld.com/javaworld/jw-07-2006/jw-0717-ruby.html "JRuby for the Java World"], JavaWorld
★ [Joshua Fox, http://www.javaworld.com/javaworld/jw-02-2007/jw-02-jruby.html "JRuby on Rails"], JavaWorld
★ Java Posse, Interview with Charles Oliver Nutter and Thomas Enebo about JRuby
★ JRuby development in NetBeans
★ Deploying a Rails Application in Tomcat
★ Calling Ruby’s ActiveRecord from Java Using the Bean Scripting Framework
★ Arun's Flash Demo: First JRuby app in GlassFish V2
★ First JRuby app in GlassFish V3
This article provided by Wikipedia. To edit the contents of this article, click here for original source.
psst.. try this: add to faves
Featured Companies
| Golf Holidays International | |
| Green Parrot Beach Houses Resort | |
| Century 21 Beltair Associates |

العربية
中国
Français
Deutsch
Ελληνική
हिन्दी
Italiano
日本語
Português
Русский
Español



