First things first, we need to set up our work environment. In this section, we will get all the tools and libraries, and then install and configure them on your computer.
Scala programs are compiled to Java bytecode, which is a kind of assembly language that can be executed using a Java Virtual Machine (JVM). You will, therefore, need to have a Java compiler and a JVM installed on your computer. The Java Development Kit (JDK) provides both components, alongside other tools.
You could develop in Scala using a simple text editor and compile your programs using the Scala Simple Build Tool (SBT). However, this would not be a pleasant nor productive experience. The majority of professional Scala developers use an Integrated Development Environment (IDE), which provides many helpful features such as syntax highlighting, autocompletion, code navigation, integration with SBT, and many more. The most widely used IDE for Scala is IntelliJ Idea from JetBrains, and this is the one we are going to install and use in this book. The other options are Scala IDE for Eclipse and ENSIME. ENSIME is an open source project that brings IDE-like features to popular text editors such as Emacs, Vim, Atom, Sublime, and VSC.
We are going to install the Oracle JDK, which includes a JVM and a Java compiler. On many Linux distributions, the open source OpenJDK is preinstalled. OpenJDK is fully compatible with the Oracle JDK, so if you already have it you do not need to install anything else to follow this book.
You might already have a Java SDK installed on your computer. We are going to check if this is the case. If you are using Windows, open a DOS Command Prompt. If you are using macOS or Linux, open a Terminal. After the prompt, type the following:
javac -version
If you have a JDK installed, the version of the installed compiler will be printed:
javac 1.8.0_112
If the version installed is greater than or equal to 1.8.0_112, you can skip the JDK installation. The version of Scala that we are going to use is compatible with JDK version 1.8 or 1.9.
If not, open the following URL, download the SDK for your platform, and follow the installation instructions given: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html.
Go to https://www.jetbrains.com/idea/download. Download the community edition for your platform. The ultimate edition offers more features, but we will not use them in this book.
The following are the steps to install IntelliJ IDEA:
- Run IntelliJ Idea.
- Select the
Do not import settings
option:
Build Tools
:Disable All.
Version Controls
: Only keep Git and GitHub.Test Tools
:Disable All.
Swing
:Disable.
Android
:Disable.
Other Tools
:Disable All
and keep Bytecode viewer, Terminal, and YAML.Plugin Development
:Disable.
You can see the aforementioned plugins in the following screenshot:
- Click on the
Install
button forScala
and for theIDE Features Trainer,
as shown in the following screenshot, and then proceed by clicking onStart using IntelliJ IDEA
:
Note
If you are already a Vim aficionado, you can install IdeaVim
. Otherwise, I would recommend that you avoid it. I personally use it daily, but it took me some time to get used to it.
- Fill in the following details, as shown in the following screenshot:
Name
:scala_fundamentals
.JDK
: Click onNew
and then select the installation directory of the Oracle JDK.sbt
: Choose the version1.0.4
, checkSources.
Scala
: Choose the latest version 2.12.x, for instance2.12.4
(IntelliJ lists all the possible versions and will download the one you choose), and checkSources.
- Click on
Finish
.
It is going to take some time depending on your internet connection's speed: