Introduction to JRuby

JRuby is an implementation of Ruby which runs on top of Java Virtual Machine. JRuby code can be embedded in Java code and your JRuby code can interact with Java Objects and has access to every Java API.

Why to use JRuby?
Ruby being a scripting language is dynamic and much faster than Java. There are lot of things that can be easily accomplished in Ruby for example I found that parsing & scraping HTML is much easier and faster in Ruby using HPricot. As a Java programmer and you can write part of your application in JRuby and then either embed this in your Java code or use JRubyC compiler to convert your JRuby code in to Java.

Your first JRuby program

require 'rubygems'
class MyClass
  def initialize()
  def myfunction(msg)
  	puts msg;
end'Hello JRuby!');

Executing the above code can be done using the following command

1567 Total Views 2 Views Today