Thursday, September 27, 2012

From Ruby to Java with interactive Tutor canal.

Main difference with Java

As with Java, in Ruby,...

  • Memory is managed for you via a garbage collector.
  • Objects are strongly typed.
  • There are public, private, and protected methods.
  • There are embedded doc tools (Ruby's is called RDoc). The docs generated by rdoc look very similar to those generated by javadoc.

Differences

Unlike Java, in Ruby,...
  • You don't need to compile your code. You just run it directly.
  • There are several different popular third-party GUI toolkits. Ruby users can try WxRuby, FXRuby, Ruby-GNOME2, or the bundled-in Ruby Tk for example.
  • You use the end keyword after defining things like classes, instead of having to put braces around blocks of code.
  • You have require instead of import.
  • All member variables are private. From the outside, you access everything via methods.
  • Parentheses in method calls are usually optional and often omitted.
  • Everything is an object, including numbers like 2 and 3.14159.
  • There's no static type checking.
  • Variable names are just labels. They don't have a type associated with them.
  • There are no type declarations. You just assign to new variable names as-needed and they just "spring up" (i.e. a = [1,2,3] rather than int[] a = {1,2,3};).
  • There's no casting. Just call the methods. Your unit tests should tell you before you even run the code if you're going to see an exception.
  • It's foo = Foo.new( "hi") instead of Foo foo = new Foo( "hi" ).
  • The constructor is always named "initialize" instead of the name of the class.
  • You have "mixin's" instead of interfaces.
  • YAML tends to be favored over XML.
  • It's nil instead of null.
  • == and equals() are handled differently in Ruby. Use == when you want to test equivalence in Ruby (equals() is Java). Use equal?() when you want to know if two objects are the same (== in Java).
If you're really want to Ruby has a Kick Start , here is the interactive Tutor session given by Ruby. Learn Ruby within 20mins  http://tryruby.org/levels/1/challenges/0 

3 comments:

  1. You are the jack of all technologies.I don't see your old website, is it alive? . This page is a great understanding from java point. I moving to ruby project from last few weeks.

    pls help me to understand the between with the documentation with java and ruby.. more ? any useful hints.

    pls share your email address to share my queries :-)

    ReplyDelete
    Replies
    1. Hope you're a friend in FB, get me there :-) I failed to renew my register , difficult to maintain, So drop it. Java apps maintenance is always costly , and I hate their package like private JVM, sharing JVM etc . Need to be specific

      I'm planning to ask bill to get me a space in azure, to deploy my apps for long time :-)

      Ganesh

      Delete
  2. Nice to your journals. I have chosen ruby has my next development.
    Its a good comparison from java I love your archived articles which was hosted in www.programmingthrill.com ? dead ?
    can you help us in pushing those archives articles into this blog. hey are you in India? Missing your techno alcoholic talks

    ReplyDelete

Thanks for your comments ! Please do leave feedback