Scala vs Java 8 – in a Java 8 World
At our last Orange Slice, we gave a comparison tech talk of Scala vs Java 8. Below we have included both the video and the slides, as well as a few main takeaways below the video to help you along the way in your decision if Scala is relevant in a Java 8 world, and if it might be right for you.
Scala vs Java 8 Tech Talk Video
If you want to see the entire presentation, click on the slides below.
Two Main Takeaways from Scala vs Java 8
- Why Scala?
- Is Scala still relevant in a Java 8 World?
But before we get into Why Scala, let’s first look at the criteria we want in terms of choosing a language.
What do we need in a language?
We need the right solution for the problem
First off, it has to be the right solution for the problem. If it doesn’t work for the problem then there’s no use in looking at it. One language can’t fit all. And one language can’t be the solution for every single problem.
We need developer productivity
In addition to this, we need developer productivity. A language needs to be easy to use and allow a developer to write code as quickly as possible.
We need great libraries
Lastly, we need to have great libraries. The greatest language in the world is useless without a strong ecosystem. We don’t want to have to take the time to reinvent the wheel. Nor do we want to work with an incomplete or buggy library.
So if a language needs to be the right solution for the problem, what are the problems we’re trying to solve?
The Need for Massive Parallelism
Things like Big Data and services like Twitter which handles 200 million users a day and 500 million tweets a day, require the need for massive parallelism. We also have a change in hardware. Now, with multi-cores, the number of cores are increasing, so to make a program faster we need to throw parallel hardware at it, not bigger hardware.
But there’s one problem. Parallel processing is really hard! Anyone that’s dealt with threads knows that parallel processing is not a trivial issue. Well, what is it that really makes parallel processing hard? What makes it hard is shared Mutable State. So what can we do about shared mutable state?
A common approach is to use synchronization and locking. This approach works but it can become problematic because if we have too much synchronization and locking then our performance starts to suffer. So what’s a better approach?
The best approach is to actually get rid of Mutable State, or minimize it. So what can we do to get rid of shared Mutable State? Well, Scala can help!
Scala Can Help!
Scala was introduced in 2004, and Scala is actually an acronym for Scalable Language. So exactly how does Scala help us out?
Scala is Functional
Functional languages eliminate the need for shared Mutable State. But that’s not all…
Scala is Object-Oriented
So not only do we get a functional language, but we get a full object-oriented language as well. Scala is basically like a functional language on training wheels. It allows developers to continue to code the way they’re used to, while being able to introduce functional programming where it makes sense and where it’s necessary.
Scala is JVM Based
Another nice feature of Scala is that it runs in the JVM and is completely inter-operable with Java. So what this means is that Java code compiles down to class files and we can actually write Scala code in Java and vice versa.
Another great benefit of Scala being in the JVM is that we get to make use of Java’s great ecosystem. There’s 15 years of great libraries to use, so this means that as developers we don’t have to leave behind our favorite libraries whether it be Spring or Hibernate.
So it’s great that we have access to these libraries but a language isn’t useful unless it has a great community around it. You might be wondering who else is using Scala? Well, there are a lot of large companies such has LinkedIn, Twitter, Sony, and Amazon that are using Scala. In addition to that there’s a lot of large projects such as Apache Spark, Apache Kafka, Apache Apollo, and Akka all using Scala.
Scala vs Java 8 – Isn’t Java 8 enough?
So Scala is functional, object-oriented, and it runs in the JVM. But don’t we get all that with Java 8? So why do we really need Scala?
Well, Java 8 does introduce functional programming but the problem is that Java 8 is not a functional language. It’s really trying to play catch up to functional languages, so it’s functional programming is actually limited. But Scala has a lot more to offer than just functional programming.
Scala vs Java 8 – Scala is all about developer productivity!
What’s nice about Scala is that it’s an expressive language. So this means that we can write code as quickly as possible and it doesn’t take a lot of code to do simple tasks. In the video, we take a look at some of the features in Scala that make a developer’s life easy and we compare them with Java 8 examples, so be sure to check it out for the full download of this presentation!