Scala/Setup

Setting up Scala
The following gives a guide on how to install Scala on different operating systems:

Linux

 * Ubuntu/Debian (dpkg based):  or  . You may also install   for the documentation and examples.

Windows

 * Go to the Scala official download page: http://www.scala-lang.org/download/
 * Download and open the Scala installation file from the above mentioned site to start the installation.
 * Read and follow the instructions on screen.
 * When installed, the Windows Command Prompt or Windows Powershell is used to utilize the Scala Compiler, the Scala Interpreter ("REPL") or any precompiled Scala written programs.

Mac OS X

 * Using homebrew:


 * Or download from the package official site:
 * extract the tar ball
 * and append xxx/scala-x.x.x./bin directory to
 * use  as in a REPL environment

Setting up Scala IDEs

 * Using a tool Lightbend Activator or sbt to bootstrap your development project
 * Or install one of the fabulous Scala IDEs:
 * IntelliJ IDEA with the Scala plugin;
 * The Scala IDE (based on Eclipse);
 * NetBeans IDE with the Scala plugin.

Running Scala
Scala can be written and run in different ways, by using the interpreter, by compiling, or by running it as a script. The "Hello World!" program will be used to illustrate these different ways.

Interpreting Scala
The Scala interpreter is an interactive shell that supports easy writing and running of commands and programs. The Scala interpreter is generally included in the basic Scala installation and can be initiated from the command-line (typically by writing ), but is also supported in some Scala IDE plugins (such as Scala-IDE for Eclipse).

Once initiated, the prompt looks like this:

The simplest way to write "Hello world!" is to write the following command:

prints the given string and adds a newline. If only  is used, no newline is added. If you write this in the interpreter and press enter, the result should look like this:

The  command was interpreted and run, and the result (printing to the terminal) is shown.

There are also special commands in the interpreter; for more information on these, type “:help”.

The interpreter is generally well-suited for small tests and experiments, and less for program development. When learning Scala, the interpreter is often a very useful tool, since it gives immediate feedback. The interpreter is actually a REPL.

Additionally, in a scala IDE such as eclipse or Intellij, there is a worksheet that can be used in a REPL as well.

Compiling Scala
Scala is a JVM based language, and like Java it is compiled into java bytecode files. Below is the Scala version of Hello World:

We can simply use  to build and then there would be two class files: HelloWorld.class and HelloWorld$.class. Using  to execute and the screen should print:

supports other options like, also it provides advanced options beginning with   and private options beginning with.

Scripting Scala
We can use  as a script.For a scala source file script.scala We can use  to run it, just like the Python script. However, there is no support for shebang in Unix like system.

For eclipse and Intellij, there is also a scala script that can be used in the development environment.