How to write hello world
Objective
I want to write a hello world program in Scala, and run it.
Steps
- Create a fresh directory, like
hello_scala/
- Create a directory named
project/
underhello_scala/
, and createproject/build.properties
withsbt.version=2.0.0-M3
- Under
hello_scala/
, createbuild.sbt
:scalaVersion := "3.3.3"
- Under
hello_scala/
, createHello.scala
:@main def main(args: String*): Unit = println(s"Hello ${args.mkString}")
- Navigate to
hello_scala/
from the terminal, and runsbt
:$ sbt
- When the prompt appears, type
run
:sbt:hello_scala> run
- Type
exit
to exit the sbt shell:sbt:hello_scala> exit
Alternatives
When you're in a hurry, you can run sbt init
in a fresh directory, and select the first template.