Your First Program
6 min · Scala
Write and run your very first Scala program, right here on the page.
Enemy 1 of 5
Anatomy of a Scala program
Scala runs on the Java Virtual Machine (the JVM), the same runtime that powers Java. That single fact explains a lot of its shape: Scala programs are organized into objects and classes, they compile down to JVM bytecode, and Scala can freely use any existing Java library. Where Scala differs from Java is in how much it lets you say with how little code — and in how comfortably it mixes an object-oriented style with a functional one (writing programs mostly as expressions and transformations, rather than step-by-step mutation).
You don't need to understand any of that to write your first program, but it's useful context for later: when you see `object Main` and `def main`, you're looking at the JVM entry-point convention, not something unique to Scala.
A Scala program starts inside an `object` — a singleton (a class with exactly one instance, created automatically). `def main(args: Array[String]): Unit = { ... }` is the method the JVM looks for when it runs your program. `args` holds any command-line arguments as an array of strings, and `Unit` is Scala's way of saying "this method returns nothing meaningful" (similar to `void` in Java or C).
Inside the curly braces is the body — the actual instructions that run, top to bottom. For your first program, focus on just one line: `println("Hello, World!")`.
Loading editor...