Computer scienceProgramming languagesScalaBasicsIntroduction to Scala

Introduction to Scala

3 minutes read

What is Scala?

Scala is a general-purpose programming language with the ability to write programs in a functional style. If you are not familiar with functional programming (FP) yet, learning Scala can help you dive into it smoothly and gain both practical and theoretical knowledge.

scala logo

Many design decisions for Scala language were based on the criticism of Java. Scala compiles to Java bytecode and is executable on Java virtual machine; moreover, it provides language interoperability with the existing libraries. Sometimes Scala is even called a better Java, but now the language has moved past that phrase and gained additional functionality.

Why Scala?

Some specific interest must have brought you to this page, but you'd still be right to wonder: why Scala? This question is not so simple: Java, Kotlin and other languages sure have their advantages. However, for certain tasks, Scala is a particularly suitable solution.

As mentioned before, Scala is sometimes called a better Java. Its simplified syntax and strong type system let you build programs in a less vague manner. Interoperability with Java programs adds more options to the table and helps write code that's both readable and safe.

Scala is true functional language. Unlike programming languages that experts call "pure functional" (such as Haskell), Scala still works directly with JVM (Java Virtual Machine), so you can gradually transition from Java to a more functional code style.

Some existing popular projects were written on Scala: Kafka, Spark, Akka and many more. This means that you easily could read code of these products and effectively build distributed processing, reactive systems or highload APIs.

And last but not least – Scala is fun!

A brief history

The history of Scala began in 2001 at the École Polytechnique Fédérale de Lausanne (EPFL) in Switzerland by Martin Odersky, who formerly worked on the Java compiler. Scala evolved from his previous work on Funnel, a programming language that combines ideas of functional programming and Petri nets.

After an internal release in late 2003, Scala was released publicly in early 2004 on the Java platform. A second version (v2.0) followed in March 2006.

Lightbend, formerly known as Typesafe, is a company founded by Martin Odersky, Jonas Bonér (creator of the Akka middleware), and Paul Phillips in 2011 to lead the development of the Scala programming language and related products (Akka, Play framework, and others).

After Scala 2.13 was released in 2019, the plan for the next versions was revealed: the next release will concentrate on migration to Scala 3. Scala 2 and Scala 3 are fundamentally the same language; the compiler is new, but nearly everything that programmers already know about Scala 2 applies to Scala 3 as well. Also, most ordinary Scala 2 code will also work on Scala 3 with only some minor changes.

In May 2021, the third version of the language was officially released. The compiler gained new features, and many old problems were resolved.

Platforms

Scala runs primarily on the Java Virtual Machine (JVM). Scala can be compiled to JavaScript with help of Scala.js project, and to native code with Scala Native. However, we will try to concentrate mostly on language features related to JVM.

A sample of Scala

Here is a sample of a simple Scala program that prints Hello, Scala 3!

@main def hello() = println("Hello, Scala 3!")

For now, you do not need to understand how this code works: just enjoy the fact that it does and get ready for more!

176 learners liked this piece of theory. 3 didn't like it. What about you?
Report a typo