Scala can be run stand alone, using the command line interpreter - using the "scala" command.

Scala also has plugin support for NetBeans, Eclipse and InteliJ

Syntax Overview:

Type inference means most type declarations can be omitted (but can still be explicitly declared).

Variables are defined as name : type rather than type name as per Java

Semicolons are often optional

Does not specify or define operators. +-*/ etc are valid method names are defined as such for appropriate types

var and val keywords - val declares a constant type (like Java's final, not reassignable), var declares a variable that can be reassigned. val, like var can still be mutable however, if the type is mutable.

The List type supports ::: (concat) and :: (cons, prepend), both apply the operation and return the resulting new List

Arrays are always mutable, lists are always immutable. Sets and maps can be either, the default is immutable (from the trait scala.collection.immutable) but the mutable equivalents can be imported from scala.collection.mutable

The -> method provides Implicit Conversion. e.g. x -> y is x.->y which returns a key/value tuple containing x as the key and y as the value

Some simple Functional examples:

Print all command line arguments, using foreach, passing println function:

Verbose:args.foreach((arg: String) => println(arg))

Type inference on arg:args.foreach(arg => pringln(arg))

Concise:args.foreach(println)

The last example is a shorthand that can be applied when a function literal cosists of one statement that takes one argument - known as a Partially Applied Function.

For Expressions:

Replacing imperative for loops, the syntax is of the form:

for (arg println(arg)

Note: In the above for expression example, arg is a val (final/const) not a var, and a new val variable is created for each "iteration".

or

for (i Declaring Arrays:

Very concisely:val myArray = Array("value1", "value2")

defines a string array (type inference) of size 2

This is equivalent to:

val myArray = Array.apply("value1", "value2")

where apply is called on the Array Companion ObjectMore Verbosely the array could also be declared more traditionally as:val myArray = new Array[String](2)

or even

val myArray : Array[String] = new Array[String](2)

but the former concise approach is the Scala recommended way, the later hints at the underlying Java roots.

Note: The Nil (empty List) is needed so that working from right to left, the :: method is defined on Nil, which first gives Nil.::(5) returning List(5) which then gives 5.::(4) resulting in List(4, 5), and so on. Without the Nil there is a syntax error as :: (cons) is not defined on 5 (which is of type integer).