Page Contents
Scala Features
Scala is a modern multi-paradigm programming language designed to express common programming patterns in a concise, elegant, and type-safe way. Scala has been created by Martin Odersky and he released the first version in 2003. Scala smoothly integrates the features of object-oriented and functional programming languages. This tutorial explains the basics of Scala in a simple and reader-friendly way.
Scala is object-oriented
Scala is a pure object-oriented language in the sense that every value is an object. Scala doesn’t have primitives. All primitive types are represented by type AnyVal. You can also see the post for more details.
Scala is functional
Scala is also a functional language in the sense that every function is a value and every value is an object so ultimately every function is an object.
Scala provides a lightweight syntax for defining anonymous functions, it supports higher-order functions, it allows functions to be nested, and supports currying. See the post to see more about functions.
Scala is statically typed
Scala is a Statically typed language because once a type is assigned to a variable, it remains the same for the entire scope.
Example
scala>var message = "Hello Proedu"
message: String = Hello World // variable message is of type String.
scala>message = 100 // Trying to assign an Int vale to a variable of type String.
<console>:8: error: type mismatch;
found : Int(100)
required: String
message = 100
Scala runs on the JVM
Scala is compiled into Java Byte Code which is executed by the Java Virtual Machine (JVM). This means that Scala and Java have a common runtime platform. You can easily move from Java to Scala.
The Scala compiler compiles the Scala code into Java Byte Code, which can then be executed by the ‘scala‘ command.
Scala can Execute Java Code
Scala enables you to use all the classes of the Java SDK and also your own custom Java classes, or your favorite Java open source projects.
Scala vs Java
Scala has a set of features that completely differ from Java.
- Scala is pure object oriented.
- Type inference
- Nested Functions
- Functions are objects
- Domain specific language (DSL) support
- Traits
- Closures
- Concurrency support inspired by Erlang