Working with Scala
In this book, we're using Scala version 2.12.2. Scala 2.12 requires your system to have Java version 8 installed. Older Scala versions support Java version 6 and above. Support for Java version 9 is still a topic of discussion for the Scala 2.13 roadmap.
Scala 2.12 was a step up from previous versions, mainly for support of Java and Scala lambda interoperability. Traits and functions are compiled directly to their Java 8 equivalents.
Java installation
Do the needful. If Java is not already installed on your machine, you may refer to Oracle's website at https://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html for instructions on how to install Java for your operating system.
SBT installation
SBT, as the name suggests, is a Simple Build Tool. From managing all source files to their compiled target versions to downloading all dependencies, SBT helps you create a Scala application with ease. You can configure how your test cases run. SBT comes with various commands for such tasks.
To install SBT on your machine, perform the following:
- Go to http://www.scala-sbt.org/download.html.
- You may choose from the available options suitable for your operating system.
After installation, you may check the version, so open a command prompt/terminal and type this:
sbt sbt-version [info] 0.13.11
You should get the corresponding version number.
Scala REPL
There is more than one way of interacting with Scala. One of them is using Scala Interpreter (REPL). To run Scala REPL using SBT, just give the following command in the command prompt/terminal:
sbt console
This command will run Scala REPL.
To run Scala REPL using Scala binary, perform the following:
- Go to https://www.scala-lang.org/download/.
- Download the latest Scala archive.
- Extract the archive to any directory.
- Set the directory path as environment variables as shown in https://www.scala-lang.org/download/install.html.
- Try running the
scala
command, it should look something like this:

If so, congrats. You've done it. Now it's asking you to type any expression. You may try typing any expression. Try anything, like 1 + 2 or 1 + "2". REPL is your playground to learn Scala.
Scala IDEs
After getting familiar with Scala REPL, now is the time to install IDE (Integrated Development Environment). There are options available to work with Scala in IDE. Choose what fits the best for you. Eclipse lovers can go for Scala IDE. To download:
- Go to http://scala-ide.org/download/sdk.html.
- You may choose from the available options suitable for your operating system.
If you're accustomed to IntelliJ IDE, you may go for the plugin download for SBT. This will enable you to create Scala applications. To get started with Scala development on IntelliJ IDE:
- Go to https://www.jetbrains.com/idea/download/.
- You may choose from the available options suitable for your operating system.
- After installation, go to
File
|IntelliJ IDEA
|Preferences
|Plugins
and search forScala
. - Click on
Install
|Apply
.
With this, you're ready to work with Scala on IntelliJ IDE. If you're IDE neutral, you may choose whichever suits the best. We'll use IntelliJ IDE (Community Edition) version 2017.1 with SBT version 0.13.15 and Scala 2.12.2 version.