Getting Started
object HelloWorld {
def main(args: Array[String]): Unit = {
println("Hello, world!")
}
}
1 scala shell
scala>:q
The shortcut :q stands for the internal shell command :quit used to exit the interpreter.
2 Compile it!
The scalac command compiles one (or more) Scala source file(s) and generates Java bytecode which can be executed on any [standard JVM](http://java.sun.com/docs/books/jvms/)
scalac HelloWorld.scala
By default scalac generates the class files into the current working directory. You may specify a different output directory using the -d option.
> scalac -d classes HelloWorld.scala
3 Execute it!
The scala command executes the generated bytecode with the appropriate options:
> scala HelloWorld
scala allows us to specify command options, such as the -classpath (alias -cp) option:
> scala -cp classes HelloWorld
4 Script it!
We may also run our example as a shell script or batch command (see the examples in the man pages of the scala command).
The bash shell script script.sh containing the following Scala code (and shell preamble):
#!/usr/bin/env scala
object HelloWorld extends App {
println("Hello, world!")
}
HelloWorld.main(args)
can be run directly from the command shell:
> ./script.sh