Getting Started
Quick links
• Course Home
• Piazza
• Scala 3 Book
• X86 Cheat Sheet
This page explains how to setup the tools and environment necessary for development. You will need to have the following software installed on your machine:
The Java Development Kit (JDK). The Scala compiler and tools run on the Java Virtual Machine (JVM), but we don’t need to write any Java code directly.
The Scala compiler, tools and environment.
C compiler and the make build tool - specific to your CPU and operating system
Editors or IDEs for writing Scala code.
Optionally, Git for version control and managing your own code history.
Please don’t hesitate to ask for help on the course Piazza if you have any problems setting up the environment.
As the projects will generate x86-64 assembly code, the projects will be tested on an x86-64 Linux machine or Mac OS machine via Rosetta emulation. Thus, developing on non-x86-64 non-Unix-like platform (e.g. Windows + cygwin) is possible but not recommended. If you have only Windows installed on your laptop, consider running Linux in a VM (e.g. VirtualBox) or using WSL, or use the lab machines for the project.
1 Install JDK and the Scala Toolchain
The scala compiler scalac compiles Scala source code down to Java bytecode which is then interpreted by the Java Virtual Machine (JVM). Additionally, Scala Build Tool (sbt) is often used to manage and build the projects. Sbt will orchestrate the compilation and execution of Scala code by invoking the appropriate Scala and Java tools.
For this course, we are using the following versions,
Java (OpenJDK 21)
Scala 3.7.3
sbt 1.11.7
Note that sbt manages the Scala and sbt version for each project individually (in its build file build.sbt). Once you have sbt installed, running sbt in the project directory will automatically download and use the correct Scala version. Note that Scala 2.x will not work for this course.
Using other versions of Java or sbt may work, but does not guarantee passing the tests when grading.
Installation instructions for these tools are as follows.
1.1 Install Java Development Kit (JDK)
If you use a Linux distribution, use your package manager to install OpenJDK 21. For example, on Ubuntu/Debian, you can run:
$ sudo apt-get install openjdk-21-jdkOn Mac OS, you can use Homebrew to install OpenJDK 21:
$ brew install openjdk@21Once you have installed the JDK, you can verify the installation by checking the version of the Java compiler javac:
$ javac -version
javac 21.0.91.2 Install Scala Toolchain
Follow the instruction on the official Scala website to install sbt and Scala: https://www.scala-lang.org/download/.
The recommended way is to use coursier, which installs the Scala compiler, sbt, and other tools.
Once you have installed Scala and sbt, you can verify the installation by running sbt in the project directory (e.g., proj1 for Project 1). You should see output similar to the following (sbt may download some dependencies):
$ sbt
[info] welcome to sbt 1.11.7 (Homebrew Java 21.0.9)
[info] loading project definition from <omitted>/proj1/project
[info] loading settings for project root from build.sbt...
[info] set current project to Project1 (in build file:<omitted>/proj1/)
[info] sbt server started at local: <omitted>
[info] started sbt server
sbt:Project1>You should be able to compile the given skeleton code by running compile in the sbt console:
sbt:Project1> compileThere should be no compilation errors. The command above will generate the target and project/target directories. They contain compiled files and other build artifacts. It is safe to delete both directories. You can close the sbt console through Ctrl+D or closing the terminal window.
Finally you should be able to run the Scala REPL (Read-Eval-Print Loop) by running console or consoleQuick in the sbt console:
sbt:Project1> console
Welcome to Scala 3.7.3 (21.0.9, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala>Alternatively, you may use Ammonite REPL for experimenting.
2 Structure of Scala/sbt Project
Although it would be possible to compile projects manually using the scalac command, scala projects use the sbt tool and have the following directory structure.
my-app
├── build.sbt
├── project/build.properties
└── src
├── main
│ └── scala
│ ├── util_package
│ │ └── Lib.scala
│ └── Main.scala
└── test
└── scala
└── *Test.scalaThe build.sbt file is a configuration file for sbt that describes the scala version used, dependencies, etc. Source files are usually found under src/main/scala. This directory denotes that the source files are Scala code. Test files are usually found under src/test/scala. Similarly to Java, package hierarchy is reflected in the directory structure.
3 C Compiler and Make
$ sudo apt-get install build-essential gdbIf you use Mac OS, you can install the Xcode Command Line Tools by running the following command in the terminal:
$ xcode-select –installIf you use Mac OS on an Apple silicon machine, you also need to install Rosetta for x86 emulation. You should verify that clang can generate x86-64 code and Rosetta emulation works correctly:
$ echo "#include <stdio.h>\nint main() { printf(\"Hello\"); return 0; }" > hello.c
$ clang -arch x86_64 hello.c -o hello
$ ./hello
Hello%You should see the output Hello.
4 Editors and IDEs
You may use any text editors or IDEs of your choice for writing Scala and C code.
Some popular choices include: VSCode, Vim/NeoVim, Emacs, IntelliJ IDEA (with Scala plugin).
For VSCode, you may want to install the official Scala syntax extension. Optionally, Metals is a popular language server for Scala that provides IDE-like features with in various editors.