JVM is too small for two leaders. That’s how I want to start a post about Java vs Scala. By the way, I had used Java for a long time, but then switched to Scala and wasn’t happy with that decision. Luckily I have understood how to use its features in order to be more productive developer. Make yourself comfortable, it’s going to be a very interesting conversation about marketing in a programming languages world. Yes-yes, exactly conversation, because I encourage my readers to write comments with their thoughts about the topic.

Firstly, I want to guide you through brief stories of two competitors. This will be helpful because I’m going to refer to the historical facts. Furthermore, recalling the main phases of Java & Scala development will give us a pretty accurate prediction of their future. Let’s start a journey back to the days.

The Java way

In 1995 Java was released. It was some kind of revolution. You probably know why, but I’d like to explain my vision of that fact. Here is a list of Java killer features:

  • Runs on any platform (of course JVM is required)
  • A code written once runs anytime (back compatibility)
  • Garbage collector (no need to manage a memory)
  • Classical object oriented paradigm
  • Syntax (almost the same as in C++)

So looking at the list above you can easily imagine what problems were crucial for developers in 1995. Since that time Java has been updated many times. The number of Java developers has grown so incredibly. Now Java is an undisputed leader among programming languages, especially in a context of server-side development. In order to prove it I suggest you to refer to TIOBE index, PYPL index or GitHut statistics:

tiobe-index-java

Of course you can find any other statistics, but I bet Java also will be there in TOP-3.

githut-info

What is the reason of such popularity? Well, that is the list of Java advantages published above. Definitely they gave extremely strong impulse to the future development of the programming language. But to be honest, the success of Java on a such long distance was provided by the important and useful features introduced from release to release.

All these factors sound well until we recall what moves the tech world. Java was created by Sun Microsystems and then in 2010, Oracle has acquired it with all the consequences. Huge amount of money is invested in Java: conferences (JavaOne), Java Champions program, Java Magazine, movies (Oracle placement in Iron Man 2), promo videos…

As you can see, Java with its brilliant concept and design is surrounded by tons of money.

That’s how I see Java today. Just look at the number of communities, libraries and frameworks on GitHub, books, blogs and courses in order to understand that Java is a market leader. You can develop almost everything you want using Java: server-side app, client-side code, JVM database, programs for microcontrollers…

I’m used to writing a Java code, I like its reliability and resources where I can find an answer on my question. Finally, Java has so good OOP implementation that I can’t express my happiness (before Java I worked with PHP & JavaScript)!

The Scala way

I like a quality stuff. That’s why when I hear something about Swiss cheese, watches, knives, chocolate and banks, I’m confident that people are talking about a high quality. As you may guess, Scala was developed in Switzerland. In 2004 Martin Odersky released the first version of a successful hybrid programming language. Why hybrid? Because Scala unites two worlds: an object oriented programming and a functional programming. If you have worked only with object oriented programming languages before, you would say, that’s a pretty weird mix.

Let’s consider what Scala gives to its users. First, you get all Java libs because Scala is compatible with Java. Secondly, a code becomes more concise and expressive, so you write less but get more. Finally, a concurrency in Scala is implemented in absolutely different level of abstraction comparing with Java. Sounds rather pretentious, doesn’t it? But that’s true.

This programming language has become a breath of fresh air for experienced Java developers who was exhausted with a boilerplate code, factory-delegator-facade patterns and a cumbersome enterprise development. Here is a list of Scala features, try to analyze it:

  • Very concise syntax (helps to avoid a boilerplate code)
  • REPL (try code samples in a console)
  • Option class (no need to use null)
  • Functions as a smallest unit of code (no need to create a class where it’s redundant)
  • Pattern matching
  • OOP on steroids (case classes & traits)
  • Powerful collections (3rd-party libs not required)
  • Implicit arguments & values
  • Future class (asynchronous programming)
  • Has all advantages of Java (except back compatibility)

If I missed something, please add it in comments, I’ll highly appreciate this.

A developer with all these features under the belt moves to the next programming level. Of course if the developer is ready to spend some time for understanding new concepts because Scala is harder than Java. Furthermore a learning curve can extremely vary from book to book and from tutorial to tutorial.

Talking about Scala disadvantages, I want to emphasize its complexity for beginners, absence of back compatibility and compile time.

Scala is still in a very active development. In this context its binary compatibility becomes an advantage because any unsuccessful experimental feature can be easily removed in the next release.

