Move over, Java. There's more to the Java Virtual Machine than just the Java language these days -- and the field of languages for JVM is growing.
Conceived as a mechanism to provide Java application portability across multiple hardware varieties and operating systems, the JVM now accommodates other languages, ranging from dynamic languages such as JRuby, Jython, and Clojure to the statically typed Scala language. Thus, the JVM is becoming a polyglot platform, where developers can take advantage of different languages for different needs.
The reason the JVM has become so attractive for other languages is the Java platform offers performance and other advantages, says Tim Bray, Sun Microsystems' director of Web technologies. "These days, the JVM, especially HotSpot, has extremely high performance. Second, there's a huge universe of Java libraries. One of the hard problems in getting a new language going is assembling all the necessary libraries to make it useful; on the Java platform you get those for free," he says. Many enterprises also will not deploy anything that does not fit into the Java ecosystem, he notes.
Java the platform taking more prominence than Java the language
Sun's Bray emphasizes that the Java platform is becoming more important than the language itself: "I personally think that the Java platform has more strategic importance than the Java language, going forward."
"The JVM has been absolutely great for us because it really has improved performance very steadily essentially in every new generation," says Martin Odersky, developer of the Scala language. Scala can replace Java in a company's infrastructure, he notes, citing Sony Pictures as a case in point.
Still, JVM proponents do not see the Java language being made obsolete by the increasing use of other languages in the JVM. "Java remains the world's most popular programming language and will be at the core of enterprise and systems programming for the foreseeable future," Bray says.
"If anything like that would happen, it would be in the very, very far future," Odersky says. Java has huge momentum behind it and most companies are reluctant to change, he notes. Still, it is "likely that Scala and some other languages will gain programmer share on the JVM platform and that the platform will become more polylingual than it is now," Odersky adds.
One reason JVM may become more polylingual is Sun's Da Vinci Machine project, which promises to simplify the running of dynamic languages on the JVM. "The Da Vinci Machine work-around [Java Specification Request] 292, designed to make it easier for dynamic-language implementers to get good performance on the JVM, is going to improve the platform's attractiveness to the dynamic language community beyond where it is today. That work deserves close attention going forward," Bray says.
Dynamic languages are good for solving problems where the answer is not necessarily known when starting out, such as in building Web applications, especially because there is no one "right" way to build a Web application, says Clojure author Rich Hickey. By contrast, Java is a good language for implementing another version of a solved problem; lower-level infrastructure apps are particularly suitable for Java, he notes.
Several languages bring better capabilities to the JVM
JRuby and Jython proponents call their languages a supplement to Java, not a competitor. "Jython is much more of a supplement to Java on the JVM," says Frank Wierzbicki, a Jython project lead. "JRuby is definitely a supplement. It is something you can use instead of Java when the situation is right for that. JRuby enhances the Java platform by bringing Ruby to it," says Ola Bini, a JRuby core developer.
JRuby has been the arguably most visible of the dynamic languages riding on the JVM lately. It dates back to 2001 and is an implementation of the Ruby language. "Having Ruby on the JVM is important for two reasons. First, it gives Java developers access to a programming language that is higher-level," Bini says. Second, "Ruby [has] lots of interesting libraries such as Rails and RSpec that can be used on top of the JVM. Being on the JVM also means that when using Ruby you still have access to all the existing Java libraries. JRuby can use any Java class as if it was a Ruby class. This means you get the combined power of both the Ruby language and ecosystem and the Java environment," he says.
Meanwhile, Jython goes all the way back to July 1998 when it was called JPython, Wierzbicki notes. "There is a vast amount of Java out there, and Jython provides a way to access that code from the highly productive Python language," he says. For example, Jython has been used by testing frameworks as an embedded scripting tool.
"I've spoken at many Python conferences like PyCon, EuroPycon, and EuroDjangoCon and I have found that many in the Python community really want to be able to use Python on the JVM," he adds.
Also atop the JVM is Clojure (pronounced "closure"), developed to support functional style and better concurrent programming on the JVM, says Hickey. It is leveraged for multithreaded application development. "The intent of Clojure is to be useful wherever Java is useful," Hickey notes -- thus its use of Java libraries and a syntax to support Java calls transparently.
Debuting in 2004 and boasting Twitter and LinkedIn as users, Scala arose out of Odersky's desire to improve on Java. While the Java platform has offered capabilities such as type safety and garbage collection for object disposal, more was needed, he says. "We wanted to make Java more expressive, so people could be more productive" and write at a higher level of abstraction with fewer lines of code, Odersky says. Scala differs from other JVM-compatible languages such as JRuby, Jython, and Clojure in that it deploys a refined static type system and offers more expressive programming, he says.
Another language for the JVM is Groovy, which has a mixed reputation among developers. Billed as "an agile dynamic language for the JVM," Groovy builds on Java strengths while also offering features inspired by languages such as Ruby and SmallTalk, says the Groovy Web page on Codehaus.
"It's definitely easier to program," with Groovy than Java, says Jon Travis, principal software engineer at SpringSource, which oversees development of the Groovy language. "Groovy all around adds a lot of expressiveness for people who are very familiar with Java," he notes.
PHP so far not catching on among JVM developers
While Ruby and Python implementations have gained a foothold on the JVM, the same oddly is not true for the popular PHP language, says Sun's Bray. "The No. 1 candidate that people are working [on] but isn't really there yet in terms of widespread adoption is PHP," he notes.