Ruby vs Java

Germain Arturo Duran Torres
4 min readNov 20, 2018

--

When I decided I wanted to continue my studies with programming languages I was not sure if I wanted to expand my knowledge in JAVA or if I wanted to learn another language. Since I had minimal previous experience with JAVA from my university life and one class taken in NYU I was initially undecided. Ultimately, I decided going to Flatiron School to take a boot camp program to become a Web developer; my intention with this blog is to share a little bit about Java and Ruby, and show some basic differences or similarities. Whether you are a complete beginner or looking to enhance your knowledge, any language is the right one. Only if you are willing to put in the time and effort. The skills you acquire from learning a language to fluency can carry over into any other language. Find a starting point to begin: once you have learned one language, the next one comes easier.

Being a coder does take work and discipline. When we decide to take on the challenge, discover the resources available. Our language skills are adaptable, so once we’ve learned one language we can pick up others quite easily. We cannot go wrong picking a language that is in common use, and there are plenty of discussions and resources for us. Get to work, and don’t let anything stand between you and a career in coding!

JAVA

“Java is a general-purpose computer-programming language that is concurrent, class-based, object-oriented”, and specifically designed to have as few implementation dependencies as possible. It is meant to let developers “write once, run anywhere” (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation.

“Java is a special programming language based on the syntax of the C and C++ programming language. In the development of Java was carefully from the beginning to ensure that certain serious programming errors cannot even occur. So there are no pointers in Java and thus the programmer cannot accidentally access the wrong memory address. Among the programmers, Java is highly valued as an easy-to-learn, object-oriented, secure, and computer-language independent programming language”.

RUBY

“Ruby is a dynamic, interpreted, reflective, object-oriented, general-purpose programming language.”

Ruby is an interpreted scripting language. Therefore, no compilation process is required, the code is not executed directly by the processor, it is executed by the interpreter. It reads the script code and converts it at runtime into executable code.

“The language is more flexible and dynamic and allows programming constructs such as reflection, dynamic typing or dynamic scoping. But above all, it brings the great advantage of Transportability with itself. Ruby code is platform independent and can run on any machine that has a Ruby interpreter. Ruby interpreters are available for today’s popular platforms Windows, Mac OS X and Linux, but some classic operating systems such as MS-DOS, Mac OS 9 or IBM OS / 2 also have sophisticated environments.”

Some basic similarities and differences are:

Similarities

As with Java, in Ruby,…

  • Memory is managed for us via a garbage collector (“The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program.”)
  • Objects are strongly typed (this mean that each type of data is predefined as part of the programming language.)

Example:

We cannot Multiply or Divide two different types String vs Integer

 answer = 1 * "1"; // we cannot do this
  • There are public and private methods.
  • They are object oriented

Differences

Unlike Java, in Ruby,…

  • We don’t need to compile your code. We just run it directly.
  • Everything is an object, including numbers like 2 and 3.14159.
  • There are no type declarations. We just assign to new variable names as-needed ( a = [1,2,3] rather than int[] a = {1,2,3}).
  • The constructor is always named “initialize” instead of the name of the class.

What is the best programming language to learn first?

When comparing Java vs Ruby, I found that the Slant community (Slant is a platform to ask questions and get independent answers and recommendations for several products, games, and software, etc.) recommends Ruby for most people. The Slant community ranked Ruby 4th while Java is 18th. The most important reason people chose Ruby is:

“Ruby has a very clean syntax that makes code easier to both read and write than more traditional Object Oriented languages, such as Java.”

Finally, giving a final and general conclusion about the differences and similarities I can say Ruby is an interpreted scripting language, whereas Java is a compiled programming language. Ruby is similar to Java in that both are object-oriented languages and are strongly typed.

Being a programmer means we will spend our time coding all the time, but that is what we are passionate about and we are lucky enough that we can do it everywhere with our computer.

--

--