High-level Overview

  • Scala is a high-level, general-purpose programming language with support for both object-oriented and functional programming
  • Scala is statically typed and compiled into Java bytecode (JVM instructions)
  • All types and functions are objects (instances)
  • It provides seamless Java interoperability — all classed from the java.lang the package is imported by default
  • Designed for concurrent, distributed, and message-driven applications –  strong static systems, data science, and machine learning
  • It has nested functions support
  • Runs on JVM as well as JavaScript (Scala.js)
  • SBT is a popular open-source build tool for Scala projects
  • IntelliJ is a good Scala IDE
  • Official Scala Lang –> tutorials
Scala vs. Java – Key Differences
ScalaJava
Concurrency Actor model Thread-based model 
VariablesImmutable by defaultMutable by default
Operator OverloadingYesNo
Lazy EvaluationYesNo
Pattern Matching & Big MathYesNo
Build ProcessSlowFaster

Scala Syntax

object HelloWorld {
  def main(args: Array[String]): Unit = {
    println("Hello, world!")
  }
}
  • Singleton Object model – a class with a single instance
  • Unit is used to define a function that does not return anything, similar to void in Java

Variables & Types
// Declaring immutable variables 
// val <Name>: <Type> = <Literal>

val a: Int = 5
val b: Long = 100000000L
val c: Short = 1
val d: Double = 2.50
val e: Float = 2.50f
val f: String = "allaboutscala Donut Store"
val g: Byte = 0xa
val h: Char = 'D'
val i: Unit = ()

// Declare a variable with no initialization
var j: String = _

// Declaring mutable variables
// var <Name> : <Type> = <Literal>

var x: Int = 1
var y: String = "text"
var z: Double = _
String Interpolation
val x: String = "some text"
println(s"my variable text is $favoriteDonut")

Scala Frameworks

Big DataApache Spark – leading open sourced platform for large scale data processing
High Throughput MessagingKafka – high throughput distributed messaging system
Highly Concurrent SystemsAkka – build highly concurrent and distributed systems
Finagle – highly concurrent servers with protocol agnostic APIs
Spray – high throughput HTTP server
Other FrameworksPlay – scalable web applications
Shapeless – added functionality to data types
ScalaTest – testing framework
Scalaz – additional semantics for functional programming
Slick – rich data access layer

Scala Tutorials

GETTING STARTED

A SCALA TUTORIAL FOR JAVA PROGRAMMERS

ONLINE RESOURCES