SlideShare a Scribd company logo
Welcome to Scala
Scala
Scala - Scalable Language
● Scala is a modern multi-paradigm programming
language designed to express common programming
patterns in a concise, elegant, and type-safe way
● Integrates the features of object-oriented and
functional languages
Scala
Why Scala?
● Statically Typed
■ Proven correctness before deployment
■ Performance
● Lightweight Composable Syntax
■ Low boilerplate
■ Syntax is very similar to other data centric languages
● Stable
■ Is being used in enterprises, financial sectors, retail, gaming
and more for many years
Scala
Scala - History
2011 Corporate stewardship
2005 Scala 2.0 written in Scala
2003 First Experimental Release
2001 Decided to create even better Java
1990
Martin Odersky (Creator of Scala) made Java better via
generics in the “javac” compiler
Scala
Scala - JVM
● Scala source code gets compiled to Java byte
code
● Resulting bytecode is executed by a JVM - the
Java Virtual Machine
● Java libraries may be used directly in Scala code
and vice versa
Scala
// Create a file hello_world.scala
// using nano hello_world.scala
object HelloWorld {
def main(args: Array[String]) {
println("Hello, world!")
}
}
Scala - Hello World - Example
Scala
Scala - Hello World - Compiling and Running
● Compile using scalac
scalac hello_world.scala
● To run it
scala HelloWorld
Scala
Scala - Interpreter
● scala hello_world.scala
Scala
Scala - Interpreter
To evaluate a single expression, you can use the following:
scala -e 'println("Hello, World!")'
Scala
Scala - Variables
● Variables are reserved memory locations to store values
● Compiler allocates a memory based on the data type of
the variable
Scala
Scala - Variables - Types
● Mutable
● Immutable
Scala
Scala - Variables - Types
● Mutable variables are defined using “var” keyword
○ values can be changed
● Immutable variables are defined using “val” keyword
○ values can not be changed after assignment
Scala
● val x: Int = 8 // Immutable, Read Only
● var y: Int = 7 // Mutable
Scala - Variables - Hands-on
Scala
What is the importance of immutable variables?
● In large systems, we do not want to be in a situation
where a variable's value changes unexpectedly
● In case of threads, APIs, functions and classes, we may
not want some of the variables to change
Scala - Immutable Variables - Importance
Scala
● We can define the variables without specifying their data
type
● Scala compiler can understand the type of the variable
based on the value assigned to it
Scala - Variables - Type Inference
Scala
● var x = "hi" // Type Inference (Scala compiler determines the type)
● var x: String = "hi" // Explicitly specifying the type
Scala - Variables - Type Inference
Scala
● We should always define type of variables explicitly
○ Code will be compiled faster as compiler will not have to spend
time in guessing the type
○ No ambiguity
Scala - Variables - Type Inference
Scala
● A class is a way of creating your own data type
● We can create a data type that represents a customers using a class
● A customer might have states like first name, last name, age,
address and contact number
● A customer class might represent behaviours for how these states
can be transformed like how to change someone’s address or name
● A class is not concrete until it has been instantiated using a new
keyword
Scala - Classes
Scala
class Person(val fname: String, val lname: String, val anage: Int) {
val firstname:String = fname;
val lastname: String = lname;
val age = anage;
}
val obj = new Person("Robin", "Gill", 42);
print(obj.age)
print(obj.firstname)
Scala - Classes - Hands-on
Scala
Scala - Classes - Methods - Hands-on
class Person(val fname: String, val lname: String, val anage: Int) {
val firstname:String = fname;
val lastname: String = lname;
val age = anage;
def getFullName():String = {
return firstname + " " + lastname;
}
}
val obj = new Person("Robin", "Gill", 42);
print(obj.getFullName())
Scala
● A singleton is a class which can have only one instance at any point
in time
● Methods and values that aren’t associated with individual instances
of a class belong in singleton objects
● A singleton class can be directly accessed via its name
● Create a singleton class using the keyword object
Scala - Singleton Objects
Scala
object Hello {
def message(): String = {
return "Hello!!!";
}
}
Hello.message()
Scala - Singleton Objects
Scala
● Objects are useful in defining utility methods and constants as they
are not related to any specific instance of the class
Scala - Singleton Objects
Scala
var x = 10;
if( x < 20 ){
println("x is less than 20");
}
Scala - if
Scala
var x = 30;
if( x < 20 ){
println("x is less than 20");
} else {
println("x is greater than 20");
}
Scala - if - else
var x = 10;
if( x < 20 ){
println("x is less than 20");
}
Scala
var x = 30;
if( x == 10 ){
println("Value of X is 10");
} else if( x == 20 ){
println("Value of X is 20");
} else if( x == 30 ){
println("Value of X is 30");
} else{
println("This is else statement");
}
Scala - if - else - if - else
Scala
while loop
Repeats a statement or group of statements while a given condition
is true. It tests the condition before executing the loop body.
do-while loop
Like a while statement, except that it tests the condition at the end
of the loop body.
for loop
Executes a sequence of statements multiple times and abbreviates
the code that manages the loop variable.
Scala - loops
Scala
Repeats a statement or group of statements while a given condition is
true. It tests the condition before executing the loop body.
Scala - while loop
var a = 10;
// while loop execution
while( a < 20 ){
println( "Value of a: " + a );
a = a + 1;
}
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
Scala
Scala - do-while Loop
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
var a = 10;
// do loop execution
do {
println( "Value of a: " + a );
a = a + 1;
}
while( a < 20 )
Like a while statement, except that it tests the condition at the end
of the loop body.
Scala
Scala - for loop
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
var a = 0;
// for loop execution with a range
for( a <- 1 to 10){
println( "Value of a: " + a );
}
Executes a sequence of statements multiple times and abbreviates
the code that manages the loop variable.
Scala
Scala - Functions - Representations
1. def add(x : Int, y : Int) : Int = {
return x + y
}
2. def add(x : Int, y : Int) = { //return type is inferred
x + y //"return" keyword is optional
}
3. //Curly braces are optional on single line blocks
def add(x : Int, y : Int) = x + y
Scala
● Collections provide different ways to store data
● Scala collections hierarchy represents a structure of collections that
can contain data in different ways
Scala - Collections - Overview
Scala
Scala - Collections - Overview
Scala
● An ordered collection of data
● May or may not be indexed
● Array, List, Vector
Scala - Collections - Sequence
Scala
● Contains elements of same type
● Fixed size, ordered sequence of data
● Values are contiguous in memory
● Indexed by position
Scala - Collections - Sequence - Array
Scala
Scala - Collections - Sequence - Array
● var languages = Array("Ruby", "SQL", "Python")
● languages(0)
● languages(1) = "C++"
● // Iterate over array
for(x <- languages) {
println(x);
}
languages :+ "scala"
Scala
● List represents linked list with a value and a pointer to the
next element
● Poor performance as data could be anywhere in the
memory
● Theoretically unbounded in size
Scala - Collections - Sequence - List
Scala
● var number_list = List(1, 2, 3)
● number_list :+ 4
Scala - Collections - Sequence - List
Scala
● Bag of data with no duplicates
● Order is not guaranteed
Scala - Collections - Sets
Scala
● var set = Set(76, 5, 9, 1, 2);
● set = set + 9;
● set = set + 20;
● set(5);
● set(14);
Scala - Collections - Sets
Scala
Scala - Collections - Tuples
● Unlike array or list, tuples can hold elements of different
data types
● Example var t = (14, 45.69, "Australia") or
● var t = Tuple3(14, 45.69, "Australia") //Same result
● Can be accessed using a 1-based accessor for each value
Scala
Scala - Collections - Tuples
● t._1 // 14
● t._3 // Australia
● Can be deconstructed into names bound to each value in
the tuple
● Tuples are immutable
Scala
● Collection of key/value pairs
● Allows indexing values by a specific key for fast access
● Java HashMap, Python dictionary
Scala - Collections - Maps
Scala
Scala - Collections - Maps
● var colors = Map("red" -> "#FF0000", "yellow" -> "#FFFF00")
● colors("yellow")
● colors += "green" -> "#008000"
● colors -= "red"
● for ((key,value) <- colors) {
printf("key: %s, value: %sn", key, value)
}
Scala
Scala - Collections
● Two types of Collection
○ Mutable
○ Immutable
● By default, Scala uses the immutable map
● For mutable maps explicitly import
○ import scala.collection.mutable.Map
https://docs.scala-lang.org/overviews/collections/overview.html
Scala
Scala - Higher Order Functions
● Higher order function is a function which takes another
function as an argument
● Describes “how” the work to be done in a collection
Scala
● The map applies the function to each value in the
collection and returns a new collection
Scala - Higher Order Functions - Map
Scala
Scala - Higher Order Functions - map
3 137 16
3 + 1 7 + 1 16 + 113 + 1
4 148 17
Scala
var list = List(1,2,3)
1. def incrByOne(x:Int): Int = x + 1
list.map(incrByOne)
2. list.map(x => x + 1) // List(2, 3, 4)
3. var list1 = list.map(_+ 1) // Same output
Scala - Higher Order Functions - Map
Scala
● flatMap takes a function as an argument and this function
must return a collection
● Returned collection could be empty
● The flatMap applies the function passed to it as argument
on each value in the collection just like map
● The returned collections from each call of function are
then merged together to form a new collection
Scala - Higher Order Functions - flatMap
Scala
● var list = List("Python", "Go")
● list.flatMap(lang => lang + "#") // List(P, y, t, h, o, n, #, G, o,
#)
● list.flatMap(_+ "#") // Same output
Scala - Higher Order Functions - flatMap
Scala
● Filter applies a function to each value in the collection and
returns a new collection with values that satisfy a condition
specified in the function
Scala - Higher Order Functions - Filter
Scala
Scala - Higher Order Functions - Filter
● var list = List("Scala", "R", "Python", "Go", "SQL")
● list.filter(lang => lang.contains("S")) // List(Scala, SQL)
Scala
● Each of the previous higher order functions returned a
new collection after applying the transformation
● At times we do not want the functions to return a new
collection
○ Waste of memory resources on JVM if we do not want
a return value
● foreach applies a function to each value of collection
without returning a new collection
Scala - Higher Order Functions - foreach
Scala
● var list = List("Python", "Go")
● list.foreach(println)
Scala - Higher Order Functions - foreach
Scala
Scala - Higher Order Functions - Reduce
Scala
Scala - Higher Order Functions - Reduce
3 7 13 16
10
23 39
Scala
Scala - Higher Order Functions - Reduce
● In previous example, addition of two variables was called
again and again until all the values got reduced to a single
value
● Please note, in case of reduce input collection should
contain elements of same data type
Scala
Scala - Higher Order Functions - Reduce
● var list = List(3, 7, 13, 16)
● list.reduce((x, y) => x + y) // 39
● list.reduce(_ + _) // same
Scala
import java.util.{Date, Locale}
import java.text.DateFormat
import java.text.DateFormat._
object USDate {
def getDate(): String = {
val now = new Date
val df = getDateInstance(LONG, Locale.US)
return df.format(now)
}
}
Scala - Interaction with Java
Scala
● If we are working on a big project containing hundreds of
source files, it becomes really tedious to compile these files
manually
● We need a build tool to manage the compilation of all
these files
● SBT is build tool for Scala and Java projects, similar to
Java's Maven or ant
Scala - Build Tool - SBT
Scala
● Sample Scala project is located at CloudxLab GitHub repository
https://github.com/cloudxlab/bigdata/tree/master/scala/sbt
● Clone the repository
git clone https://github.com/cloudxlab/bigdata.git
● Or update the repository
cd ~/bigdata && git pull origin master
Scala - Build Tool - SBT - Demo
Scala
● cd ~/bigdata/scala/sbt
● Look at the build.sbt file and the directory layout. Scala files must be
located at
src/main/scala
● Run the project using
sbt run
Scala - Build Tool - SBT - Demo
Scala
● Case classes are regular classes that are:
○ Immutable by default
○ Can be pattern matched
○ Compiler automatically generates hashCode and equals
methods, so less boilerplate code
○ Helps in writing more expressive and maintainable code
Scala - Case Classes
Scala
● Sample Scala project is located at CloudxLab GitHub repository
https://github.com/cloudxlab/bigdata/tree/master/scala/case_classes
● Clone the repository
git clone https://github.com/cloudxlab/bigdata.git
● Or update the repository
cd ~/cloudxlab && git pull origin master
Scala - Case Classes - Demo
Scala
● cd ~/cloudxlab/scala/case_classes
● scala case_class.scala // Run case class demo
● scala pattern_matching.scala // Run pattern matching demo
Scala - Case Classes - Demo
Scala
Thank You
Scala - End

