what are the major differences and similarity in java and ruby?

what are the major differences and similarity in java and ruby?

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

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 rubys 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

what are the major differences and similarity in java and ruby?

Youre asking a very broad question. I like to compare scripting languages similarly to how Id compare spoken languages, so in this case; what are the major differences and similarities between Spanish and Italian?

If you ask that question, youre going to either get very varied or very long answers. Explaining differences between languages are difficult at best, as its hard to pinpoint key factors.

This is proved by the responses here so far, as well as the links other people have linked to. Theyre either varied or very long.

Going back to the Spanish vs. Italian analogy, I could say that the languages are similar but still very different. If you (only) know one of them, you might be able to understand whats going on in the other, though you would probably not be able to use it very well. Knowing one definitely makes it easier for you to learn the other. One is used by a larger number of people, so you might benefit more from learning it.

All of the previous paragraph can be applied to Java vs. Ruby as well. Saying that both are object oriented is like saying Spanish and Italian both are members of the Romanic language family.

Of course, all of this is irrelevant. Most probably, your underlying question is whether its worth learning Ruby instead of or in addition to Java. Unfortunately, theres no easy answer to that either. You have to weigh advantages and disadvantages with each language, such as popularity, demand and career opportunities. And then theres naturally the question of which language you prefer. You might like one language more than the other simply because it has a nicer syntax. (Similarly, you may prefer Italian because you think its more beautiful than Spanish, even though the latter is more widespread and youd have more use for it.)

Personally, I prefer Ruby. For many different reasons. Just like I prefer Italian.

Leave a Reply

Your email address will not be published. Required fields are marked *