Scala Basics

Run a small program with an entry point.

Scala
object Main {
  def main(args: Array[String]): Unit = {
    val name = "Ada"
    println(s"Hello, $name")
  }
}
Output
Hello, Ada

Explanation

The main method is called when the program starts. val binds an immutable value, and println writes it.

Explore the dry run
Guided walkthroughReady
1object Main {
2 def main(args: Array[String]): Unit = {
3 val name = "Ada"
4 println(s"Hello, $name")
5 }
6}

Follow the example

Start to inspect the source, values, and output. These prepared steps explain the published sample; grouped loop steps describe multiple iterations.

View the complete dry-run table
Prepared trace of the published program. Some rows group repeated iterations.
Step / lineWhat happensState after stepOutput so far
Create immutable name when main runs.name = "Ada"
—
Interpolate name into the string and print.name = "Ada"
Hello, Ada