More Related Content

What's hot

Introduction to Spark ML Pipelines Workshop
Introduction to Spark ML Pipelines WorkshopIntroduction to Spark ML Pipelines Workshop
Introduction to Spark ML Pipelines Workshop
Holden Karau
 
Introduction to Spark with Scala
Introduction to Spark with ScalaIntroduction to Spark with Scala
Introduction to Spark with Scala
Himanshu Gupta
 
Why Scala Is Taking Over the Big Data World
Why Scala Is Taking Over the Big Data WorldWhy Scala Is Taking Over the Big Data World
Why Scala Is Taking Over the Big Data World
Dean Wampler
 
Apache spark Intro
Apache spark IntroApache spark Intro
Apache spark Intro
Tudor Lapusan
 
Dive into spark2
Dive into spark2Dive into spark2
Dive into spark2
Gal Marder
 
Scala Days NYC 2016
Scala Days NYC 2016Scala Days NYC 2016
Scala Days NYC 2016
Martin Odersky
 
Stream processing from single node to a cluster
Stream processing from single node to a clusterStream processing from single node to a cluster
Stream processing from single node to a cluster
Gal Marder
 
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, TokyoWeaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Taro L. Saito
 
Introduction to Spark ML
Introduction to Spark MLIntroduction to Spark ML
Introduction to Spark ML
Holden Karau
 
