ArticleslgStudy

computer science

JRuby

JRuby is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand JRuby rather than just read about it. In short: JRuby is an implementation of the programming language Ruby on the Java virtual machine, written largely in Java. It is free software released under a three-way Eclipse Public License (EPL); GNU General Public License (GPL), GNU Lesser Public License (LGPL).

JRuby — main illustration
JRuby — illustration

Key takeaways

  • JRuby belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect JRuby to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of JRuby from memory before moving on to harder problems.

Reference excerpt

JRuby is an implementation of the programming language Ruby on the Java virtual machine, written largely in Java. It is free software released under a three-way Eclipse Public License (EPL); GNU General Public License (GPL), GNU Lesser Public License (LGPL). JRuby is tightly integrated with Java to allow embedding the interpreter into any Java application with full two-way access between Java and Ruby code (similar to Jython for the Python language). JRuby's lead developers are Charles Oliver Nutter and Thomas Enebo, with many current and past contributors including Ola Bini and Nick Sieger. In September 2006, Sun Microsystems hired Enebo and Nutter to work on JRuby full-time. In June 2007, ThoughtWorks hired Ola Bini to work on Ruby and JRuby. In July 2009, the JRuby developers left Sun to continue JRuby development at Engine Yard. In May 2012, Nutter and Enebo left Engine Yard to work on JRuby at Red Hat.

History JRuby was originally created by Jan Arne Petersen, in 2001. At that 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.6, an effort began to update JRuby to 1.8.6 features and semantics. Since 2001, several contributors have assisted the project, leading to the current (2012) core team of around six members. JRuby 1.1 added just-in-time compilation (JIT) and ahead-of-time compilation (AOT) modes to JRuby and was already faster in most cases than the then-current Ruby 1.8.7 reference implementation. JRuby packages are available for most platforms. In mid-2008, Fedora Linux 9 was among the first to include it as a standard package at JRuby 1.1.1. In July 2009, the core JRuby developers at Sun Microsystems, Charles Oliver Nutter, Thomas Enebo, and Nick Sieger, joined Engine Yard to continue JRuby development. In May 2012, Nutter and Enebo left Engine Yard to work on JRuby at Red Hat. JRuby has supported compatibility with Ruby MRI versions 1.6 through 1.9.3. JRuby 1.0 supported Ruby 1.8.6, with JRuby 1.4.0 updating that compatibility to Ruby 1.8.7. JRuby 1.6.0 added simultaneous support for Ruby 1.9.2, with JRuby 1.7.0 making Ruby 1.9.3 the default execution mode (Ruby 1.8.7 compatibility is available via a command-line interface flag). JRuby 9.0.0.0 added support for Ruby 2.2. The current version of JRuby (10.0.3.0) targets Ruby 3.4.

Ruby on Rails JRuby has been able to run the Ruby on Rails web framework since version 0.9 (May 2006), with the ability to execute RubyGems and WEBrick. Since the hiring of the two lead developers by Sun, Rails compatibility and speed have improved greatly. JRuby version 1.0 successfully passed nearly all of Rails's own test cases. Since then, developers have begun to use JRuby for Rails applications in production environments.

Multiple virtual machine collaboration On February 27, 2008, Sun Microsystems and the University of Tokyo announced a joint-research project to implement a virtual machine capable of executing more than one Ruby or JRuby application on one interpreter.

Dynamic invocation on Java virtual machines JSR 292 (Supporting Dynamically Typed Languages on the JavaTM Platform) proposes:

adding a new invokedynamic instruction at the JVM level, allowing method invocation using dynamic type checking, dynamically changing classes and methods at runtime. The Sun Open source project Multi Language Virtual Machine aims to prototype this JSR. The first working prototype, developed as a patch on OpenJDK, was announced and made available on end of August 2008. The JRuby team has implemented dynamic invocation into their codebase. Dynamic invocation initially shipped with the 1.1.5 release in a primitive form. Version 1.7.0 enabled it by default on Java 8 builds.

Release history This table presents only releases that present significant steps in JRuby history, aside from versions that mainly fixed bugs and improved performance. Performance improvements are also not shown in the table below, as every release has usually brought such improvements.

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 compiling to JVM 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 JVM bytecode, or ahead-of-time compiled to JVM bytecode before execution. Until October 2007, only the interpreted mode supported all Ruby constructs, but a full AOT/JIT compiler is available since version 1.1. The compiler design allows for interpreted and compiled code to run side-by-side, and for decompiling to reoptimize and outputting generated bytecode as Java class files.

Frameworks support JRuby has built-in support for Rails, RSpec, Rake, and RubyGems. It embeds an FFI subsystem to allow the use of C libraries bundled as gems. It also allows launching the Interactive Ruby Shell (irb) as Ruby MRI does. The Netbeans Ruby Pack, available in NetBeans 6, allows integrated development environment (IDE) development with Ruby, JRuby, and Ruby on Rails for both implementations of Ruby. It is no longer included in NetBeans 7.0 and later.

Programming

Ruby meets Java JRuby is similar to the standard Ruby interpreter except written in Java. JRuby features some of the same concepts, including object-oriented programming, and dynamic typing as Ruby. The key difference is that JRuby is tightly integrated with Java, and can be called directly from Java programs. Java has significant footing in the development of web applications.

JRuby calling Java 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 JFrame with a JLabel:

JRuby also allows the user to call Java code using the more Ruby-like underscore method naming and to refer to JavaBean properties as attributes:

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with JRuby

Start with the simplest possible case. Write down what JRuby claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to JRuby before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about JRuby ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of JRuby

In research
JRuby appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses JRuby in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
JRuby is common in secondary-school and first-year university syllabi. It links to neighbouring topics Free software programmed in Java, Free software programmed in Ruby, JVM programming languages, so understanding it makes those chapters shorter.
In everyday life
Look for JRuby outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “JRuby” →

How to study JRuby in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what JRuby means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain JRuby out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is JRuby in simple terms?

JRuby is an implementation of the programming language Ruby on the Java virtual machine, written largely in Java. It is free software released under a three-way Eclipse Public License (EPL); GNU General Public License (GPL), GNU Lesser Public License (LGPL).

Why does JRuby matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study JRuby?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on JRuby.

Tags

  • Free software programmed in Java
  • Free software programmed in Ruby
  • JVM programming languages
  • Object-oriented programming languages
  • Ruby (programming language)
  • Scripting languages
  • Software using the Eclipse Public License

Keep exploring