Scala
Scala is a programming language used for backend services and data processing. It usually runs on the Java Virtual Machine (JVM) and lets developers combine classes and objects with function-based data transformations.
What is Scala?
Scala is a statically typed language: the compiler checks that values are used in ways their types allow. You don't have to write every type yourself. In val count = 3, the compiler infers Int, so passing count to a method that expects a String is still a compile-time error.
Scala combines object-oriented and functional programming. A service might use classes and traits to define how its components interact, while expressing its business rules as functions that take inputs and return new values. Neither style is mandatory: Scala also supports mutable state and ordinary loops.
How it works
On the JVM, the Scala compiler produces bytecode that runs on the same virtual machine as Java bytecode. Scala code can call Java APIs, which makes it possible to reuse existing Java libraries. Interoperability doesn't make the two languages' types interchangeable, though: for example, a Scala List needs to be converted before passing it to an API that expects a java.util.List.
Scala uses features such as case class and pattern matching to model and work with structured data. A case class provides field-based equality and a copy method that creates a new instance with selected fields changed. Pattern matching lets code branch on the kind of value it receives and extract the parts it needs.
Example: an optional lookup
val users = Map(1 -> "Ada", 2 -> "Lin")
def greeting(id: Int): String =
users.get(id).map(name => s"Hello, $name!").getOrElse("Hello, guest!")
greeting(1) // "Hello, Ada!"
greeting(9) // "Hello, guest!"
Map.get returns an Option[String]: either Some(name) for a matching key or None for a missing one. map formats the greeting only when a name is present. getOrElse supplies the fallback. The return type of the lookup makes missing data explicit, without requiring callers to check for null.
Where it is used and what to watch for
Scala is used in backend APIs, event-processing services, and data pipelines, including Apache Spark jobs. Both Scala 2 and Scala 3 appear in existing projects, so check that a library is compatible with the project's Scala version before adding it.
A common mistake is to read val as “this object cannot change.” It only means the binding cannot be reassigned. A val that refers to an array still lets you change the array's elements. An immutable collection, by contrast, leaves the original collection unchanged when you add or replace an element.
In interviews
Expect to explain val versus var, and to choose between Option for absence and Either when a failure needs to carry a reason. A common exercise is to combine two lookups where the second depends on the first. If both return Option, explain why map would produce a nested Option, while flatMap gives one Option and skips the second lookup if the first returns None.