The Artima Developer Community
Sponsored Link

Java Community News
Using Ruby from Java, Java from Ruby

5 replies on 1 page. Most recent reply: Jul 22, 2006 1:21 PM by Dalibor Topic

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

Using Ruby from Java, Java from Ruby Posted: Jul 19, 2006 8:03 AM
Reply to this message Reply
Summary
Ruby has become one of the most popular dynamic languages in recent years. A JavaWorld article shows how to use new JDK features to extend Java applications with Ruby-based scripting, and how to run Ruby code inside the JVM.
Advertisement

While discussions about programming languages often point to the differences between statically and dynamically typed languages, in the context of Java, the static-vs-dynamic debate may soon become a moot point: JDK 1.6 includes several features that allow many scripting languages to be used in conjunction with Java classes and objects.

In a recent JavaWorld article, Ruby for the Java world, Joshua Fox describes how to use Ruby in the context of some of those new JDK features, as well as JRuby, a Java-based Ruby implementation. The latter is also an example of how code written in a language other than Java can still run in the JVM:

The JVM is often contrasted with .Net's multilanguage Common Language Runtime as supporting only a single language. But in fact, the JVM executes not only Java, but also Python, JavaScript, Groovy, Scheme, and many other languages, which means that where necessary, Ruby code can interact with these languages as well. [Editor's note: code written in such languages must still compile to Java bytecode.]

The article illustrates the flexible roles Ruby can assume in a Java application:

JRuby can pull data from one system, transform it and insert it into another. When the requirements change, modifying a JRuby script is as easy as changing a configuration file, thereby avoiding the complex compile-and-deploy cycle of Java integration code.

In addition to just running Ruby code inside the JVM, the article points out the ways in which Ruby code can invoke Java classes and objects, and how Java code can interact with Ruby scripts:

In addition to running ordinary Ruby code, you can also use JRuby to construct Java objects, call Java methods, and inherit from Java classes. A Ruby class can even implement Java interfaces—necessary for statically calling Ruby methods from Java... To initialize the libraries used for accessing Java from Ruby, start with require "java". Then specify the Java classes to use with the include_class method, for example, include_class "javax.jms.Session". You can include an entire Java package into a Ruby module with include_package.

... In addition to calling Java from Ruby, you can call Ruby from Java, making your application scriptable. With JRuby's minimal syntactic overhead, you can create an easy-to-use domain-specific language for users to work with.

What do you think of JRuby and the new JDK scripting framework?


Ivan Lazarte

Posts: 91
Nickname: ilazarte
Registered: Mar, 2006

Re: Using Ruby from Java, Java from Ruby Posted: Jul 19, 2006 8:21 AM
Reply to this message Reply
Python>Javascript>TCL>>>>>>>>>>Ruby.

Morel Xavier

Posts: 73
Nickname: masklinn
Registered: Sep, 2005

Re: Using Ruby from Java, Java from Ruby Posted: Jul 20, 2006 6:52 AM
Reply to this message Reply
> Python>Javascript>TCL>>>>>>>>>>Ruby.

I must say that this "answer" is both very sad, very stupid, very false, not constructive at all, and probably a worse thing for Python than for Ruby.

And as a user of both, Ruby feels very similar to Python, and is just as good of a language.

Marcin Mielżyński

Posts: 5
Nickname: lopex
Registered: Jan, 2006

Re: Using Ruby from Java, Java from Ruby Posted: Jul 20, 2006 9:34 AM
Reply to this message Reply
Actually I feel the opposite
Javascript is the worse unreadable mistake ever (although very powerfull), that's why it's becoming to be generated by more & more frameworks/tools.
Tcl actually suffers from it's unreadibility and as a user of both Python & Ruby I feel Ruby more readable.

Ivan Lazarte

Posts: 91
Nickname: ilazarte
Registered: Mar, 2006

Re: Using Ruby from Java, Java from Ruby Posted: Jul 20, 2006 11:23 AM
Reply to this message Reply
So is it safe to say both of you were using Ruby more than a year ago?

Dalibor Topic

Posts: 26
Nickname: robilad
Registered: Mar, 2006

Re: Using Ruby from Java, Java from Ruby Posted: Jul 22, 2006 1:21 PM
Reply to this message Reply
You can also use gcj + swig to use java libraries from Ruby. Apache POI does it that way. See http://www.sengupta.net/talks/Avik_Java_Ruby.sxi

Flat View: This topic has 5 replies on 1 page
Topic: Using Ruby from Java, Java from Ruby Previous Topic   Next Topic Topic: JBoss Cache 1.4.0 Aims for Improved Scalability

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use