Scala Tutorial
Basics
Control Statements
OOP Concepts
Parameterized - Type
Exceptions
Scala Annotation
Methods
String
Scala Packages
Scala Trait
Collections
Scala Options
Miscellaneous Topics
In Scala, writing a simple "Hello, World!" program is straightforward. Below are the steps to create and run such a program.
.scala
extension.object HelloWorld { def main(args: Array[String]): Unit = { println("Hello, World!") } }
Save the file as HelloWorld.scala
.
Open a terminal and navigate to the directory where HelloWorld.scala
is saved.
Compile the Scala file using scalac
, the Scala compiler:
scalac HelloWorld.scala
This will generate a HelloWorld.class
file. You can run it using the scala
command:
scala HelloWorld
You should see "Hello, World!" printed to the terminal.
Create a new sbt project directory and navigate to it.
Place the HelloWorld.scala
file inside the src/main/scala/
directory of the sbt project.
Open a terminal and navigate to the sbt project directory.
Run the following command to execute your program:
sbt run
sbt will compile and run your Scala program, and you should see "Hello, World!" printed to the terminal.
Open Scala REPL (Read-Eval-Print Loop) by typing scala
into the terminal.
You can directly print "Hello, World!" to the console as follows:
println("Hello, World!")
These are some of the various ways you can write and run a "Hello, World!" program in Scala.