More Tutorials| Bioinformatics| Open Source| Photoshop| Questions? | Software Development
 

Hello World Program in JRuby

In this tutorial of JRuby we are going to tell you from the scratch for example how to install JRuby into your computer and setting path for JRuby.

Hello World Program in JRuby

                         

JRuby Introduction

JRuby team developed JRuby, which is a pure implementation of Ruby language into Java programming language. JRuby supports various features of both Java and Ruby such as Object Oriented Programming and duck-typing as Ruby. As JRuby is integrated with Java Technology, it can be directly called by Java Program. 

In this tutorial of JRuby we are going to tell you from the scratch for example how to install JRuby into your computer and setting path for JRuby. After that we have mentioned about how to check if the JRuby is installed correctly in your computer or not.

Now After installing and checking the JRuby into your computer, we will show you how to write your first JRuby "Hello World" Example. So go through this tutorial to find out more about JRuby and writing your first application in JRuby.

Running first JRuby program

Before start to write and execute your JRuby program you have to set environment for JRuby program . You must follow these few simple steps to set environment for your first JRuby application to execute successfully as follows:

  • Download jruby-bin-1.0.1.zip
  • Extract this zip file and put this folder to your directory( e.g. "C:\jruby-bin-1.0.1" in our example)
  • Set JRUBY_HOME to jruby directory ( e.g. "C:\jruby-bin-1.0.1\jruby-1.0.1" in our example)
  • Set your Path environment variable to your jruby's bin directory ( e.g. "C:\jruby-bin-1.0.1\jruby-1.0.1\bin" in our example)
  • Now open command prompt and run "jruby - version" command to check that JRuby is working or not. Output would be like this
C:\JRuby>jruby -version
ruby 1.8.5 (2007-08-23 rev 4201) [x86-jruby1.0.1]


Running first HelloWorld program

1. Create HelloWorld.rb

require "java"

stringHello= "Hello World"
stringDate = java.util.Date.new

puts "#{stringHello.to_s}"
puts "Date := #{stringDate.to_s}"

First line in our program require "java" enables use of java classes in Ruby program. In this example we have created two string objects one contains string "Hello World" and another contains "current date". "to_s" is being used to convert  returning value to string. To print expression's vale we have used puts.

Execute HelloWorld.rb with jruby command and you will get following output:

C:\JRuby>jruby HelloWorld.rb
Hello World
Date := Tue Sep 23 18:12:26 GMT+05:30 2008

Download Sample Code

                         

» View all related tutorials
Related Tags: java c ruby class tutorials tree io classes jruby vi tutorial ria set example program to learn ram exam sse

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
 
Tell A Friend
Your Friend Name

 

 
Recently Viewed
Software Solutions
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.