🎓 A1Learner
🔍
0 of 50 lessons completed

Scala Introduction

Scala is a programming language that mixes object style and functional style in one language. It runs on the Java Virtual Machine, the program that lets Java code run on many kinds of computers.

Printing shows text on the screen

The println command prints a value and then moves to a new line. Text goes inside double quotes.

@main def main(): Unit =
  println("Hello, Scala!")

Printing can show a calculated result

A calculation inside println is worked out first. The result is printed instead of the calculation.

@main def main(): Unit =
  println(1 + 2)
  println(3 * 4)

Lines print in the order they are written

A program runs its lines from top to bottom. Each println adds one new line.

@main def main(): Unit =
  println("First line")
  println("Second line")

Example

@main def main(): Unit =
  println("Hello from Scala!")
  println(5 + 5)
  println("Ready to learn")

Key points

  • JVM: the Java Virtual Machine is the program that runs Scala code on many kinds of computers.
  • Printing: this course starts by showing text and numbers on the screen.
  • Values: the course then teaches how to store values and work with text.
  • Collections: later lessons store groups of values in lists and other collections.
  • Control: later lessons make choices, repeat actions, and handle missing values.
  • Building: the final lessons create classes and small programs that combine every idea.

In this example, the first line prints a greeting. The second line works out 5 + 5 and prints 10. The third line prints the closing text.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Scastie

Exercise

What does println do in a Scala program?