Scala · Lesson 1 · On the house

Hello Scala

object, def main, println, run basics. Lesson 1 is free — on the house.

Lessons · Scala · Lesson 1 of 10 · On the house

Hello Scala

object, def main, println, run basics.

Illustration for Scala
Lesson 1 is on the house.

A classic Scala JVM entry lives in a singleton object with def main(args: Array[String]): Unit. The object name is what you run after compiling.

println writes a line to standard output and adds a newline. print exists too but omits the trailing newline — demos almost always use println.

Line comments start with //. Block comments use /* ... */. Scala is case-sensitive: Println is not println.

Compile a single file with scalac Hello.scala, then run with scala Hello (the object name). With sbt, sbt run finds the main entry in the project.

Misses: writing public static void main (Java), using fun main (Kotlin), or forgetting args: Array[String] on the classic main signature.

hello

object Hello {
  def main(args: Array[String]): Unit = {
    println("hello")
  }
}
Match this when you type.

Quiz

Where does a classic Scala JVM entry live?

Quiz

Which call writes a line with a trailing newline?

Quiz

How do you compile then run a single-file Hello object?

Quiz

Is Scala case-sensitive?

Check

Match the still for: Hello Scala.

Open-book: the answers are on this page. Pass every quiz and check (5) to mark the lesson done. This visit: 0/5.