Differences between Java and Scala

2

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
  • Both have lambdas (Java 8)
asked by anonymous 11.12.2018 / 11:01

1 answer

4

Running in the JVM and compiling to bytecode is implementation details and not part of the language feature.

There are more important similarities, for example the most important Java paradigm is the imperative rather than the objects. Scala already uses the most functional she can. Imperative and functional are antagonistic, object orientation , and so it is present in both. Even so it is possible to have some of the imperative and functional together. Scala has a lot, Java started to have a little bit.

Today both have functional features. Scala was born this way and strengthens this paradigm. Java has been adopting this more recently and is still shy, an example is the use of lambda . In Scala this features is best implemented. When the comparison is with more modern Java it has fewer differences. Java decided that he needed to get closer to Scala as much as possible. And newer versions should adopt more features.

Differences

  • Scala is less verbose, one of the problems most people complain about in Java, and in a way most other differences are about it. 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 appropriate syntax for functional, such as pattern matching .
  • Scala typing is safer and more strict. It has existential types and high order types, as well as variance control, better control of optional values (it does not have null ).
  • Some types created by Scala are more suitable for use in it. In general they can end up being used in Java also with some advantages.
  • Scala abandoned the idea of exceptions checked.
  • Scala allows for better composition and encourages this, for example by adopting Traits .
  • Scala has case class .
  • And macros.
11.12.2018 / 12:09