Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what are the major differences and similarity in java and ruby? [closed]

Tags:

java

ruby

I am java professional now I like to go for ruby.Are there any similarity in both the languages? and what are the major differences? As both are object oriented.

like image 345
giri Avatar asked Jan 07 '10 03:01

giri


2 Answers

What about these:

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.
  • All member variables are private. From the outside, you access everything via methods.
  • 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.
  • The constructor is always named “initialize” instead of the name of the class.
  • You have “mixin’s” instead of interfaces.
  • == 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).

Taken from: To Ruby From Java

like image 193
OscarRyz Avatar answered Sep 28 '22 06:09

OscarRyz


Besides being object oriented there are very few similarities between the two languages. Java is a statically typed compiled language while ruby is a dynamically typed interpreted language. The syntax is also very different. Java uses the c convention of terminating lines with a semi-colon while ruby uses the return character.

While Java does have some built in support for iterators ruby's uses of iterators is pervasive throughout the language.

This obviously only touches upon a comparison of the two. This is a decent write-up on the comparisons

like image 24
ennuikiller Avatar answered Sep 28 '22 07:09

ennuikiller