Differences between Java and Scala

Asked

Viewed 304 times

3

What are the main differences between Java and Scala? Both have these similarities:

  • Both are object oriented
  • Both compile to bytecode and run in the JVM
  • They both have Amble (Java 8)

1 answer

6


Run on JVM and compile to bytecode are implementation details and is not part of the language feature.

There are more important similarities, for example the paradigm most important of Java is the imperative and not object oriented. Already Scala uses the functional as much as it can. Imperative and functional are antagonistic, object orientation no and so it is present in both. Even so it is possible to have some of the imperative and functional together. Scala has enough, Java has started having a little bit.

Today both have functional characteristics. Scala was born like this and forces this paradigm enough. Java has been adopting this more recently and is still shy, an example is the use of lambda. In Scala this feature is better implemented. When the comparison is with more modern Java has less differences. Java decided it needed to get closer to Scala as far as possible. And newer versions should adopt more features.

Differences

  • Scala is less verbose, one of the problems that people complain most about from Java and in a way most other differences are about this. For example it has operator overload, understandings,
  • Scala adopts a model called Actor to work with competition.
  • Scala adopts more functional techniques such as immutability by default, referential transparency, and a more functional syntax, such as Pattern matching.
  • Scala typing is safer and stricter. It has existential types and high order types, as well as variance control, better control of optional values (no null).
  • Some types created by Scala are more suitable for use in it. In general they may end up being used in Java also with some advantages.
  • Scala abandoned the idea of checked exceptions.
  • Scala allows better composition and encourages this by for example adopting Traits.
  • Scala has case class.
  • And macros.
  • 1

    I think it’s worth, out of historical curiosity, what I’m about to say. Even in the time of Java 6, there was a great profusion of languages compiled for JVM (by default). And at the time the JVM was no help to those languages. There was then a congress of JVM-based languages, and there they suggested the bytecode invokeDynamics, as the Ambdas were a major performance problem. And that’s roughly how invokeDynamics came into being in JVM 7, even though it didn’t have lambda in Java 7

Browser other questions tagged

You are not signed in. Login or sign up in order to post.