Archive for April, 2007



Internationalization in JRuby

Monday 30 April 2007 @ 11:15 am

I have been using and teaching Java since 1995. The other day, I was talking to my students about Internationalization in Java.

Internationalization is the process of designing an application so that it can be adapted to various languages and regions without engineering changes.

Localization is the process of adapting software for a specific region or language by adding locale-specific components and translating text.

The following is a simple example (in Java) to demonstrate how to internationalize a program so that it displays text messages in the appropriate language. Notice that the text of the messages is not hardcoded.

import java.util.*;
public class InternationalizationEx
{
  public static void main(String[] args)
  {
    String lang, country;
    Locale cLocale;
    ResourceBundle msg;

    lang = new String(”de”);
    country = new String(”DE”);

    cLocale = new Locale(lang, country);
    msg = ResourceBundle.getBundle(”MessagesBundle”, cLocale);

    System.out.println(msg.getString(”greetings”));
    System.out.println(msg.getString(”welcome”));
  }
}

To compile and run the above program, you need these source files:

The internationalized program uses a language and a country code. In the above example the language code is de (German) and the country code is DE (Germany), so the program displays the messages in German:

java InternationalizationEx
Hallo
HeiBen Sie Willkommen nach Indien

If the language code is en (English) and the country code is US (United States), the program displays the messages in English:

java InternationalizationEx
Hello
Welcome to India

The arguments passed to the getBundle method identify which properties file will be accessed. The first argument, MessagesBundle, refers to this family of properties files:

  • MessagesBundle_de_DE.properties
  • MessagesBundle_en_US.properties

The Locale, which is the second argument of getBundle, specifies which of the MessagesBundle files is chosen. When the Locale was created, the language code and the country code were passed to its constructor. Note that the language and country codes follow MessagesBundle in the names of the properties files.

You may be wondering what’s the point of this post and that too about code in Java, whereas RubyLearning.com is a blog that talks about Ruby and Rails!

Internationalization in JRuby

Well, since I am currently exploring JRuby, I wanted to call these Java classes in Ruby using JRuby. In Ruby, one can use Masao Mutoh’s Ruby-GetText-Package to do the same, though personally I find it quite cumbersome to use.

So here’s JRuby to my rescue! The program code in JRuby is:

#javaInternational.rb
require 'java'

module JavaLang
  include_package "java.lang"
end

ResourceBundle = java.util.ResourceBundle
Locale = java.util.Locale

lang = JavaLang::String.new("de")
country = JavaLang::String.new("DE")

cLocale = Locale.new(lang, country)
msg = ResourceBundle.getBundle("MessagesBundle", cLocale)

puts msg.getString("greetings")
puts msg.getString("welcome")

Run the program on a command prompt as follows:

jruby javaInternational.rb

It works! Okay, a little explanation of some of the JRuby code - There can be name clashes between Java class names and Ruby class names. String is an example of this; Java has java.util.String and Ruby also has Kernel::String. To resolve this name clash, define a Ruby module that includes the Java class definition as follows:

module JavaLang
  include_package "java.lang"
end

If you know Java and have started using Ruby, please do explore JRuby - you shall not be disappointed.

Technorati Tags: , , ,

Posted by Satish Talim



Startups.in Interview

Sunday 29 April 2007 @ 8:51 am

Nag. B is the brain behind Startups.in. Startups.in simplifies the establishment of startups through a collaborative approach that is a win-win situation to all the involved members. I’ve invited Nag to share some of his experiences in this interview.


Nag. B

Could you tell us something about yourself - your background, where you are based…?

Satish, thank you very much for your interest in Startups.in and I appreciate you taking time in featuring us on your highly regarded site.

So far, I’m yet another Indian currently based in US. I work for a company that provides offerings to create the Internet solutions and enables people to make powerful connections.

Personally, I also have a deep passion and a strong fascination about startups and entrepreneurship and Startups.in/India is an outlet to share these interests with others.

Could you tell us a little more about Startups.in?

As with any other venture it all started with an idea. In this case, the idea was to bring to fore the spirit of entrepreneurship in India and provide a common platform to connect startups, more specifically, startups in India. Startups.in/India is the first step towards realizing that idea.

The venture has been active for less than an year now and the focus so far has been to feature startups in India with two primary goals -

  • help spread the word out to the world about the startups in India and
  • help the future entrepreneurs learn from the experiences of the seasoned entrepreneurs.

Based on the feedback being received and looking at the way Startups.in/India is molding itself, I believe we are on the right track to meet our goals.

