Home Java/J2EE What is Better Java 8 or Scala?

What is Better Java 8 or Scala?

Very tough choice here, we know each language has its own ups and downs. But what to chose among two strong fighters is very difficult.

Scala is enjoying its 10th anniversary previous month (Jan 2014) while Java 8 just launched in March 2014.

Java as always tops the index but Scala has took attension due to its emphasis on functional programming. As Java 8 adds significant Scala features, there’s a case to be made that Scala will diminish.

One more strong things has been added to Java 8 is Lamda which Scala already providing.
For Java developers, it is tough to choose a new language Scala while they can play with Java 8 with little more self teaching.
Java 8’s implementation of lambdas will bring new methods to the java.util.stream.Stream type that will sound very familiar to Scala developers. In my experience, these methods make writing high-level collection code a lot easier and act as a “gateway drug” to change to a more functional style overall. Heavy users of these abstractions would then also appreciate the additional readability Scala bring to the table with itsfor expressions.

What’s interesting about Lambda expressions is that from the JVM’s perspective they’re completely invisible. It has no notion of what an anonymous function or a Lambda expression is. It only knows bytecode which is a strict OO specification. It’s up to the makers of the language and its compiler to work within these constraints to create newer, more advanced language elements.
To get things going I took a simple Lambda expression that converts a list of Strings to a list of their lengths.
In Java –

List arys = Arrays.asList(“abc”, “pqr”, “xyz”);
Stream lengths = arys.stream().map(arys -> name.length());

In Scala –

val arys = List(“abc”, “pqr”, “xyz”)
val lengths = arys.map(arys => arys.length)

The list of features being included in Java 8 is actually quite long, but several of them are particularly interesting to me. Java 8 will definitely bring the Java and Scala developer communities closer together.

It’s fascinating to see how Java, the most “strict” of modern languages is now using dynamic linkage to power its new Lambda expressions. It’s also an efficient approach, as no additional class loading and compilation is needed – the Lambda method is simply another private method in our class. Java 8 has really done a very elegant job in using new technology introduced in Java 7 to implement Lambda expressions in what is a very easy manner.

Java 8 will make more programmers aware of functional programming. They may start to like it, and see that it is better in Scala. It may be Java 8 becomes a boost for Scala.

So, both languages are continuing to grow, but they have different design objectives. The single most important feature of Java 8 will be that it is compatible with Java 7. Scala eschews compatibility with Java in order to bring us a more powerful type system and a lot of great features. For some people, compatibility with Java 7 will be the killer feature, and they’ll be delighted with Java 8; others will be willing to give that up (or will have given that up long ago!) for the extra power.

So now choice is yours what to use as per your requirements.

Please share thoughts.

Share!Share on FacebookShare on Google+Share on LinkedInTweet about this on TwitterFlattr the authorDigg thisPin on PinterestEmail this to someoneShare on StumbleUponShare on RedditShare on TumblrBuffer this pagePrint this page
Tags: ,
Comments Off on What is Better Java 8 or Scala?.
Copyright © 2017 - Scalsys. All Rights Reserved