Sonia Fernández Rodríguez
Software Engineer
Lesson 1: Getting started and familiarize
Clone project
https://github.com/soniarodriguez/scala-for-java-devs
Open project in IntelliJ
Install Scala plugin
Scalable programming language
Built in a multi-paradigm way
Object-oriented programming
Data abstraction with objects
Functional programming
Mathematical functions, no side effects
Interactive build tool
sbt test
sbt run
sbt clean
sbt console
Starting point of a project:
Scala also runs on the JVM
Easy to interact with Java code
Some Java imports by default
val result1 = 5 + 2
val result2 = 3 + 1
<scope> def <functionName>(<parameterName: ParameterType>*): <returnType> = {
body
}
def canFly(animal: String): Boolean = {
animal.equalsIgnoreCase("bird")
}
Example
import scala.collection.JavaConverters._
def getFirstNPrimeNumers(n: Int): List[Int]
Example:
scala> val result = 1 + 4 * 2
result: Int = 9
scala> val result = 1.+(4.(*2))
result: Int = 9
Using infix syntax
Calling methods of a number
sbt console
Using tab to autocomplete
By Sonia Fernández Rodríguez