Startups.in is a central site that binds all other value add-in applications and other sites like:

  • Startups.in/Jobs - a free job posting site
  • Startups.in/Videos - a collection of educational videos highlighting entrepreneurship and technology etc., in addition to others.

Why did you decide to use Ruby on Rails (RoR) for this site?

As any other web based project developer, I too would prefer a framework that would allow us to churn better software which is easy to maintain with a quick turnaround time. I believe any framework that can meet these requirements would not only be a efficient choice but would also be “cost effective” for bootstrapped startups.

While I’m not an authority on web application frameworks, I’ve been keenly following the discussions on various websites and RoR seems to fit my requirements very well.

Again, this is coming from some one who did not have a first hand experience at RoR and I therefore have started seeking expert advice from well respected professionals like you who have been in this Industry for a long time.

What’s your impression about the RoR scene in India?

I will not claim much expertise here but from whatever I’ve been reading and following through the media, RoR as a whole still has a long to way before it goes mainstream and experiences a higher adoption rate. As far as RoR scene in India is concerned, the “scene” is still in its “opening act” and the “rail” is yet to pick up the “steam”.

But given its obvious advantages and with efforts from evangelists like you, I’m sure RoR will be on the express track very soon across India with Pune as its hub.

What are your future plans for Startups.in?

More than highlighting the products/services, Startups.in/India is about entrepreneurship and the entrepreneurial spirit behind these startups in India. In my personal opinion what really deserves a focus is not just the startups but the passionate entrepreneurs driving them.

While we will continue to drive Startups.in/India with that focus, we will also continue to explore, innovate and offer better ways to help startups. Startu.ps will be our launch pad.

Thanks once again for the opportunity, Satish.


Information

There are many sites and blogs that conduct free hosting reviews. If you are interested in getting you own domain name you should take a look at these reviews. Also there are many things to consider while getting a hosting plan. Like many hosting companies offer free services along with their hosting plans e.g. affiliate marketing, web templates, search engine submission but on the other side they are not that good at taking backups etc. They are trying to cover this discrepancy by offering free services; startlogic offers quality web hosting in this context. Also many isp now offer the services of web hosting and some offer free wireless internet along with taking hosing plan from them.


Technorati Tags: , , , , ,

Posted by Satish Talim



JRuby: Caffeinated Ruby

Friday 27 April 2007 @ 11:52 am

Recently, JRuby has been gaining more and more attention in the Java and Ruby communities. Java is a powerful platform and there are millions of lines of Java code being written each month, that the world will have to live with for a long time from now. By leveraging Java the platform with the power of the Ruby programming language, programmers get the best from both worlds. You better not ignore JRuby any more!

What is JRuby?

JRuby is a 100% pure-Java implementation of the Ruby programming language that runs in the JVM. JRuby’s creators, Thomas Enebo and Charles Nutter, have been hired by Sun to work on JRuby full time. The current JRuby release 0.9.9 is fully compatible with Ruby 1.8.5.

Ola Bini says that “JRuby is ready for prime time. Application developers should try their applications on JRuby NOW.”

So, I decided to take a quick look at JRuby and found it very easy to use.

Download and Setup:

  • The JRuby distribution comes as a tar.gz file, namely jruby-bin-0.9.9.tar.gz
  • Uncompress the archive; you should end up with a jruby-0.9.9 folder.
  • In Windows, set the system environment variable JRUBY_HOME to C:\jruby-0.9.9 I am assuming that you have uncompressed JRuby to C:
  • Also, set the system environment variable path to C:\jruby-0.9.9\bin;
  • The JRuby distribution’s bin directory contains the jruby.bat file that is used to run the JRuby interpreter. Run the command jruby -version from the command line to test that the JRuby is working. On my PC, it said:
    ruby 1.8.5 (2007-04-23 rev 3539) [x86-jruby0.9.9]

Where to use JRuby?:

a. JRuby allows Ruby programs to use Java classes. This is a powerful concept that JRuby now brings to Ruby users. My Ruby/Tk Tutorial has a program p075hellotk1.rb that uses Ruby/Tk a graphical user interface. However, the documentation for Ruby/Tk is extremely poor and I would be comfortable in using Java Swing instead. The code in JRuby for the program p075hellotk1.rb can be something like this:

# javaSwingHello.rb
require 'java' # Line 2
JFrame = javax.swing.JFrame
JLabel = javax.swing.JLabel
frame  = JFrame.new
jlabel = JLabel.new("Hello World")
frame.add(jlabel)
frame.setDefaultCloseOperation(JFrame::EXIT_ON_CLOSE)
frame.pack
frame.setVisible(true)

