Free lesson preview · Scala

Scala toolchain and first application

Explore this complete sample lesson before enrolling.

Learning objectives

Install a reproducible Scala 3 toolchain, create an sbt project, compile source code, run tests, and distinguish compile-time failures from runtime failures.

Core concepts

Scala runs on the JVM and combines object-oriented and functional programming. A production project pins its Scala and plugin versions, keeps code under src/main/scala, tests under src/test/scala, and declares dependencies in build.sbt. Compilation is a useful design boundary: the compiler detects many invalid states before a job reaches production. Keep application startup small and move behavior into testable functions.

object Main:
  def greeting(name: String): String =
    s"Hello, ${name.trim}!"

  def main(args: Array[String]): Unit =
    println(greeting("data engineer"))

Guided practice

Create an sbt project using Scala 3, add the program, run it with sbt run, and add a test for whitespace normalization. Deliberately introduce a type mismatch and explain the compiler message before correcting it.

Checkpoint

Why should the Scala version be pinned? What belongs in source control, and which generated directories should be ignored? Why is a small main method easier to test and operate?

Reference approach

Commit build.sbt, project/build.properties, source, tests, and documentation. Ignore target/ and editor metadata. Pin versions and keep orchestration at the boundary while pure functions hold application behavior.