Channels ▼

JVM Languages

JVM Languages Today

Since 2005 or so, the Java virtual machine (JVM) has become a popular platform to host more than just Java code for execution. Other language developers rely upon the "write-once, run-anywhere" nature of the JVM (as well as other advanced features) to provide the runtime environment for their own languages. In fact, porting language interpreters to the JVM became so popular that Sun hired high-profile language developers — Charles Nutter (JRuby), Ted Leung (Jython), and others — to accelerate the porting efforts.

More Insights

White Papers

More >>


More >>


More >>

Why have so many languages, including Ruby, Groovy, and Python, been ported to Java? Mainly because it's much easier to target one platform (Java code, in this case) and rely on the multiplatform JVM to host it than it is to write interpreters for each operating system. In addition, with the JVM's advanced just-in-time compilation, the resulting compiled and optimized Java bytecode typically will run with equal or better performance than native interpreters. Further, the Java JIT compiler continues to optimize code well after it's first compiled, depending upon changes in code execution and branching. The cost and effort associated with building this performance optimization into each independent interpreter implementation is prohibitive, so it makes sense to leverage the JVM's existing multiplatform implementation.

The JVM has other useful features, such as a large set of well-tested libraries, garbage collection, and excellent built-in tools and debugging interfaces that a language developer can easily plug into.

Bridging The Gap

Although writing language interpreters in Java offers huge benefits in terms of performance and multiplatform support, the biggest win is the interoperability it provides. For instance, Ruby code executing on the JVM is readily callable from a Java application, and vice versa. As a result, entire libraries of Java code, in source or JAR form, are instantly available to developers building applications in these other languages. Conversely, Java developers can experiment with code written in these other languages as well.

However, prior to the release of Java SE 7 last year, there was a small performance penalty when calling to and from the ported languages, such as when calling Ruby code from a Java application, or Ruby code calling into Java classes in a JAR file. This was mainly because the JVM wasn't initially built to support dynamically typed languages. To eliminate the performance penalty, the JSR-292 initiative was started with the goal of creating a new binary instruction (bytecode in Java nomenclature).

The result was the invokedynamic bytecode, which is a JVM enhancement that allows dynamic and direct linkage between the calling code and the called code at runtime. With Java 7, invoking code in other languages is now equivalent to calling straight Java methods.

JVM Languages

You can put languages ported to JVM into three categories: those whose primary goal is to improve Java, those that are ports of existing languages, and a miscellaneous category. All the of them are open source, and they fall out roughly this way:

  • Better Java: Groovy, Scala, Kotlin, Fantom, Gosu, NetRexx (the original JVM scripting language);
  • Ported languages: JRuby (port of Ruby), Jython (port of Python), Clojure (modified port of Lisp);
  • Miscellaneous: Rhino (JavaScript syntax designed to be called from Java programs).

Beyond Invokedynamic

As for the future of JVM language support, Oracle announced Project Nashorn (German for Rhino) at JavaOne 2011, which is an advanced JavaScript engine that's built using invokedynamic. Planned for Java Development Kit 8, due late next year, the Nashorn JavaScript engine will work closely with the Oracle Hotspot JVM to provide optimal performance, and allow seamless Java-to-JavaScript (and reverse) method calls. Plans for JDK 9 include further optimization regarding Java-to-native calls (JNI), a unified type system, and the meta-object protocol. The goal is to provide a more generic set of rules and descriptors for the code being written, regardless of language, and achieve symbolic freedom (non-Java-specific types) throughout the JVM. Of course, as improvements are made to the JVM runtime performance, JIT optimization, and platform support (including embedded), as they have been with each Java release, all dynamic languages built on top of the JVM benefit as well.

Related Reading

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.