Run the above program from the command line as follows:

jruby javaSwingHello.rb

Line 2: The second line of the above program enables JRuby’s Java support and allows a Ruby program to use Java classes.

b. Calling JRuby from Java. JRuby can just as easily be called from Java, using either the JSR 223 Scripting for Java 6 or the Apache Bean Scripting framework. More information on this is available in the JRuby Wiki

c. Running Rails with JRuby. The advantages are obvious. To quote the JRuby Wiki:

  • Gives Rails the power and functionality of Java: Virtual Machine, application servers, and libraries.
  • With future JVM and JRuby improvements, JRuby may be faster than Matz’ Ruby Interpreter in running Rails
  • Gets Rails in the door of Java shops by making Rails apps into Java-platform apps.

To conclude, I am surely liking JRuby and would definitely explore it further. Ignore JRuby at your own peril !

Resources:

Go on! Digg It !

Technorati Tags: , , ,

Posted by Satish Talim



Interview: Charles Nutter

Thursday 26 April 2007 @ 9:26 am
Charles Nutter

(This interview appeared before on 30th Aug. 2006 on the PuneRuby blog).

Today’s talk with Ruby Guru, Charles Nutter would be of interest to all of you who have a Java background.

Satish Talim>> Hello Charles, and welcome to PuneRuby. Could you tell us something about yourself - your background; where you are based…?

Charles Nutter>> I’ve been programming computers since I was in grade school. Since 1996 I’ve been a fulltime Java developer, primarily working on web-based applications using Java EE technologies. My most recent job has me as application architect for a number of large Java EE applications, making technology decisions and setting project direction. However for the past year my true love has been JRuby, a Ruby implementation for the JVM. I have devoted much of my free time to making JRuby compatible with Ruby, so Java developers might be able to take advantage of the beauty and power of Ruby.

I am based in the Minneapolis area in the state of Minnesota in the United States.


You can learn HTML as a first step into web programming.

Satish Talim>> Given the choices out there, why did you select Ruby?

Charles Nutter>> I came to Ruby via a recommendation from a friend. Before I’d ever written a line of code, I found that RubyConf 2004 would be held within a few miles of my employer’s home office. I arranged to attend, and was amazed by the level of energy, the enthusiasm of the attendees, and especially the ingenuity and simplicity of the applications and libraries being presented. I began to believe I might have finally found a scripting/dynamic language I could really love. While at the conference, I wondered if there might be a Java implementation of Ruby. That led me to JRuby, and I’ve been a Rubyist and JRubyist ever since.

Satish Talim>> How did you learn Ruby and when?

Charles Nutter>> I’ve learned Ruby a bit differently than most folks; namely, from the inside out. In the process of helping to redesign and reengineer JRuby, I’ve had to learn the language, obviously, but I’ve also had to learn how JRuby and the stock Ruby interpreter work internally. That’s taught me more about the language than any other source, since I’ve had to develop a deeper understanding of features most books and documents only cover from a Ruby point of view. I’m hoping to take my knowledge of Ruby to organizations interested in advancing the language and advancing JRuby, so that the Java world I know and love can benefit from Ruby as well.

Satish Talim>> Which features of Ruby do you like the most?

Charles Nutter>> Closures are certainly the most visible and compelling feature of Ruby…so compelling that most other platforms and languages are compared to Ruby simply by how easily they can implement or present closures. I also like that the language is very terse but very readable, and that whitespace is not syntactically important. Though there are perlisms, most code I’ve had the pleasure to read is still very clear in its intent. I believe Ruby has been carefully evolved not to fulfill some higher vision of what a language ought to do, or to show off crazy language feature X, but to really help people get work done. As has been said many times before, Ruby makes simple problems easy and difficult problems possible. That’s exactly what we need in the Java world, since so many problems we solve again and again with too much code are really very simple at their core.

Satish Talim>> Do you think Ruby has the potential to be a mainstream programming language?

Charles Nutter>> Absolutely, and I think it’s already on its way. The mainstream press has started to realize that the Ruby Way is gathering a lot of momentum, and now major software companies are starting to investigate and fund research in the Ruby world. I believe that Ruby is the best scripting/dynamic language currently available, and I am not at all surprised that its popularity has exploded recently. I have introduced friends and family to Ruby and in every case they have told me “if only I had learned Ruby first, I might have [finished my degree|continued in school|understood programming...]“. It’s simply awe-inspiring how easily people can become productive with Ruby. It has the potential to change the world.

Satish Talim>> What applications, utilities have you developed in Ruby and what platform are you running these applications on?

