# What Scala Is and Where It Is Used — Scala

Source: https://www.geekswithgeeks.com/en/scala/f-what

> Describe Scala's design, platforms and typical uses.

## Object-oriented and functional, on the JVM

**Scala** (from "scalable language") was created by Martin Odersky at EPFL and first released in 2004. It **fuses object-oriented and functional programming**: every value is an object, functions are values, and immutable data, expressions and pattern matching are the norm. Scala has a powerful **static type system** with strong **type inference**, so code is concise but checked at compile time. It runs mainly on the **JVM** with full **Java interoperability** (use any Java library), and also compiles to JavaScript with **Scala.js** and to native binaries with **Scala Native**. **Scala 3** (released in 2021) is a major redesign of Scala 2: cleaner syntax with optional braces (indentation-based), **enums**, **given/using** for contextual abstractions, **extension methods**, **opaque types**, **union and intersection types**, and a new macro system. Scala 3.3 is a long-term-support line. Scala powers big-data processing (**Apache Spark** and Kafka were written largely in Scala), high-throughput backends (Twitter, LinkedIn, Netflix and banks have used it), streaming systems and functional libraries such as **Cats Effect** and **ZIO**.

## Scala's two halves

Classes, traits and objects meet immutable data, functions as values and pattern matching.

![Two interlocking puzzle pieces, one labelled with a class box icon and the other with a lambda arrow icon, sitting on a coffee-cup shaped platform.](assets/figures/scala/section-1-map.svg) — Figure 1.1 — OOP and FP combined on the JVM.

## A first Scala 3 program

A @main entry point, a case class and collection operations.

```scala
case class Order(id: String, city: String, total: BigDecimal, paid: Boolean)

@main def report(): Unit =
  val orders = List(
    Order("o1", "Pune", BigDecimal(1200), paid = true),
    Order("o2", "Delhi", BigDecimal(300), paid = false),
    Order("o3", "Pune", BigDecimal(800), paid = true)
  )

  val revenueByCity: Map[String, BigDecimal] =
    orders.filter(_.paid).groupMapReduce(_.city)(_.total)(_ + _)

  for (city, revenue) <- revenueByCity do
    println(s"$city: Rs $revenue")

// run with:  scala run report.scala   (Scala CLI)
```

## Learn Scala 3 syntax first

Most new projects and current learning material use Scala 3. Scala 2.13 code still appears in older codebases and in Spark, but the core ideas carry over and Scala 3 can use most Scala 2.13 libraries.

**Quiz:** Which statement about Scala is true?

- [x] It combines object-oriented and functional programming with static types on the JVM
- [ ] It is dynamically typed
- [ ] It cannot call Java libraries
- [ ] It only runs in the browser

*Answer:* It combines object-oriented and functional programming with static types on the JVM. Scala is a statically typed OOP and FP language with full Java interoperability.
