Saturday, July 3, 2010

OO Hello World - JRuby



Let’s have a look at the hello world program in JRuby which is the Java implementation of the Ruby programming language for the JVM runtime.

The code is identical to the previous post of IronRuby. This is because at the end, both are written in the Ruby programming language. Nevertheless, I decided to create separate posts for those developers looking for their preferred platform and also because of the “Ruby Info” section, which of course differs between the two implementations. In the future, if I post about IronRuby or JRuby I will be using their respective libraries and frameworks, so it makes sense to differentiate.


By the way, you can see my previous post here: http://carlosqt.blogspot.com/2010/06/oo-hello-world.html
where I give some details on WHY these "OO Hello World series" samples.

Version 1 (Minimal):
The minimum you need to type to get your program compiled and running.
class Greet  
 @name = ""  
 def initialize(name)  
  @name = name.capitalize  
 end  
 def salute  
  puts "Hello #@name!"  
 end  
end  
  
# Greet the world!  
g = Greet.new("world")  
g.salute
Version 2 (Verbose):
Explicitly adding instructions and keywords that are optional to the compiler.
require "java"

module GreetProgram   
 class Greet  
  @name = ""  
  def initialize(name)  
   @name = name.capitalize  
  end  
  def salute  
   puts "Hello #@name!"  
  end  
 end  
   
 # Greet the world!  
 g = Greet.new("world")  
 g.salute    
end
The Program Output:









JRuby Info:
“JRuby is a 100% Java implementation of the Ruby programming language. It is Ruby for the JVM.” Taken from: (http://kenai.com/projects/jruby/pages/AboutJRuby)

“JRuby (or Juby) is a Java implementation of the Ruby programming language, being developed by the JRuby team. It is free software released under a three-way CPL/GPL/LGPL license. JRuby is tightly integrated with Java to allow the embedding of the interpreter into any Java application with full two-way access between the Java and the Ruby code (similar to Jython for the Python language).” Taken from: (http://en.wikipedia.org/wiki/JRuby)

Appeared:
2001
Current Version:
Developed by:
Charles Nutter, Thomas Enebo, Nick Sieger, Ola Bini, Marcin Mielzynski, Bill Dortch, Wayne Meissner, MenTaLguY
Creator:
Jan Arne Petersen
Influenced by:
Ruby (Yukihiro Matsumoto)
Predecessor Language
Predecessor Appeared
Predecessor Creator
Runtime Target:
JVM
Latest Framework Target:
JDK 6
Mono Target:
No
Allows Unmanaged Code:
Yes (using native libraries)
Source Code Extension:
“.rb”
Keywords:
38
Case Sensitive:
Yes
Free Version Available:
Yes
Open Source:
Yes
Standard:
No
Latest IDE Support:
NetBeans 6.9
Eclipse
IntelliJ IDEA
Language Reference:
Extra Info:


No comments:

Post a Comment