Scala · Course navigation

Scala Basics

Run a small program with an entry point.

On this page

The concept

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

Code example

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

Follow the code

Open the walkthrough to inspect the example one step at a time.

Show guided walkthrough
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

Behind the scenes

How Scala processes this code

Scala compiles for the JVM, which invokes the main entry point.