What about Scala financing? Well, on the one hand Scala continues its development due to the efforts of Ecole Polytechnique Fédérale de Lausanne (Scala Center), but on the other hand we know about Lightbend (formerly Typesafe). According to the CrunchBase information, overall investments in Lightbend make about $37M. Since “lightbenders” use Scala as a main programming language, I can say that Scala is in safe hands.

Also, I want to mention the companies and products where Scala is used: Twitter, Coursera, Foursquare, Apple (in some projects), Netflix, Tumblr, Walmart, Spark, Akka, Play! Framework, Lagom…

I don’t know what to add, Scala knows how to impress its users.

And the winner is…

I guess you remember that the title of the article is rather provocative. So it’s time to stop peaceful rhetoric and oppose Scala to Java 🙂

I don’t want to discuss banal things as compile time, learning curve and community size. All of us know that Java compiles faster, it’s easier to learn it and start to use it. Finally, number of Java developers is much higher than Scala devs. But what is interesting in all these boring questions? Scala knows how to resolve issues by continuous improvements.

So regarding the drawbacks mentioned above:

  • New compiler is under development (Dotty promises high speed)
  • Numerous books, courses and resources appear (choose anything what fits your needs)
  • Scala community grows up (btw, in many cases it intersects with Java fans)

As you can see, Scala makes a good business, especially if we look at it in dynamic:

scala-dynamic

This diagram reflects the demand on Scala and Java developers. Please note that curves are relative, but not absolute. It means that total number of Java positions still exceed Scala positions. It’s easy to predict Scala progress in the future. Why? Because Scala totally satisfies its users and as a result – customers. Don’t forget about BigData world. Spark acquires total domination there. Reactive programming represented by Akka. Actually, I like this cosy company.

What about Java? Well, you know better than me, it still runs in millions apps and thousands of developers are looking forward to Java 9 with its so cool new features. Just imagine, Java wants to introduce JShell.

why-scala-beats-java

When it becomes possible, I will still choose Scala.

Also, be sure, I’m really happy that Java evolves because this process implicitly makes Scala better on JVM level 🙂

About The Author

Mathematician, programmer, wrestler, last action hero… Java / Scala architect, trainer, entrepreneur, author of this blog

  • Nikolay Kushin

    Do not forget also scalajs and ScalaNative 😉

  • Marco Antonio Ordoñez Valverde

    Great post man, your comparison is really fair and you have good comments about Scala. Some Java Developers like the way they write programs now (OOP) and are like dinosaurs and don’t want to learn new concepts related to the functional programming, I think those concepts (like any other knowledge) can improve the way they write programs. When I start to use Scala the thing I liked most was the new functional programming fascinating world, in that time it had so many new concepts for me and take me to learn more and more, now I like it more!

    • Marco, thanks I’m very appreciated!
      I have the same experience about Scala learning. After the first year I noticed some small progress in a code evolution, but then thing become more effective =)

  • Mike Toggweiler

    In the feature list I’m missing Monads as a powerful construct to represent sequential and fail-safe steps

    • Regarding the monads, I can’t say anything because didn’t work with them, but I know that it’s possible to use scalaZ in order to obtain monads in Scala 🙂

      • Mike Toggweiler

        Yes they exist. I did mean the future might be worth to list as a scala feature based on the functional approach because it opens a convenient way of handling business rules failsafe.

      • Ashesh Ambasta

        If you use Option in Scala and like to map and flatMap on them, you’re using monads.

  • Pingback: How I would like to learn Scala?()

  • Nicolas Guillemot

    Thanks. That was fresh, though ingredients were already known to me.
    I read something close telling that Scala’s type system is proven Turing complete, whatever concrete meaning, which might explain why I am attracted to it. It quotes Shapeless and I sure love to see how it solves my reflection needs in a static way.

    To think I have to convince people some time soon about the relevance of choosing Scala over Java is quite depressing… I… cannot honestly tell I know Java, not really much more than what I could learned through Scala practice. It is so obvious there is not way back to Java for me (although it would not truly be back then); maybe this is why I have so much trouble to put my finger on the exact selling points. Where would one find the boring time to convert all of a nice Scala sizeable prototype to its equivalent in Java as an honest proof basis?

  • Paa Kojo Gad

    I want to program like u Boss

Close