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).
分享到:
相关推荐
《From Java to Ruby》这本书是Java开发者转向Ruby语言的一份宝贵资源。它引导读者了解从传统的Java编程环境过渡到Ruby的动态世界时所遇到的概念差异和技术挑战。Ruby是一种灵活、简洁且富有表现力的编程语言,它...
### 从 Java 到 Ruby:理解两种编程语言的转变 #### 概述 《从 Java 到 Ruby》这本书由 Bruce Tate 所著,旨在帮助 Java 开发者了解并过渡到 Ruby 这一更为灵活和高效的编程语言。本书不仅对 Ruby 的核心概念和...
### 从 Java 到 Ruby:每位管理者应知之事 #### 引言 随着技术的不断发展,编程语言也在不断地演进。对于很多企业来说,选择合适的技术栈是至关重要的一步。《从 Java 到 Ruby:每位管理者应知之事》这本书正是为了...
Based on the bestselling first and second editions, Beginning Ruby, Third Edition is a leading guide to learn Ruby from the ground up. The new edition of this book provides the same excellent ...
压缩包中的文件列表暗示了这可能是一本电子书的资源,例如 "Pragmatic.Bookshelf.From.Java.to.Ruby.Jun.2006.pdf",这可能来自 Pragmatic Bookshelf 出版社,一家知名的程序员图书出版商。"intro.txt" 可能是书籍的...
- **特性与优势**:详细阐述Ruby语言的主要特点,如简洁性、面向对象、动态类型等,并对比其他编程语言如Java、Python等,突出其独特之处。 ##### 2. Ruby基础语法 - **数据类型**:讲解Ruby中的基本数据类型,包括...
Like Smalltalk, it is dynamically typed (as opposed to Java or C++), but unlike Smalltalk, Ruby features the same conveniences found in modern scripting languages such as Perl and Python. The ...
### Ruby语言介绍与基础知识 #### 一、Ruby语言概述 **1.1 Ruby的历史** Ruby是一种面向对象的脚本语言,由日本人松本行弘(Matsumoto Yukihiro)于1993年开始开发。起初,Ruby是作为一种兴趣项目而诞生的,但...
This section likely covers the basic command-line usage of the `ruby` command and how to run scripts directly from the terminal. - **Using a Shebang Line on Unix/Linux:** Discusses the use of the ...
- **循环控制**: Java中的循环控制语句相对固定,而Ruby提供了更多的灵活性。 ```java // Java for (int i = 1; i ; i++) { System.out.println(i); } ``` ```ruby # Ruby (1..10).each { |i| puts i } ``...
From Java To Ruby – Free Pdf Book
在Java中,你可以利用内置的ScriptEngine接口和相关的脚本引擎实现对不同脚本语言(如JavaScript、Groovy、Ruby等)的支持,从而在应用程序中进行动态计算、数据处理或者扩展功能。JavaMail则是Java中用于处理电子...
The author focuses on practical programming aspects and covers a broad range of topics, from basic introduction to the Python language on the Java platform (Jython), to descriptive statistics, ...
The target audience is largely Java developers but the book also supports PHP and Ruby developers who want to learn about Couchbase. The author supplies examples in Java, PHP, Ruby, and JavaScript.
What You'll Learn:* How to use a Java client and MongoDB shell * How to use MongoDB with PHP, Ruby, and Node.js as well* How to migrate Apache Cassandra tables to MongoDB documents; Couchbase to ...