be entered interactively in the REPL: $ scala Welcome to Scala 2.12.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_131). Type in expressions for evaluation. Or try :help. scala> List(1, 2, 3).map(x => x * x) res0: List[Int] = List(1, 4, 9) scala> Basic example The following example shows the differences between Java and Scala syntax. The function mathFunction takes an integer, squares it, and then adds the cube root of that number to the natural log of that number, returning the result (i.e., ): Some syntactic differences in this code are: Scala does not require semicolons (;) to end statements. Value types are capitalized (sentence case): Int, Double, Boolean instead of int, double, boolean. Parameter and return types follow, as in Pascal, rather than precede as in C. Methods must be preceded by def. Local or class variables must be preceded by val (indicates an immutable variable) or var (indicates a mutable variable). The return operator is unnecessary in a function (although allowed); the value of the last executed statement or expression is normally the function's value. Instead of the Java cast operator (Type) foo, Scala uses foo.asInstanceOf[Type], or a specialized function such as toDouble or toInt. Instead of Java's import foo.*;, Scala uses import foo._. Function or method foo() can also be called as just foo; method thread.send(signo) can also be called as just thread send signo; and method foo.toString() can also be called as just foo toString. These syntactic relaxations are designed to allow support for domain-specific languages. Some other basic syntactic differences: Array references are written like function calls, e.g. array(i) rather than array[i]. (Internally in Scala, the former expands into array.apply(i) which returns the reference) Generic types are written as e.g. List[String] rather than Java's List<String>. Instead of the pseudo-type void, Scala has the actual singleton class Unit (see below). Example with classes The following example contrasts the definition of classes in Java and Scala. The code above shows some of the conceptual differences between Java and Scala's handling of classes: Scala has no static variables or methods. Instead, it has singleton objects, which are essentially classes with only one instance. Singleton objects are declared using object instead of class. It is common to place static variables and methods in a singleton object with the same name as the class name, which is then known as a companion object. (The underlying class for the singleton object