Work in Progress

Scala 3 has not been released, yet. We are still in the process of writing the documentation for Scala 3. You can help us to improve the documentation.

Are you searching for the Scala 2 documentation?

Scala 3 — Book

Hello, World!


A Scala 3 “Hello, world!” example goes as follows. First, put this code in a file named Hello.scala:

@main def hello = println("Hello, world!")

In this code, hello is a method. It’s defined with def, and declared to be a “main” method with the @main annotation. It prints the "Hello, world!" string to standard output (STDOUT) using the println method.

Next, compile the code with scalac:

$ scalac Hello.scala

If you’re coming to Scala from Java, scalac is just like javac, so that command creates several files:

$ ls -1

Like Java, the .class files are bytecode files, and they’re ready to run in the JVM.

Now you can run the hello method with the scala command:

$ scala hello
Hello, world!

Assuming that worked, congratulations, you just compiled and ran your first Scala application.

Contributors to this page: