Scala vs. Java: Another View
Scala vs. Java: Another View
Check out this historical comparison of Scala and Java's features and why one developer favors the new kid on the block.
Join the DZone community and get the full member experience.Join For Free
Build vs Buy a Data Quality Solution: Which is Best for You? Gain insights on a hybrid approach. Download white paper now!
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 a more productive developer. Make yourself comfortable, it’s going to be a very interesting conversation about marketing in a programming languages world. Yes, exactly, a 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 and 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 (backward 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:
Of course, you can find other statistics, but I bet Java also will be there in the top three.
What is the reason for such popularity? Well, that is the list of Java advantages published above. They definitely they gave an extremely strong start to the future development of the programming language. But to be honest, the success of Java over such a long distance was provided by the important and useful features introduced from release to release.
All these factors sound great until we recall what moves the tech world. Java was created by Sun Microsystems until, in 2010, Oracle acquired it with all the consequences. A huge amount of money is invested in Java: conferences (JavaOne), the 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…
The Scala Way
I like 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: object-oriented programming and functional programming. If you have only worked 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 the Java libs because Scala is compatible with Java. Secondly, code becomes more concise and expressive, so you write less but get more. Finally, a concurrency in Scala is implemented at an absolutely different level of abstraction compared to 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 were exhausted with a boilerplate code, factory-delegator-facade patterns, and a cumbersome enterprise development. Here is a list of Scala features — try to analyze them:
- Very concise syntax (helps to avoid a boilerplate code).
- REPL (try code samples in a console).
Optionclass (no need to use
- Functions as a smallest unit of code (no need to create a class where it’s redundant).
- Pattern matching.
- OOP on steroids (case classes and traits).
- Powerful collections (third-party libs not required).
- Implicit arguments and values.
Futureclass (asynchronous programming).
- Has all advantages of Java (except backward compatibility).
If I missed something, please add it in comments, I’ll highly appreciate this.
A developer with all these features under their belt moves to the next programming level. Of course, the developer needs to be ready to spend some time understanding new concepts because Scala is harder than Java. Furthermore, a learning curve can vary wildly from book to book and from tutorial to tutorial.
Talking about Scala disadvantages, I want to emphasize its complexity for beginners, absence of backward compatibility, and the compile time.
Scala is still in (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 this peaceful rhetoric and compare Scala to Java
I don’t want to discuss banal things like 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, the 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 with continuous improvements.
So regarding the drawbacks mentioned above:
- A new compiler is under development (Dotty promises high speed).
- Numerous books, courses, and resources appear (choose anything that fits your needs).
- The Scala community is growing up (and 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:
This diagram reflects the demand on Scala and Java developers. Please note that curves are relative, not absolute. It means that the total number of Java positions still exceed Scala positions. It’s easy to predict Scala's progress in the future. Why? Because Scala totally satisfies its users and as a result – customers. Don’t forget about the Big Data world. Spark acquired total domination there. Reactive programming is represented by Akka. Actually, I like this cozy 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.
When it becomes possible, I will still choose Scala.
Also, be sure, I’m really happy that Java has evolved because this process implicitly makes Scala better on the JVM level.
Published at DZone with permission of Alexey Zvolinskiy , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.