Charles Nutter>> I have been working almost exclusively on JRuby, a Ruby implementation in Java originally written in 2001. During the two years I’ve been on the project, we’ve worked furiously to improve compatibility with Ruby 1.8, fixing bug after bug after bug and adding as many tests as possible. Over the past nine months, I’ve led efforts to get more complicated applications working like IRB, RubyGems, and Ruby on Rails, to the point that most pure Ruby applications now “just work” under JRuby. I’m very excited that I and other Java developers will now be able to use Ruby alongside our Java code and libraries, within our Java application servers, and in concert with our existing Java infrastructure. The potential for JRuby is enormous, and we’re only seeing the tip of the iceberg right now.

JRuby has taken most of my free time, but I have many other projects on which I plan to spend more time. I’d like to make Rake into a full-fledged replacement for Ant. I’d like to wire in JRuby’s extension mechanism to allow transparent installation of Gems that have native code components. I want to continue to help efforts to get Mongrel running under JRuby. I want to help build out the RubySpec Wiki, an effort to document in a tighter specification format the functioning of Ruby and its libraries. I want to build out tool support for Ruby in the NetBeans IDE. I want to help efforts to build code refactoring capabilities for Ruby. I want to help bring disparate test frameworks and libraries together into a comprehensive suite of RubyTests. I want to make as many existing Ruby apps run well under JRuby as possible. I want to bring the world of Ruby to the world of Java, and help both worlds gain maximum benefit from each other. They’re big goals, but I know they’re all possible…and I think they’re inevitable.

Satish Talim>> Anything else you would like to share with the PuneRuby members?

Charles Nutter>> Have a look at JRuby, especially if you have Java libraries, legacy Java code, or existing Java servers and infrastructure you’d like to Rubify. JRuby has become a viable Ruby interpreter in its own right, but it’s even more compelling as a way to write Java Platform-based applications in a simple, beautiful language. Think of Ruby on the JVM like Ruby under UNIX: Java and C are excellent, powerful languages for writing core components, libraries, and frameworks, and Ruby helps programmers tie the power of those components, libraries, and frameworks together into applications with a minimum of effort. JRuby is hosted on Codehaus, and we welcome code contributions and mailing list discussions from anyone interested. Stop by and let us help you decide if JRuby might be the Ruby for you.

Satish Talim>> Thanks Charles for sharing your views with the PuneRuby members.

You can keep in touch with Charles Nutter via his blog.

Technorati Tags: , , , , ,

Posted by Satish Talim



Ruby on Rails in India

Tuesday 24 April 2007 @ 9:14 am

I have been asked time and again about companies in India working on Ruby on Rails. Here’s a partial list of companies (in alphabetical order) that do so.

  1. 360 Degree Interactive, Chennai
  2. Accenture Tech Labs, Bangalore
  3. Aditi Technologies, Bangalore
  4. Allerin, Mumbai
  5. Apptility, Bangalore
  6. Better Labs, Pune
  7. Blue Whale Labs, New Delhi
  8. BroadSpire, Chennai
  9. CircleSource, Bangalore
  10. CodeWalla, Pune
  11. Goldstone Technologies, Hyderabad
  12. Itellix, Bangalore
  13. MangoSpring Inc., Pune
  14. Patni Computers, Hyderabad
  15. Persistent Systems, Pune
  16. Pinstorm, Mumbai
  17. Satyam, Hyderabad
  18. SlideShare, New Delhi
  19. Subex Azure, Bangalore
  20. SurgeWorks, Mumbai
  21. Synerzip, Pune
  22. ThinkDRY, Pune
  23. Thoughtworks, Pune
  24. UrbanEye, Mumbai
  25. Uzanto, New Delhi
  26. V2 Solutions, Mumbai
  27. Viamentis Technologies, Chennai
  28. Vinsol, New Delhi
  29. WarmlyYours, Hyderabad - Christian Billen is the Chief Information Officer, IT Department.
  30. Zestadz, Chennai

Please be aware that there are many companies in India claiming to be working on ROR; be doubly sure!


Look up some India timeshares if you plan on visiting. Timeshares can be a great way to stay in a foreign land and India timeshares are no exception.

Also please feel free to comment and suggest other Indian companies working on ROR (with their URLs), that you may have come across.

Update:

  • In response to Fabio Akita’s comment, it is my opinion that most companies are still in the experimentation stage and / or executing small ROR based projects.
  • Thanks to Ajay Kumar for some more company names.

Technorati Tags: ,

Posted by Satish Talim



«« Previous Posts

RUBYGALORE.COM