Installing the Scala environment

Installing the Scala environment

Start a command line

From the Windows menu, find the terminal program (under "Accessories"). Alternatively, press Windows+R and type cmd to start the terminal program.

Install Java if necessary

Type java -version in your terminal. If your output indicates that you have Java 1.6 or higher installed, then you are done. Otherwise, you need to install Java. Click on Windows Online at www.java.com.

Restart your terminal program after the Java installation and check that Java is now on your computer.

Install Scala

Type scala -version in your terminal. If the output shows that Scala 2.11.1 (or higher) is installed, then you are done.

Otherwise, download the file scala-2.11.7.zip (from www.scala-lang.org) and save it to your desktop.

Extract the zip file to C:\Program Files. You need to add the Scala directory to your command line path - the TAs will show you how.

Restart your terminal program, and check that you can start scala by saying scala.

Try some simple interactive Scala statements, such as

scala> println ("Hello World")
Hello World

scala> 7 * 3
res1: Int = 21

scala> 7 * math.Pi
res2: Double = 21.991148575128552

Install Notepad++

You can use any editor you like for writing Scala programs. Perhaps you are already using VIM or Emacs—then keep using them.

Otherwise we recommend that you use Notepad++. Download and install npp.6.7.4.Installer.exe (from notepad-plus-plus.org).

Finally, download the file userDefineLang.xml and save it to your desktop. Find the file in your terminal program, and say

copy userDefineLang.xml "%APPDATA%\Notepad++"

When you start Notepad++ again, you should see "Scala" in the "Language" menu.

Write a Scala script

Open your editor, and write the following small program:

println("Your arguments are:")

for (i <- 0 until args.length) {
  println(i + ": " + args(i))
Save it as a file named args.scala.

Try running this program from the command line, with arguments, such as:

scala args.scala Hello World!

Install CS109 UI module

I have written a simple module called CS109UI that makes it possible to write programs with a simple graphical user interface without learning about the Swing library or worrying about event-based programming.

To install the module, download the file cs109ui.jar. You need to save this file in the directory containing your Scala libraries. If you installed Scala to C:\Program Files as explained before, that means that you should copy this file to the directory C:\Program Files\scala-2.11.6\lib (of course this will depend on your Scala version).

To test the installation, download uitest1.scala. Run it from the command line:

$ scala uitest1.scala 
CS109 UI version 2015/03/31

You should see the version message of CS109 UI (as shown above), and then a new window should appear.

Install ScalaTest

We will also be using the ScalaTest library for unit testing in CS109 and CS206. Start by downloading the file scalatest_2.11-2.2.4.jar. Save it again in the directory containing your Scala libraries, that is C:\Program Files\scala-2.11.6\lib (depending on your Scala version).

A quick test that the library can be found:

> scala
Welcome to Scala version 2.11.5 (OpenJDK 64-Bit Server VM, Java 1.7.0_79).

scala> import org.scalatest.FunSuite
import org.scalatest.FunSuite

For a more complete test, download the example test suite test1.scala, compile it, and run it:

> fsc test1.scala 
> scala org.scalatest.run AdditionCheckSuite

The output should show that everything went alright and that all tests were passed.

Try a larger program

Finally, you may want to try a larger program, such as mastermind.scala.