To Ruby From Java

Java is mature. It’s tested. And it’s fast (contrary to what the anti-Java crowd may still claim). It’s also quite verbose. Going from Java to Ruby, expect your code size to shrink down considerably. You can also expect it to take less time to knock together quick prototypes.
Similarities
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 different 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).
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值