Scala basics
Scala modernizes Java's object-oriented approach while adding in the mix functional programming. It compiles into byte-code, and it can be executed on any Java virtual machine; thus, libraries and classes of Java and Scala communicate seamlessly.
Scala, similar to Java, is a statically typed programming language but can infer type information. It can infer that t
is a String
type in the following example:
val t = "Text"
Semicolons are not required when terminating commands. Variables are declared, with var
and constants with val
, and Scala favors immutability, which means that we should try to minimize the usage of variables.
Scala is fully object-oriented and functional. There are no primitives, like float or int only objects such as Int, Long, Double, String, Boolean, Float. Also there is no null.
The Scala equivalent of Java interfaces is called trait. Scala allows traits to be partially implemented, that is, it is possible to define default implementations for...