Beyond shuffling global big data tech conference 2015 sj
Beyond shuffling   global big data tech conference 2015 sjBeyond shuffling   global big data tech conference 2015 sj
Beyond shuffling global big data tech conference 2015 sj
Holden Karau
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
Tomer Gabel
 
Apache Spark
Apache Spark Apache Spark
Apache Spark
Majid Hajibaba
 
Spark architecture
Spark architectureSpark architecture
Spark architecture
datamantra
 
Scala profiling
Scala profilingScala profiling
Scala profiling
Filippo Pacifici
 
Elasticsearch And Apache Lucene For Apache Spark And MLlib
Elasticsearch And Apache Lucene For Apache Spark And MLlibElasticsearch And Apache Lucene For Apache Spark And MLlib
Elasticsearch And Apache Lucene For Apache Spark And MLlib
Jen Aman
 
Survey of Spark for Data Pre-Processing and Analytics
Survey of Spark for Data Pre-Processing and AnalyticsSurvey of Spark for Data Pre-Processing and Analytics
Survey of Spark for Data Pre-Processing and Analytics
Yannick Pouliot
 
Beyond Shuffling - Effective Tips and Tricks for Scaling Spark (Vancouver Sp...
Beyond Shuffling  - Effective Tips and Tricks for Scaling Spark (Vancouver Sp...Beyond Shuffling  - Effective Tips and Tricks for Scaling Spark (Vancouver Sp...
Beyond Shuffling - Effective Tips and Tricks for Scaling Spark (Vancouver Sp...
Holden Karau
 
An Introduction to Scala
An Introduction to ScalaAn Introduction to Scala
An Introduction to ScalaBrent Lemons
 
Introduction to ScalaZ
Introduction to ScalaZIntroduction to ScalaZ
Introduction to ScalaZ
Knoldus Inc.
 
An Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
An Introduction to Higher Order Functions in Spark SQL with Herman van HovellAn Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
An Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
Databricks
 

What's hot (20)

Introduction to Spark ML Pipelines Workshop
Introduction to Spark ML Pipelines WorkshopIntroduction to Spark ML Pipelines Workshop
Introduction to Spark ML Pipelines Workshop
 
Introduction to Spark with Scala
Introduction to Spark with ScalaIntroduction to Spark with Scala
Introduction to Spark with Scala
 
Why Scala Is Taking Over the Big Data World
Why Scala Is Taking Over the Big Data WorldWhy Scala Is Taking Over the Big Data World
Why Scala Is Taking Over the Big Data World
 
Apache spark Intro
Apache spark IntroApache spark Intro
Apache spark Intro
 
Dive into spark2
Dive into spark2Dive into spark2
Dive into spark2
 
Scala Days NYC 2016
Scala Days NYC 2016Scala Days NYC 2016
Scala Days NYC 2016
 
Stream processing from single node to a cluster
Stream processing from single node to a clusterStream processing from single node to a cluster
Stream processing from single node to a cluster
 
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, TokyoWeaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
 
Introduction to Spark ML
Introduction to Spark MLIntroduction to Spark ML
Introduction to Spark ML
 
Beyond shuffling global big data tech conference 2015 sj
Beyond shuffling   global big data tech conference 2015 sjBeyond shuffling   global big data tech conference 2015 sj
Beyond shuffling global big data tech conference 2015 sj
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
Apache Spark
Apache Spark Apache Spark
Apache Spark
 
Spark architecture
Spark architectureSpark architecture
Spark architecture
 
Scala profiling
Scala profilingScala profiling
Scala profiling
 
Elasticsearch And Apache Lucene For Apache Spark And MLlib
Elasticsearch And Apache Lucene For Apache Spark And MLlibElasticsearch And Apache Lucene For Apache Spark And MLlib
Elasticsearch And Apache Lucene For Apache Spark And MLlib
 
Survey of Spark for Data Pre-Processing and Analytics
Survey of Spark for Data Pre-Processing and AnalyticsSurvey of Spark for Data Pre-Processing and Analytics
Survey of Spark for Data Pre-Processing and Analytics
 
Beyond Shuffling - Effective Tips and Tricks for Scaling Spark (Vancouver Sp...
Beyond Shuffling  - Effective Tips and Tricks for Scaling Spark (Vancouver Sp...Beyond Shuffling  - Effective Tips and Tricks for Scaling Spark (Vancouver Sp...
Beyond Shuffling - Effective Tips and Tricks for Scaling Spark (Vancouver Sp...
 
An Introduction to Scala
An Introduction to ScalaAn Introduction to Scala
An Introduction to Scala
 
Introduction to ScalaZ
Introduction to ScalaZIntroduction to ScalaZ
Introduction to ScalaZ
 
An Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
An Introduction to Higher Order Functions in Spark SQL with Herman van HovellAn Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
An Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
 

Similar to Introduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLab

Scala.pdf
Scala.pdfScala.pdf
Scala.pdf
ssuser155dbc1
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Rahul Jain
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersMiles Sabin
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
Miles Sabin
 
Yes scala can!
Yes scala can!Yes scala can!
Yes scala can!
amirmoulavi
 
Scala in a nutshell by venkat
Scala in a nutshell by venkatScala in a nutshell by venkat
Scala in a nutshell by venkat
Venkateswaran Kandasamy
 
Programming in scala - 1
Programming in scala - 1Programming in scala - 1
Programming in scala - 1
Mukesh Kumar
 
A Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersA Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java Developers
Miles Sabin
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersSkills Matter
 
Stepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaStepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to Scala
Derek Chen-Becker
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java Programmers
Eric Pederson
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvm
Isaias Barroso
 
Introduction to Scala : Clueda
Introduction to Scala : CluedaIntroduction to Scala : Clueda
Introduction to Scala : Clueda
Andreas Neumann
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scala
Michael Stal
 
Scalable Applications with Scala
Scalable Applications with ScalaScalable Applications with Scala
Scalable Applications with ScalaNimrod Argov
 
Scala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuScala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuHavoc Pennington
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To Scala
Basuk
 
Scala intro for Java devs 20150324
Scala intro for Java devs 20150324Scala intro for Java devs 20150324
Scala intro for Java devs 20150324
Erik Schmiegelow
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
Pray Desai
 

Similar to Introduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLab (20)

Scala.pdf
Scala.pdfScala.pdf
Scala.pdf
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
 
Yes scala can!
Yes scala can!Yes scala can!
Yes scala can!
 
Scala in a nutshell by venkat
Scala in a nutshell by venkatScala in a nutshell by venkat
Scala in a nutshell by venkat
 
Scala - core features
Scala - core featuresScala - core features
Scala - core features
 
Programming in scala - 1
Programming in scala - 1Programming in scala - 1
Programming in scala - 1
 
A Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersA Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java Developers
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java Developers
 
Stepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaStepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to Scala
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java Programmers
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvm
 
Introduction to Scala : Clueda
Introduction to Scala : CluedaIntroduction to Scala : Clueda
Introduction to Scala : Clueda
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scala
 
Scalable Applications with Scala
Scalable Applications with ScalaScalable Applications with Scala
Scalable Applications with Scala
 
Scala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuScala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on Heroku
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To Scala
 
Scala intro for Java devs 20150324
Scala intro for Java devs 20150324Scala intro for Java devs 20150324
Scala intro for Java devs 20150324
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 

More from CloudxLab

Understanding computer vision with Deep Learning
Understanding computer vision with Deep LearningUnderstanding computer vision with Deep Learning
Understanding computer vision with Deep Learning
CloudxLab
 
Deep Learning Overview
Deep Learning OverviewDeep Learning Overview
Deep Learning Overview
CloudxLab
 
Recurrent Neural Networks
Recurrent Neural NetworksRecurrent Neural Networks
Recurrent Neural Networks
CloudxLab
 
Natural Language Processing
Natural Language ProcessingNatural Language Processing
Natural Language Processing
CloudxLab
 
Naive Bayes
Naive BayesNaive Bayes
Naive Bayes
CloudxLab
 
Autoencoders
AutoencodersAutoencoders
Autoencoders
CloudxLab
 
Training Deep Neural Nets
Training Deep Neural NetsTraining Deep Neural Nets
Training Deep Neural Nets
CloudxLab
 
Reinforcement Learning
Reinforcement LearningReinforcement Learning
Reinforcement Learning
CloudxLab
 
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
CloudxLab
 
Advanced Spark Programming - Part 2 | Big Data Hadoop Spark Tutorial | CloudxLab
Advanced Spark Programming - Part 2 | Big Data Hadoop Spark Tutorial | CloudxLabAdvanced Spark Programming - Part 2 | Big Data Hadoop Spark Tutorial | CloudxLab
Advanced Spark Programming - Part 2 | Big Data Hadoop Spark Tutorial | CloudxLab
CloudxLab
 
Apache Spark - Dataframes & Spark SQL - Part 2 | Big Data Hadoop Spark Tutori...
Apache Spark - Dataframes & Spark SQL - Part 2 | Big Data Hadoop Spark Tutori...Apache Spark - Dataframes & Spark SQL - Part 2 | Big Data Hadoop Spark Tutori...
Apache Spark - Dataframes & Spark SQL - Part 2 | Big Data Hadoop Spark Tutori...
CloudxLab
 
Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...
Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...
Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...
CloudxLab
 
Apache Spark - Running on a Cluster | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Running on a Cluster | Big Data Hadoop Spark Tutorial | CloudxLabApache Spark - Running on a Cluster | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Running on a Cluster | Big Data Hadoop Spark Tutorial | CloudxLab
CloudxLab
 
Introduction to SparkR | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to SparkR | Big Data Hadoop Spark Tutorial | CloudxLabIntroduction to SparkR | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to SparkR | Big Data Hadoop Spark Tutorial | CloudxLab
CloudxLab
 
Introduction to NoSQL | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to NoSQL | Big Data Hadoop Spark Tutorial | CloudxLabIntroduction to NoSQL | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to NoSQL | Big Data Hadoop Spark Tutorial | CloudxLab
CloudxLab
 
Introduction to MapReduce - Hadoop Streaming | Big Data Hadoop Spark Tutorial...
Introduction to MapReduce - Hadoop Streaming | Big Data Hadoop Spark Tutorial...Introduction to MapReduce - Hadoop Streaming | Big Data Hadoop Spark Tutorial...
Introduction to MapReduce - Hadoop Streaming | Big Data Hadoop Spark Tutorial...
CloudxLab
 
Introduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLab
Introduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLabIntroduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLab
Introduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLab
CloudxLab
 
Introduction to Deep Learning | CloudxLab
Introduction to Deep Learning | CloudxLabIntroduction to Deep Learning | CloudxLab
Introduction to Deep Learning | CloudxLab
CloudxLab
 
Dimensionality Reduction | Machine Learning | CloudxLab
Dimensionality Reduction | Machine Learning | CloudxLabDimensionality Reduction | Machine Learning | CloudxLab
Dimensionality Reduction | Machine Learning | CloudxLab
CloudxLab
 
Ensemble Learning and Random Forests
Ensemble Learning and Random ForestsEnsemble Learning and Random Forests
Ensemble Learning and Random Forests
CloudxLab
 

More from CloudxLab (20)

Understanding computer vision with Deep Learning
Understanding computer vision with Deep LearningUnderstanding computer vision with Deep Learning
Understanding computer vision with Deep Learning
 
Deep Learning Overview
Deep Learning OverviewDeep Learning Overview
Deep Learning Overview
 
Recurrent Neural Networks
Recurrent Neural NetworksRecurrent Neural Networks
Recurrent Neural Networks
 
Natural Language Processing
Natural Language ProcessingNatural Language Processing
Natural Language Processing
 
Naive Bayes
Naive BayesNaive Bayes
Naive Bayes
 
Autoencoders
AutoencodersAutoencoders
Autoencoders
 
Training Deep Neural Nets
Training Deep Neural NetsTraining Deep Neural Nets
Training Deep Neural Nets
 
Reinforcement Learning
Reinforcement LearningReinforcement Learning
Reinforcement Learning
 
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
Apache Spark - Key Value RDD - Transformations | Big Data Hadoop Spark Tutori...
 
Advanced Spark Programming - Part 2 | Big Data Hadoop Spark Tutorial | CloudxLab
Advanced Spark Programming - Part 2 | Big Data Hadoop Spark Tutorial | CloudxLabAdvanced Spark Programming - Part 2 | Big Data Hadoop Spark Tutorial | CloudxLab
Advanced Spark Programming - Part 2 | Big Data Hadoop Spark Tutorial | CloudxLab
 
Apache Spark - Dataframes & Spark SQL - Part 2 | Big Data Hadoop Spark Tutori...
Apache Spark - Dataframes & Spark SQL - Part 2 | Big Data Hadoop Spark Tutori...Apache Spark - Dataframes & Spark SQL - Part 2 | Big Data Hadoop Spark Tutori...
Apache Spark - Dataframes & Spark SQL - Part 2 | Big Data Hadoop Spark Tutori...
 
Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...
Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...
Apache Spark - Dataframes & Spark SQL - Part 1 | Big Data Hadoop Spark Tutori...
 
Apache Spark - Running on a Cluster | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Running on a Cluster | Big Data Hadoop Spark Tutorial | CloudxLabApache Spark - Running on a Cluster | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Running on a Cluster | Big Data Hadoop Spark Tutorial | CloudxLab
 
Introduction to SparkR | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to SparkR | Big Data Hadoop Spark Tutorial | CloudxLabIntroduction to SparkR | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to SparkR | Big Data Hadoop Spark Tutorial | CloudxLab
 
Introduction to NoSQL | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to NoSQL | Big Data Hadoop Spark Tutorial | CloudxLabIntroduction to NoSQL | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to NoSQL | Big Data Hadoop Spark Tutorial | CloudxLab
 
Introduction to MapReduce - Hadoop Streaming | Big Data Hadoop Spark Tutorial...
Introduction to MapReduce - Hadoop Streaming | Big Data Hadoop Spark Tutorial...Introduction to MapReduce - Hadoop Streaming | Big Data Hadoop Spark Tutorial...
Introduction to MapReduce - Hadoop Streaming | Big Data Hadoop Spark Tutorial...
 
Introduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLab
Introduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLabIntroduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLab
Introduction To TensorFlow | Deep Learning Using TensorFlow | CloudxLab
 
Introduction to Deep Learning | CloudxLab
Introduction to Deep Learning | CloudxLabIntroduction to Deep Learning | CloudxLab
Introduction to Deep Learning | CloudxLab
 
Dimensionality Reduction | Machine Learning | CloudxLab
Dimensionality Reduction | Machine Learning | CloudxLabDimensionality Reduction | Machine Learning | CloudxLab
Dimensionality Reduction | Machine Learning | CloudxLab
 
Ensemble Learning and Random Forests
Ensemble Learning and Random ForestsEnsemble Learning and Random Forests
Ensemble Learning and Random Forests
 

Recently uploaded

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 

Introduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLab

  • 2. Scala Scala - Scalable Language ● Scala is a modern multi-paradigm programming language designed to express common programming patterns in a concise, elegant, and type-safe way ● Integrates the features of object-oriented and functional languages
  • 3. Scala Why Scala? ● Statically Typed ■ Proven correctness before deployment ■ Performance ● Lightweight Composable Syntax ■ Low boilerplate ■ Syntax is very similar to other data centric languages ● Stable ■ Is being used in enterprises, financial sectors, retail, gaming and more for many years
  • 4. Scala Scala - History 2011 Corporate stewardship 2005 Scala 2.0 written in Scala 2003 First Experimental Release 2001 Decided to create even better Java 1990 Martin Odersky (Creator of Scala) made Java better via generics in the “javac” compiler
  • 5. Scala Scala - JVM ● Scala source code gets compiled to Java byte code ● Resulting bytecode is executed by a JVM - the Java Virtual Machine ● Java libraries may be used directly in Scala code and vice versa
  • 6. Scala // Create a file hello_world.scala // using nano hello_world.scala object HelloWorld { def main(args: Array[String]) { println("Hello, world!") } } Scala - Hello World - Example
  • 7. Scala Scala - Hello World - Compiling and Running ● Compile using scalac scalac hello_world.scala ● To run it scala HelloWorld
  • 8. Scala Scala - Interpreter ● scala hello_world.scala
  • 9. Scala Scala - Interpreter To evaluate a single expression, you can use the following: scala -e 'println("Hello, World!")'
  • 10. Scala Scala - Variables ● Variables are reserved memory locations to store values ● Compiler allocates a memory based on the data type of the variable
  • 11. Scala Scala - Variables - Types ● Mutable ● Immutable
  • 12. Scala Scala - Variables - Types ● Mutable variables are defined using “var” keyword ○ values can be changed ● Immutable variables are defined using “val” keyword ○ values can not be changed after assignment
  • 13. Scala ● val x: Int = 8 // Immutable, Read Only ● var y: Int = 7 // Mutable Scala - Variables - Hands-on
  • 14. Scala What is the importance of immutable variables? ● In large systems, we do not want to be in a situation where a variable's value changes unexpectedly ● In case of threads, APIs, functions and classes, we may not want some of the variables to change Scala - Immutable Variables - Importance
  • 15. Scala ● We can define the variables without specifying their data type ● Scala compiler can understand the type of the variable based on the value assigned to it Scala - Variables - Type Inference
  • 16. Scala ● var x = "hi" // Type Inference (Scala compiler determines the type) ● var x: String = "hi" // Explicitly specifying the type Scala - Variables - Type Inference
  • 17. Scala ● We should always define type of variables explicitly ○ Code will be compiled faster as compiler will not have to spend time in guessing the type ○ No ambiguity Scala - Variables - Type Inference
  • 18. Scala ● A class is a way of creating your own data type ● We can create a data type that represents a customers using a class ● A customer might have states like first name, last name, age, address and contact number ● A customer class might represent behaviours for how these states can be transformed like how to change someone’s address or name ● A class is not concrete until it has been instantiated using a new keyword Scala - Classes
  • 19. Scala class Person(val fname: String, val lname: String, val anage: Int) { val firstname:String = fname; val lastname: String = lname; val age = anage; } val obj = new Person("Robin", "Gill", 42); print(obj.age) print(obj.firstname) Scala - Classes - Hands-on
  • 20. Scala Scala - Classes - Methods - Hands-on class Person(val fname: String, val lname: String, val anage: Int) { val firstname:String = fname; val lastname: String = lname; val age = anage; def getFullName():String = { return firstname + " " + lastname; } } val obj = new Person("Robin", "Gill", 42); print(obj.getFullName())
  • 21. Scala ● A singleton is a class which can have only one instance at any point in time ● Methods and values that aren’t associated with individual instances of a class belong in singleton objects ● A singleton class can be directly accessed via its name ● Create a singleton class using the keyword object Scala - Singleton Objects
  • 22. Scala object Hello { def message(): String = { return "Hello!!!"; } } Hello.message() Scala - Singleton Objects
  • 23. Scala ● Objects are useful in defining utility methods and constants as they are not related to any specific instance of the class Scala - Singleton Objects
  • 24. Scala var x = 10; if( x < 20 ){ println("x is less than 20"); } Scala - if
  • 25. Scala var x = 30; if( x < 20 ){ println("x is less than 20"); } else { println("x is greater than 20"); } Scala - if - else var x = 10; if( x < 20 ){ println("x is less than 20"); }
  • 26. Scala var x = 30; if( x == 10 ){ println("Value of X is 10"); } else if( x == 20 ){ println("Value of X is 20"); } else if( x == 30 ){ println("Value of X is 30"); } else{ println("This is else statement"); } Scala - if - else - if - else
  • 27. Scala while loop Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body. do-while loop Like a while statement, except that it tests the condition at the end of the loop body. for loop Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable. Scala - loops
  • 28. Scala Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body. Scala - while loop var a = 10; // while loop execution while( a < 20 ){ println( "Value of a: " + a ); a = a + 1; } value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 value of a: 16 value of a: 17 value of a: 18 value of a: 19
  • 29. Scala Scala - do-while Loop value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 value of a: 16 value of a: 17 value of a: 18 value of a: 19 var a = 10; // do loop execution do { println( "Value of a: " + a ); a = a + 1; } while( a < 20 ) Like a while statement, except that it tests the condition at the end of the loop body.
  • 30. Scala Scala - for loop value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 value of a: 16 value of a: 17 value of a: 18 value of a: 19 var a = 0; // for loop execution with a range for( a <- 1 to 10){ println( "Value of a: " + a ); } Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.
  • 31. Scala Scala - Functions - Representations 1. def add(x : Int, y : Int) : Int = { return x + y } 2. def add(x : Int, y : Int) = { //return type is inferred x + y //"return" keyword is optional } 3. //Curly braces are optional on single line blocks def add(x : Int, y : Int) = x + y
  • 32. Scala ● Collections provide different ways to store data ● Scala collections hierarchy represents a structure of collections that can contain data in different ways Scala - Collections - Overview
  • 34. Scala ● An ordered collection of data ● May or may not be indexed ● Array, List, Vector Scala - Collections - Sequence
  • 35. Scala ● Contains elements of same type ● Fixed size, ordered sequence of data ● Values are contiguous in memory ● Indexed by position Scala - Collections - Sequence - Array
  • 36. Scala Scala - Collections - Sequence - Array ● var languages = Array("Ruby", "SQL", "Python") ● languages(0) ● languages(1) = "C++" ● // Iterate over array for(x <- languages) { println(x); } languages :+ "scala"
  • 37. Scala ● List represents linked list with a value and a pointer to the next element ● Poor performance as data could be anywhere in the memory ● Theoretically unbounded in size Scala - Collections - Sequence - List
  • 38. Scala ● var number_list = List(1, 2, 3) ● number_list :+ 4 Scala - Collections - Sequence - List
  • 39. Scala ● Bag of data with no duplicates ● Order is not guaranteed Scala - Collections - Sets
  • 40. Scala ● var set = Set(76, 5, 9, 1, 2); ● set = set + 9; ● set = set + 20; ● set(5); ● set(14); Scala - Collections - Sets
  • 41. Scala Scala - Collections - Tuples ● Unlike array or list, tuples can hold elements of different data types ● Example var t = (14, 45.69, "Australia") or ● var t = Tuple3(14, 45.69, "Australia") //Same result ● Can be accessed using a 1-based accessor for each value
  • 42. Scala Scala - Collections - Tuples ● t._1 // 14 ● t._3 // Australia ● Can be deconstructed into names bound to each value in the tuple ● Tuples are immutable
  • 43. Scala ● Collection of key/value pairs ● Allows indexing values by a specific key for fast access ● Java HashMap, Python dictionary Scala - Collections - Maps
  • 44. Scala Scala - Collections - Maps ● var colors = Map("red" -> "#FF0000", "yellow" -> "#FFFF00") ● colors("yellow") ● colors += "green" -> "#008000" ● colors -= "red" ● for ((key,value) <- colors) { printf("key: %s, value: %sn", key, value) }
  • 45. Scala Scala - Collections ● Two types of Collection ○ Mutable ○ Immutable ● By default, Scala uses the immutable map ● For mutable maps explicitly import ○ import scala.collection.mutable.Map https://docs.scala-lang.org/overviews/collections/overview.html
  • 46. Scala Scala - Higher Order Functions ● Higher order function is a function which takes another function as an argument ● Describes “how” the work to be done in a collection
  • 47. Scala ● The map applies the function to each value in the collection and returns a new collection Scala - Higher Order Functions - Map
  • 48. Scala Scala - Higher Order Functions - map 3 137 16 3 + 1 7 + 1 16 + 113 + 1 4 148 17
  • 49. Scala var list = List(1,2,3) 1. def incrByOne(x:Int): Int = x + 1 list.map(incrByOne) 2. list.map(x => x + 1) // List(2, 3, 4) 3. var list1 = list.map(_+ 1) // Same output Scala - Higher Order Functions - Map
  • 50. Scala ● flatMap takes a function as an argument and this function must return a collection ● Returned collection could be empty ● The flatMap applies the function passed to it as argument on each value in the collection just like map ● The returned collections from each call of function are then merged together to form a new collection Scala - Higher Order Functions - flatMap
  • 51. Scala ● var list = List("Python", "Go") ● list.flatMap(lang => lang + "#") // List(P, y, t, h, o, n, #, G, o, #) ● list.flatMap(_+ "#") // Same output Scala - Higher Order Functions - flatMap
  • 52. Scala ● Filter applies a function to each value in the collection and returns a new collection with values that satisfy a condition specified in the function Scala - Higher Order Functions - Filter
  • 53. Scala Scala - Higher Order Functions - Filter ● var list = List("Scala", "R", "Python", "Go", "SQL") ● list.filter(lang => lang.contains("S")) // List(Scala, SQL)
  • 54. Scala ● Each of the previous higher order functions returned a new collection after applying the transformation ● At times we do not want the functions to return a new collection ○ Waste of memory resources on JVM if we do not want a return value ● foreach applies a function to each value of collection without returning a new collection Scala - Higher Order Functions - foreach
  • 55. Scala ● var list = List("Python", "Go") ● list.foreach(println) Scala - Higher Order Functions - foreach
  • 56. Scala Scala - Higher Order Functions - Reduce
  • 57. Scala Scala - Higher Order Functions - Reduce 3 7 13 16 10 23 39
  • 58. Scala Scala - Higher Order Functions - Reduce ● In previous example, addition of two variables was called again and again until all the values got reduced to a single value ● Please note, in case of reduce input collection should contain elements of same data type
  • 59. Scala Scala - Higher Order Functions - Reduce ● var list = List(3, 7, 13, 16) ● list.reduce((x, y) => x + y) // 39 ● list.reduce(_ + _) // same
  • 60. Scala import java.util.{Date, Locale} import java.text.DateFormat import java.text.DateFormat._ object USDate { def getDate(): String = { val now = new Date val df = getDateInstance(LONG, Locale.US) return df.format(now) } } Scala - Interaction with Java
  • 61. Scala ● If we are working on a big project containing hundreds of source files, it becomes really tedious to compile these files manually ● We need a build tool to manage the compilation of all these files ● SBT is build tool for Scala and Java projects, similar to Java's Maven or ant Scala - Build Tool - SBT
  • 62. Scala ● Sample Scala project is located at CloudxLab GitHub repository https://github.com/cloudxlab/bigdata/tree/master/scala/sbt ● Clone the repository git clone https://github.com/cloudxlab/bigdata.git ● Or update the repository cd ~/bigdata && git pull origin master Scala - Build Tool - SBT - Demo
  • 63. Scala ● cd ~/bigdata/scala/sbt ● Look at the build.sbt file and the directory layout. Scala files must be located at src/main/scala ● Run the project using sbt run Scala - Build Tool - SBT - Demo
  • 64. Scala ● Case classes are regular classes that are: ○ Immutable by default ○ Can be pattern matched ○ Compiler automatically generates hashCode and equals methods, so less boilerplate code ○ Helps in writing more expressive and maintainable code Scala - Case Classes
  • 65. Scala ● Sample Scala project is located at CloudxLab GitHub repository https://github.com/cloudxlab/bigdata/tree/master/scala/case_classes ● Clone the repository git clone https://github.com/cloudxlab/bigdata.git ● Or update the repository cd ~/cloudxlab && git pull origin master Scala - Case Classes - Demo
  • 66. Scala ● cd ~/cloudxlab/scala/case_classes ● scala case_class.scala // Run case class demo ● scala pattern_matching.scala // Run pattern matching demo Scala - Case Classes - Demo