Ruby vs Java (vs JavaScript)

Daniel Mai
3 min readJun 15, 2017

Okay, it’s going to be biased: I have 3 years experience with Java, 3 months with Ruby and 3 days with JavaScript. Learning a new language is always fun, and I do enjoy all of them, but take this comparison with a grand of salt: I’m not efficient with the languages enough to provide syntax/type casting/platform/inheritance/constructor differences and similarities. Rather, this is more like my personal thought on a few interesting points that make a quite distinction when I code. Here we go.

Speed

To be honest, it is a valid but quite unfair point. When I run codes in Ruby, everything is snappy, and more often than not I receive well-documented errors instantly if there’s anything wrong. With Java, codes run slower because they need to be compiled first. I said it is not a fair point because Ruby is an interpreted language, while Java is a compiled language. Ruby codes can change on the fly, while Java codes need to be generated to byte codes before they can run. Ruby is simpler, Java is more complex hence slower, but both support OOP. I still miss Java’s platform independence though. I don’t have enough time on JavaScript to give a verdict here.

Winner: Ruby

Simplicity

To get output from terminal/ console, they are all different:

Java

System.out.println(“Hello World!”);

Ruby

puts “Hello World!”

JavaScript

console.log(“Hello World!”);

I love how concise Ruby is! This is important because as a coder, you always want to output your logic to the terminal to quickly test the code. I love how I don’t have to type long words to get the job done.

As mentioned, Ruby is an interpreted language, so you do not have to specify data type when you create a variable. In Java, you have to do it every time.

Ruby

a = “Hello”
b = 294

Java

String a = “Hello”;
int b = 294;

JavaScript is simpler than Java, but still requires a “var” when you want to create a new variable.

JavaScript

var a = "Hello";
var b = 294;

And do I need to mention that in Ruby you don’t need to end each line with a semicolon? Sweet!

Winner: Ruby

Definition/ Versatility

Every language is built with a specific purpose. For Ruby, it is a general-purpose, truly object-oriented scripting language. However, it is the Rails framework that makes it so popular, so Ruby is often used to write web applications. Java comes to the rescue when you want to “write once, run everywhere.” The idea of using the same code to run on Win32, UNIX or MacOS systems is awesome. JavaScript, on the hand, has limit use. It is strictly a run-time scripting language to be implemented mainly on Web browsers. It has no network, storage or graphic APIs. And, even with the presence of Node.js, a server-side implementation, more than 94 percent of 10 million most popular web pages use Javascript in client side.

Winner: Ruby and Java

As stated above, this comparison is as biased as it can be. I fell in love with Ruby, and to me it is the best language overall. I love how Ruby can achieve the same thing in one line of code, while in Java I will need at least 10. It is simple, powerful and flexible. But the most important reason has to be the Ruby on Rails framework. I have built web applications in Java, using Spring Boot, Hibernate and Spring MVC. They use the same Model-View-Controller pattern as Rails, but Rails is just more intuitive, unambiguous, elegant and cool.

Building Rails web apps is what I do everyday, and I do enjoy it.

--

--

Daniel Mai

I develop experiences that make peoples’ lives better.