SlideShare una empresa de Scribd logo
1 de 83
Introduction to
Hamed Khashechi, Hossein Rimaz
K.N.Toosi University ofTechnology
Table of Contents
• Introduction
• Getting Started
• Features of Language
• Programming Environment
• Demo (Word Count with Spark, Simple Web App using Play, MongoDB,
ReactiveMongo)
• Resources
• Q&A 1
Introduction
• History
• Why Scala
• Scala Ecosystem and Use Cases
2
History
3
The design of Scala started in 2001 at the (EPFL)
by Martin Odersky. Odersky formerly worked
on Generic Java, and javac, Sun's Java compiler.
4
Martin decided take some of the ideas from
functional programming and move them into the
Java space. He has created a language
called Pizza.
Pizza's initial distribution was in 1996, a year after
Java came out. It was moderately successful in that it
showed that one could implement functional
language features on the JVM platform. 5
Then He got in contact with Gilad Bracha and David
Stoutamire from the Sun core developer team.
They said, "We're really interested in the generics
stuff you've been doing; let's do a new project that
does just that.“
And that became GJ (Generic Java). So we developed
GJ in 1997/98, and six years later it became the
generics in Java 5, with some additions that we didn't
do at the time.
6
In the generics design, there were a lot of very, very
hard constraints.
The strongest constraint, the most difficult to cope
with, was that it had to be fully backwards
compatible with ungenerified Java.
That's why there were a number of fairly ugly things.
Like type eraser, raw types, unchecked warnings, … .
7
• Pizza (Odersky andWadler 96) was another language on the
JVM that added functional elements to Java:
• algebraic datatypes and pattern matching
• function values
• generics
• Scala was more ambitious:
• More innovation on the OOP side
• More functional, e.g. immutable values, by-name
parameters,
• Better integration of functional/oop, e.g. case classes.
• Not backwards compatible with Java 8
May 2011, Odersky
launched Typesafe Inc.
Currently named
Lightbend Inc.
9
Why Scala
10
“Scala is an acronym for
Scalable Language ”
Is so named because it was designed to grow with the demands of its users.
11
Why a new Language?
The work on Scala was motivated
by two hypotheses:
Hypothesis 1: A general-purpose
language needs to be scalable; the
same concepts should describe
small as well as large parts.
Hypothesis 2: Scalability can be
achieved by unifying and
generalizing functional and object-
oriented programming concepts.
If we were forced to name just one aspect of Scala that helps scalability, we’d
pick its combination of object-oriented and functional programming.
12
What is Scala?
• Scala compiles to Byte Code in the JVM. Scala programs compile to JVM
bytecodes.Their run-time performance is usually on par with Java programs.
• You can write a .class being java or scala code.
• Interoperability with Java, So you can easily use the Java Ecosystem.
13
Why Scala?
• Scala is concise. No boilerplate code! (semicolons, return, getter/setter, …)
Fewer lines of code mean not only less typing, but also less effort at reading
and understanding programs and fewer possibilities of defects
• Scala is high-level. OOP and FP let you write more complex programs.
• Scala is statically typed, verbosity is avoided through type inference so it look
likes it’s a dynamic language but it’s not.
14
JVM LanguagesTimeline
15
Indeed Scala JobTrend
16
“
”
Even Apple needs Scala developer
17
If I were to pick a language to use today
other than Java, it would be Scala.
James Gosling, the creator of the Java programming language
“
”
18
Scala Ecosystem and Use Cases
19
Scala Use Cases
• Big Data and Data Science
• Web Application Development, REST API Development
• Distributed System, Concurrency and Parallelism
• Scientific Computation like NLP, Numerical Computing and Data
Visualization
20
Scala Use Cases
Big Data and Data Science
• Apache Spark is written in Scala.You can use Spark for machine learning,
graph processing, streaming and generally as an in-memory distributed,
fault-tolerant data processing engine.
21
Scala Use Cases
Big Data and Data Science
• Apache Kafka is written in Scala and Java. It provides a unified, high-
throughput, low-latency platform for handling real-time data feeds.
22
Scala Use Cases
Big Data and Data Science
• Apache Samza is a distributed stream processing framework written in Java
and Scala. It uses Apache Kafka for messaging, and Apache HadoopYARN to
provide fault tolerance, processor isolation, security, and resource
management.
23
Scala Use Cases
Big Data and Data Science
• Apache Flink is a distributed streaming dataflow engine written in Java and
Scala.
24
Scala Use Cases
Web Application Development, REST API Development
• Play is a stateless, asynchronous, and non-blocking framework that uses an
underlying fork-join thread pool to do work stealing for network operations,
and can leverage Akka for user level operations.
• Play Framework makes it easy to build web applications with Java & Scala.
25
Scala Use Cases
Web Application Development, REST API Development
• Lift claim that it is the most powerful, most secure web framework available
today.
• It’s Secure, Scalable, Modular, Designer friendly, and Developer centric.
26
Scala Use Cases
Web Application Development, REST API Development
• Spray is an open-source toolkit for building REST/HTTP-based integration
layers on top of Scala and Akka.
• Being asynchronous, actor-based, fast, lightweight, modular and testable
it's a great way to connect your Scala applications to the world.
27
Scala Use Cases
Web Application Development, REST API Development
• Scalatra is a simple, accessible and free web micro-framework.
• It combines the power of the JVM with the beauty and brevity of Scala,
helping you quickly build high-performance web sites and APIs.
28
Scala Use Cases
Distributed System, Concurrency and Parallelism
• Akka is open source middleware for building highly concurrent, distributed
and fault-tolerant systems on the JVM.
• Akka is built with Scala, but offers both Scala and Java APIs to developers.
• At the heart of Akka is the concept ofActors, which provide an ideal model
for thinking about highly concurrent and scalable systems.
29
Scala Use Cases
Scientific Computation
• Scala NLP library including Breeze, Epic, Puck.
• Wisp is a web-based plotting library.
• ADAM is a genomics processing engine and specialized file format built
using Apache Avro, Apache Spark and Parquet.
• Scala-Chart is another library for creating and working with carts.
• Scalalab is an easy and efficient MATLAB-like scientific computing library in
Scala
30
They all use Scala
https://www.lightbend.com/resources/case-studies-and-storie 31
We’ve found that Scala has enabled us
to deliver things faster with less code.
GrahamTackley from TheGuardian.
“
”
32
Features of Language
• Scala Language Design
• The Basics of Scala
• Functional Programming in Scala
• Object-Oriented Programming in Scala
33
Scala Language Design
• ScalaType System
• Everything is an Expression
• Lexical scope
• Scopes
34
ScalaType System
Scala, unlike some of the other statically typed languages (C, Pascal, Rust,
etc.), does not expect you to provide redundant type information.You
don't have to specify a type in most cases, and you certainly don't have to
repeat it.
Scala has a unified type system, enclosed by the type Any at the top of the
hierarchy and the type Nothing at the
bottom of the hierarchy
35
ScalaType System
36
ScalaType System
• Null: Its aTrait.
• null: Its an instance of Null- Similar to Java null.
• Nil: Represents an empty List of anything of zero length. Its
not that it refers to nothing but it refers to List which has no
contents.
• Nothing: is aTrait. Its a subtype of everything. But not
superclass of anything.There are no instances of Nothing.
• None: Used to represent a sensible return value. Just to avoid
null pointer exception. Option has exactly 2 subclasses- Some
and None. None signifies no result from the method.
• Unit: Type of method that doesn’t return a value of anys sort. 37
Everything is An Expression
In programming language terminology, an "expression" is a combination of values and functions
that are combined and interpreted by the compiler to create a new value, as opposed to a
"statement" which is just a standalone unit of execution and doesn't return anything
def ifThenElseExpression(aBool:Boolean) = if aBool then 42 else 0
38
Lexical Scope (Static)
• Scala using Lexical scoping like many other languages
(why?)
• Much easier for the user (programmer)
• Much easier for the compiler to optimize
39
Scopes
In a Scala program, an inner variable is said to shadow a like-named outer variable, because
the outer variable becomes invisible in the inner scope.
𝐿𝑜𝑐𝑎𝑙 𝐷𝑒𝑓𝑖𝑛𝑖𝑡𝑖𝑜𝑛𝑠 → 𝐸𝑥𝑝𝑙𝑖𝑐𝑖𝑡𝑠 𝑖𝑚𝑝𝑜𝑟𝑡𝑠 → 𝑊𝑖𝑙𝑑 𝑐𝑎𝑟𝑑 𝑖𝑚𝑝𝑜𝑟𝑡𝑠 → 𝑃𝑎𝑐𝑘𝑎𝑔𝑒𝑠
40
The Basics of Language
• DataTypes
• Casting
• Opperations
• If Expression
• Arrays &Tuples & Lists
• For & while Comprehension
• Functions
• Call By ...
• Pattern Matching
41
DataTypes
• Byte
• Short
• Int
• Long
• Float
• Double
• Char
• Boolean
• Unit
scala> var a:Int=2
a: Int = 2
scala> var a:Double=2.2
a: Double = 2.2
scala> var a:Float=2.2f
a: Float = 2.2
scala> var a:Byte=4
a: Byte = 4
scala> var a:Boolean=false
a: Boolean = false 42
Casting
• asInstanceOf
scala> var a:Char=(Char)955//Compile error
<console>:1: error: ';' expected but integer literal found.
var a:Char=(Char)955//Compile error
^
scala> var a:Int=955
a: Int = 955
scala> var b=a.asInstanceOf[Char]
b: Char = λ
43
Operations
scala> var a=955
a: Int = 955
scala> import scala.math._
import scala.math._
scala> print(4-3/5.0)
//compile time they will change to primitive not object any more to run faster 3.4
scala> print(a+3)//a.add(3) add=>+
958
scala> println(math.sin(4*Pi/3).abs)
//1)you can import classes 2)=>math.abs(math.sin(4*Pi/3))
0.8660254037844385
scala> if(a==955) | print("lambda")
Lambda
scala> println("HOLY".>=("EVIL"))
true
44
If Expression
scala> var m="wood"
m: String = wood
scala> println(m.length())
4
scala> println(s"$m is brown")
wood is brown
scala> println(f"$m%5s")
wood
scala> if(m=="wood"){//== is equivalent to equal
| print("brown");
| }else if(m.equals("grass")){
| println("green");
| }else{
| print("i don't know")
| }
brown
45
Arrays
scala> var arr=Array(5,4,47,7,8,7)
arr: Array[Int] = Array(5, 4, 47, 7, 8, 7)
scala> println(arr(1));println(arr(2));println(arr(3));
4 47 7
scala> var array=new Array[String](3);
array: Array[String] = Array(null, null, null)
scala> var at=Array(4,4.7,"Gasai Yuno")
at: Array[Any] = Array(4, 4.7, Gasai Yuno)
scala> var matrix=Array.ofDim[Int](2,2)
matrix: Array[Array[Int]] = Array(Array(0, 0), Array(0, 0))
46
Tuples
scala> var tuples=(2*5,"ten",10.0d,10.0f,10.0,(9,"NINE"))
tuples: (Int, String, Double, Float, Double, (Int, String)) =
(10,ten,10.0,10.0,10.0,(9,NINE))
scala> print(tuples._1)
10
scala> print(tuples._2)
ten
scala> print(tuples._6._2)
NINE
47
Lists
scala> var lst=List("b","c","d")
lst: List[String] = List(b, c, d)
scala> print(lst.head)
b
scala> print(lst.tail)
List(c, d)
scala> var lst2="a"::lst
lst2: List[String] = List(a, b, c, d)
scala> var l=1::2::3::4::Nil
l: List[Int] = List(1, 2, 3, 4)
scala> var l2=l::List(5,6)
l2: List[Any] = List(List(1, 2, 3, 4), 5, 6)
scala> var l3=l:::List(5,6)
l3: List[Int] = List(1, 2, 3, 4, 5, 6)
48
While
• while (Boolean Expression) { Expression }
• do { Expression } while (Boolean Expression)
scala> var i=0;
i: Int = 0
scala> while(i<10){
| i+=1;
| print(i+" ")
| }
1 2 3 4 5 6 7 8 9 10
Note : In functional , It is preferred to not use while and in general imperative style.
49
For Comprehension
• for (Iterations and Conditions)
val books = List("Beginning Scala", "Beginning Groovy",
"Beginning Java", "Scala in easy steps", "Scala in 24
hours")
for (book<-books)
println(book)
var scalabooks = for{ book <-books if
book.contains("Scala") }yield book
for(book<-books if book.contains("Scala") )
println(book)
50
foreach
 foreach (Conditions)
scala> val list = List("Human","Dog","Cat")
list: List[String] = List(Human, Dog, Cat)
scala> list.foreach((s : String) => println(s))
Human
Dog
Cat
scala> list.foreach(s => println(s))
Human
Dog
Cat
scala> list.foreach(println)
Human
Dog
Cat
51
Foreach vs For Comprehension
 Foreach VS for each
scala> for (s<- list) println(s)//it is actually
calling foreach
Human
Dog
Cat
scala> for(s<-list if s.length==3) println(s)
Dog
Cat
scala> list.foreach((s : String) => if(s.length()==3)
println(s))
Dog
Cat
52
Functions
scala> import scala.math._
import scala.math._
scala> def add(x:Int,y:Int):Int = {
| x+y//the last value if you dont specify return
|
| }
add: (x: Int, y: Int)Int
scala> def add(x:Double,y:Double) = x+y
add: (x: Double, y: Double)Double
Note: if you add “return” you need to specify return type else you are
not obligated and one line function no need to bracket.
53
Functions
scala> def printAdd(x:Int,y:Int){// no equal mark no return
| println(x+y)
| }
printAdd: (x: Int, y: Int)Unit
scala> def printAdd(x:Double,y:Double):Unit ={// Unit = void
| println(x+y)
| }
printAdd: (x: Double, y: Double)Unit
54
Functions
scala> def distance1(x1:Double,y1:Double,x2:Double,y2:Double):Double={
| def dif(x1:Double,x2:Double)={
| pow(x2-x1,2)
| }
| return sqrt(dif(x1,x2)+dif(y1,y2))
| }
distance1: (x1: Double, y1: Double, x2: Double, y2: Double)Double
scala> def
distance2(x1:Double,y1:Double,x2:Double,y2:Double,dif:(Double,Double)=>Double):Double={
| return sqrt(dif(x1,x2)+dif(y1,y2))
| }
distance2: (x1: Double, y1: Double, x2: Double, y2: Double, dif: (Double, Double) =>
Double)Double
55
Functions
scala> println(add(4.7,3.2))
7.9
scala> println(distance1(0, 0, 3, 0))
3.0
scala> var dif:(Double,Double)=>Double=(x:Double,y:Double)=>{pow(x-y,2)}
dif: (Double, Double) => Double = <function2>
scala> println(distance2(0, 0, 3, 0, dif))//unanonymous
3.0
scala> println(distance2(0, 0, 3, 0, (x:Double,y:Double)=>pow(x-y,2)))//anonymous
3.0
56
Tail Recursion
import scala.annotation.tailrec
// 1 - basic recursive factorial method
def factorial(n: Int): Int = {
if (n == 0) 1 else n * factorial(n-1)
}
// 2 - tail-recursive factorial method
def factorial2(n: Long): Long = {
@tailrec
def factorialAccumulator(acc: Long, n: Long): Long = {
if (n == 0) acc else factorialAccumulator(n*acc, n-1)
}
factorialAccumulator(1, n)
}
57
Call By Name
def delayed(t:=> Long) = {
println("Indelayed method")
println("Param:"+t)
t
}
58
Call By Ref
def notDelayed(t:Long) = {
println("Innotdelayed method")
println("Param:"+t)
t
}
Note : In Java, all method invocations are call-by-reference or call-
by-value (for primitive types) .
Scala gives you an additional mechanism for passing parameters to
methods (and functions):
call-by-name, which passes a code block to the callee. Each time the
callee accesses the parameter, the code
block is executed and the value is calculated. Call-by-name allows you
to pass parameters that might take a
longtime to calculate but may not be used. 59
Pattern Matching
scala> def matchChecking(a:Any):Unit={
| a match{
| case a:Int => {
| println("One");
| "ali"*5;
| }
| case "two" | "One" => {
| println("Two");
| 2*8;
| }
| case a if a<4.7 =>{
| println("four point seven");
| 3.8*2;
| }
| case _ => {
| println("Recognizing ...");
| a;
| }}}
matchChecking: (a: Any)Unit
scala> matchChecking(1);
One
60
Pattern Matching
scala> def simple_fun(list: List[Char]): List[Nothing] =
list match {
| case x :: xs => {
| println(x)
| simple_fun(xs)
| }
| case _ => Nil
| } simple_fun: (list: List[Char])List[Nothing]
scala> simple_fun(simplelist)
a
b
c
d
res22: List[Nothing] = List()
61
Functional Programming in Scala
• Lazy val & Eager Evaluation
• Currying
• Concurrency
• Closures
62
Lazy val & Eager Evaluation
 lazy val vs. val
The difference between them is, that a val is executed when it is
defined whereas a lazy val is executed when it is accessed the first
time.
In contrast to a method (defined with def) a lazy val is executed once
and then never again.This can be useful when an operation takes
long time to complete and when it is not sure if it is later used.
languages (like Scala) are strict by default, but lazy if explicitly
specified for given variables or parameters.
63
Currying
Methods may define multiple parameter lists.When a method is called
with a fewer number of parameter lists, then this will yield a function
taking the missing parameter lists as its arguments.
scala> def nDividesM(m : Int)(n : Int) = (n % m == 0)
nDividesM: (m: Int)(n: Int)Boolean
scala> val isEven = nDividesM(2)_
isEven: Int => Boolean = <function1>
scala> println(isEven(4))
true
Note : when you give only a subset of the parameters to the function,
the result of the expression is a partially applied function.
64
Closures
A closure is a function, whose return value depends on the value of
one or more variables declared outside this function.
scala> var votingAge = 18
votingAge: Int = 18
scala> val isVotingAge = (age: Int) => age >= votingAge
isVotingAge: Int => Boolean = <function1>
scala> isVotingAge(16)
res2: Boolean = false
65
Concurrency
• You have three options in concurrent programming:
• Akka Actor Model
• Thread
• Apache Spark
66
Actor
• Concurrency using threads is hard
• Shared state – locks, race conditions, deadlocks
• Solution – message passing + no shared state
• Inspired by Erlang language
• Erlang used at Ericsson since 1987, open source since
1998
• Facebook chat backend runs on Erlang
67
What is an Actor?
• Actor is an object that receives messages
• Actor has a mailbox – queue of incoming messages
• Message send is by default asynchronous
• Sending a message to an actor immediately returns
68
Object-Oriented Programming in Scala
• Classes
• Objects
• Traits
• Case Classes
• Exceptions
69
Classes
/** A Person class.
* Constructor parameters become
* public members of the class.*/
class Person(val name: String, var age: Int) {}
var p = new Person(“Peter", 21);
p.age += 1;
70
Objects
• Scala’s way for “statics”
• not quite – see next slide
• (in Scala, there is no static keyword)
• “Companion object” for a class
• = object with same name as the class
71
Objects
// we declare singleton object "Person"
// this is a companion object of class Person
object Person {
def defaultName() = "nobody"
}
class Person(val name: String, var age: Int) {
def getName() : String = name
}
// surprise, Person is really an object
val singleton = Person;
var p:Person=new Person(" ",0)
72
Case Classes
Implicitely override toString, equals, hashCode
take object’s structure into account
Usefull in pattern matching
abstract class Expr
case class Number(n: Int) extends Expr
case class Sum(e1: Expr, e2: Expr) extends Expr
// true thanks to overriden equals
Sum(Number(1), Number(2)) ==
Sum(Number(1), Number(2)) 73
Exceptions
object Main {
def main(args: Array[String]) {
try {
val elems = args.map(Integer.parseInt)
println("Sum is: " + elems.foldRight(0) (_ + _)) }
catch {
case e: NumberFormatException =>
println("Usage: scala Main <n1> <n2> ... ")
}
}
}
74
Traits
Like Java interfaces
But can contain implementations and fields
trait Pet {
var age: Int = 0
def greet(): String = {
return "Hi"
}
}
75
ExtendingTraits
class Dog extends Pet {
override def greet() = "Woof"
}
trait ExclamatoryGreeter extends Pet {
override def greet() = super.greet() + " !"
}
76
Mixins traits
Traits can be “mixed in” at instation time
trait ExclamatoryGreeter extends Pet {
override def greet() = super.greet() +
" !"
}
val pet = new Dog with ExclamatoryGreeter
println(pet.greet()) // Woof !
77
Scala has Multiple inheritance!!!
Solving the Diamond Problem
Scala’s solution to the Diamond Problem is actually fairly simple: it
considers the order in which traits are inherited. If there are multiple
implementors of a given member, the implementation in the supertype
that is furthest to the right (in the list of supertypes) “wins.” Of course, the
body of the class or trait doing the inheriting is further to the right than the
entire list of supertypes, so it “wins” all conflicts, should it provide an
overriding implementation for a member
78
Programming Environment
1. Download & Install JDK
2. Download & Install Scala http://www.scala-lang.org/download/.
3. Add the installed software to your environment
4. Type scala in Console
5. Have fun 
Note:You can download plugins in eclipse and intelij and code 79
Resources
• http://www.scala-lang.org/files/archive/spec/2.12/
• https://www.tutorialspoint.com/scala/
• http://stackoverflow.com/tags/scala/info
• Beginning Scala
80
Q & A
81
THANKS FORYOUR ATTENTION
82

Más contenido relacionado

La actualidad más candente

The Apache Spark File Format Ecosystem
The Apache Spark File Format EcosystemThe Apache Spark File Format Ecosystem
The Apache Spark File Format EcosystemDatabricks
 
A Deep Dive into Query Execution Engine of Spark SQL
A Deep Dive into Query Execution Engine of Spark SQLA Deep Dive into Query Execution Engine of Spark SQL
A Deep Dive into Query Execution Engine of Spark SQLDatabricks
 
Apache Spark Fundamentals
Apache Spark FundamentalsApache Spark Fundamentals
Apache Spark FundamentalsZahra Eskandari
 
From Zero to Hero with Kafka Connect
From Zero to Hero with Kafka ConnectFrom Zero to Hero with Kafka Connect
From Zero to Hero with Kafka Connectconfluent
 
Efficient Data Storage for Analytics with Apache Parquet 2.0
Efficient Data Storage for Analytics with Apache Parquet 2.0Efficient Data Storage for Analytics with Apache Parquet 2.0
Efficient Data Storage for Analytics with Apache Parquet 2.0Cloudera, Inc.
 
Apache Spark in Depth: Core Concepts, Architecture & Internals
Apache Spark in Depth: Core Concepts, Architecture & InternalsApache Spark in Depth: Core Concepts, Architecture & Internals
Apache Spark in Depth: Core Concepts, Architecture & InternalsAnton Kirillov
 
Apache Spark Introduction and Resilient Distributed Dataset basics and deep dive
Apache Spark Introduction and Resilient Distributed Dataset basics and deep diveApache Spark Introduction and Resilient Distributed Dataset basics and deep dive
Apache Spark Introduction and Resilient Distributed Dataset basics and deep diveSachin Aggarwal
 
Introducing DataFrames in Spark for Large Scale Data Science
Introducing DataFrames in Spark for Large Scale Data ScienceIntroducing DataFrames in Spark for Large Scale Data Science
Introducing DataFrames in Spark for Large Scale Data ScienceDatabricks
 
Real-time Stream Processing with Apache Flink
Real-time Stream Processing with Apache FlinkReal-time Stream Processing with Apache Flink
Real-time Stream Processing with Apache FlinkDataWorks Summit
 
The Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization OpportunitiesThe Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization OpportunitiesDatabricks
 
Programming in Spark using PySpark
Programming in Spark using PySpark      Programming in Spark using PySpark
Programming in Spark using PySpark Mostafa
 
Sqoop on Spark for Data Ingestion
Sqoop on Spark for Data IngestionSqoop on Spark for Data Ingestion
Sqoop on Spark for Data IngestionDataWorks Summit
 
Tuning Apache Kafka Connectors for Flink.pptx
Tuning Apache Kafka Connectors for Flink.pptxTuning Apache Kafka Connectors for Flink.pptx
Tuning Apache Kafka Connectors for Flink.pptxFlink Forward
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingMoutaz Haddara
 
Spark overview
Spark overviewSpark overview
Spark overviewLisa Hua
 

La actualidad más candente (20)

The Apache Spark File Format Ecosystem
The Apache Spark File Format EcosystemThe Apache Spark File Format Ecosystem
The Apache Spark File Format Ecosystem
 
Spark SQL
Spark SQLSpark SQL
Spark SQL
 
A Deep Dive into Query Execution Engine of Spark SQL
A Deep Dive into Query Execution Engine of Spark SQLA Deep Dive into Query Execution Engine of Spark SQL
A Deep Dive into Query Execution Engine of Spark SQL
 
Apache Spark Fundamentals
Apache Spark FundamentalsApache Spark Fundamentals
Apache Spark Fundamentals
 
From Zero to Hero with Kafka Connect
From Zero to Hero with Kafka ConnectFrom Zero to Hero with Kafka Connect
From Zero to Hero with Kafka Connect
 
Efficient Data Storage for Analytics with Apache Parquet 2.0
Efficient Data Storage for Analytics with Apache Parquet 2.0Efficient Data Storage for Analytics with Apache Parquet 2.0
Efficient Data Storage for Analytics with Apache Parquet 2.0
 
Apache Spark in Depth: Core Concepts, Architecture & Internals
Apache Spark in Depth: Core Concepts, Architecture & InternalsApache Spark in Depth: Core Concepts, Architecture & Internals
Apache Spark in Depth: Core Concepts, Architecture & Internals
 
Apache Spark Introduction and Resilient Distributed Dataset basics and deep dive
Apache Spark Introduction and Resilient Distributed Dataset basics and deep diveApache Spark Introduction and Resilient Distributed Dataset basics and deep dive
Apache Spark Introduction and Resilient Distributed Dataset basics and deep dive
 
Spark architecture
Spark architectureSpark architecture
Spark architecture
 
Introducing DataFrames in Spark for Large Scale Data Science
Introducing DataFrames in Spark for Large Scale Data ScienceIntroducing DataFrames in Spark for Large Scale Data Science
Introducing DataFrames in Spark for Large Scale Data Science
 
Apache Spark Architecture
Apache Spark ArchitectureApache Spark Architecture
Apache Spark Architecture
 
Real-time Stream Processing with Apache Flink
Real-time Stream Processing with Apache FlinkReal-time Stream Processing with Apache Flink
Real-time Stream Processing with Apache Flink
 
The Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization OpportunitiesThe Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization Opportunities
 
Apache Spark 101
Apache Spark 101Apache Spark 101
Apache Spark 101
 
Programming in Spark using PySpark
Programming in Spark using PySpark      Programming in Spark using PySpark
Programming in Spark using PySpark
 
Sqoop on Spark for Data Ingestion
Sqoop on Spark for Data IngestionSqoop on Spark for Data Ingestion
Sqoop on Spark for Data Ingestion
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 
Tuning Apache Kafka Connectors for Flink.pptx
Tuning Apache Kafka Connectors for Flink.pptxTuning Apache Kafka Connectors for Flink.pptx
Tuning Apache Kafka Connectors for Flink.pptx
 
Introduction to Object Oriented Programming
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Introduction to Object Oriented Programming
 
Spark overview
Spark overviewSpark overview
Spark overview
 

Similar a Introduction to Scala

Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinayViplav Jain
 
Scala adoption by enterprises
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprisesMike Slinn
 
Ten Compelling Reasons to Go the Scala Development Way - Metadesign Solutions
Ten Compelling Reasons to Go the Scala Development Way - Metadesign SolutionsTen Compelling Reasons to Go the Scala Development Way - Metadesign Solutions
Ten Compelling Reasons to Go the Scala Development Way - Metadesign SolutionsMetaDesign Solutions
 
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...Codemotion
 
Scala Introduction - Meetup Scaladores RJ
Scala Introduction - Meetup Scaladores RJScala Introduction - Meetup Scaladores RJ
Scala Introduction - Meetup Scaladores RJRodrigo Lima
 
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...Codemotion
 
Spark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark Summit
 
Scala & Spark Online Training
Scala & Spark Online TrainingScala & Spark Online Training
Scala & Spark Online TrainingLearntek1
 
Scala and Spark are Ideal for Big Data
Scala and Spark are Ideal for Big DataScala and Spark are Ideal for Big Data
Scala and Spark are Ideal for Big DataJohn Nestor
 
Why scala for data science
Why scala for data scienceWhy scala for data science
Why scala for data scienceGuglielmo Iozzia
 
Assist software awesome scala
Assist software   awesome scalaAssist software   awesome scala
Assist software awesome scalaAssistSoftware
 
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
 
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNIntroducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNManish Pandit
 
Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Espen Brækken
 
Experience Converting from Ruby to Scala
Experience Converting from Ruby to ScalaExperience Converting from Ruby to Scala
Experience Converting from Ruby to ScalaJohn Nestor
 
ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!
ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!
ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!panagenda
 
Whitepages Practical Experience Converting from Ruby to Reactive
Whitepages Practical Experience Converting from Ruby to ReactiveWhitepages Practical Experience Converting from Ruby to Reactive
Whitepages Practical Experience Converting from Ruby to ReactiveDragos Manolescu
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumNgoc Dao
 

Similar a Introduction to Scala (20)

Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinay
 
Scala-Ls1
Scala-Ls1Scala-Ls1
Scala-Ls1
 
Scala adoption by enterprises
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprises
 
Ten Compelling Reasons to Go the Scala Development Way - Metadesign Solutions
Ten Compelling Reasons to Go the Scala Development Way - Metadesign SolutionsTen Compelling Reasons to Go the Scala Development Way - Metadesign Solutions
Ten Compelling Reasons to Go the Scala Development Way - Metadesign Solutions
 
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
 
Scala Introduction - Meetup Scaladores RJ
Scala Introduction - Meetup Scaladores RJScala Introduction - Meetup Scaladores RJ
Scala Introduction - Meetup Scaladores RJ
 
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
 
Spark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin Odersky
 
Scala & Spark Online Training
Scala & Spark Online TrainingScala & Spark Online Training
Scala & Spark Online Training
 
Scala and Spark are Ideal for Big Data
Scala and Spark are Ideal for Big DataScala and Spark are Ideal for Big Data
Scala and Spark are Ideal for Big Data
 
Why scala for data science
Why scala for data scienceWhy scala for data science
Why scala for data science
 
Assist software awesome scala
Assist software   awesome scalaAssist software   awesome scala
Assist software awesome 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
 
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNIntroducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
 
Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex
 
Experience Converting from Ruby to Scala
Experience Converting from Ruby to ScalaExperience Converting from Ruby to Scala
Experience Converting from Ruby to Scala
 
Java Introduction
Java IntroductionJava Introduction
Java Introduction
 
ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!
ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!
ICON UK '13 - Apache Software: The FREE Java toolbox you didn't know you had !!
 
Whitepages Practical Experience Converting from Ruby to Reactive
Whitepages Practical Experience Converting from Ruby to ReactiveWhitepages Practical Experience Converting from Ruby to Reactive
Whitepages Practical Experience Converting from Ruby to Reactive
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 

Más de Mohammad Hossein Rimaz

Más de Mohammad Hossein Rimaz (6)

004 - JavaFX Tutorial - Event Handling
004 - JavaFX Tutorial - Event Handling004 - JavaFX Tutorial - Event Handling
004 - JavaFX Tutorial - Event Handling
 
003 - JavaFX Tutorial - Layouts
003 - JavaFX Tutorial - Layouts003 - JavaFX Tutorial - Layouts
003 - JavaFX Tutorial - Layouts
 
002- JavaFX Tutorial - Getting Started
002- JavaFX Tutorial - Getting Started002- JavaFX Tutorial - Getting Started
002- JavaFX Tutorial - Getting Started
 
Java 9, JShell, and Modularity
Java 9, JShell, and ModularityJava 9, JShell, and Modularity
Java 9, JShell, and Modularity
 
Continuous integration with Jenkins
Continuous integration with JenkinsContinuous integration with Jenkins
Continuous integration with Jenkins
 
JavaFX in Action Part I
JavaFX in Action Part IJavaFX in Action Part I
JavaFX in Action Part I
 

Último

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 

Último (20)

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

Introduction to Scala

  • 1. Introduction to Hamed Khashechi, Hossein Rimaz K.N.Toosi University ofTechnology
  • 2. Table of Contents • Introduction • Getting Started • Features of Language • Programming Environment • Demo (Word Count with Spark, Simple Web App using Play, MongoDB, ReactiveMongo) • Resources • Q&A 1
  • 3. Introduction • History • Why Scala • Scala Ecosystem and Use Cases 2
  • 5. The design of Scala started in 2001 at the (EPFL) by Martin Odersky. Odersky formerly worked on Generic Java, and javac, Sun's Java compiler. 4
  • 6. Martin decided take some of the ideas from functional programming and move them into the Java space. He has created a language called Pizza. Pizza's initial distribution was in 1996, a year after Java came out. It was moderately successful in that it showed that one could implement functional language features on the JVM platform. 5
  • 7. Then He got in contact with Gilad Bracha and David Stoutamire from the Sun core developer team. They said, "We're really interested in the generics stuff you've been doing; let's do a new project that does just that.“ And that became GJ (Generic Java). So we developed GJ in 1997/98, and six years later it became the generics in Java 5, with some additions that we didn't do at the time. 6
  • 8. In the generics design, there were a lot of very, very hard constraints. The strongest constraint, the most difficult to cope with, was that it had to be fully backwards compatible with ungenerified Java. That's why there were a number of fairly ugly things. Like type eraser, raw types, unchecked warnings, … . 7
  • 9. • Pizza (Odersky andWadler 96) was another language on the JVM that added functional elements to Java: • algebraic datatypes and pattern matching • function values • generics • Scala was more ambitious: • More innovation on the OOP side • More functional, e.g. immutable values, by-name parameters, • Better integration of functional/oop, e.g. case classes. • Not backwards compatible with Java 8
  • 10. May 2011, Odersky launched Typesafe Inc. Currently named Lightbend Inc. 9
  • 12. “Scala is an acronym for Scalable Language ” Is so named because it was designed to grow with the demands of its users. 11
  • 13. Why a new Language? The work on Scala was motivated by two hypotheses: Hypothesis 1: A general-purpose language needs to be scalable; the same concepts should describe small as well as large parts. Hypothesis 2: Scalability can be achieved by unifying and generalizing functional and object- oriented programming concepts. If we were forced to name just one aspect of Scala that helps scalability, we’d pick its combination of object-oriented and functional programming. 12
  • 14. What is Scala? • Scala compiles to Byte Code in the JVM. Scala programs compile to JVM bytecodes.Their run-time performance is usually on par with Java programs. • You can write a .class being java or scala code. • Interoperability with Java, So you can easily use the Java Ecosystem. 13
  • 15. Why Scala? • Scala is concise. No boilerplate code! (semicolons, return, getter/setter, …) Fewer lines of code mean not only less typing, but also less effort at reading and understanding programs and fewer possibilities of defects • Scala is high-level. OOP and FP let you write more complex programs. • Scala is statically typed, verbosity is avoided through type inference so it look likes it’s a dynamic language but it’s not. 14
  • 18. “ ” Even Apple needs Scala developer 17
  • 19. If I were to pick a language to use today other than Java, it would be Scala. James Gosling, the creator of the Java programming language “ ” 18
  • 20. Scala Ecosystem and Use Cases 19
  • 21. Scala Use Cases • Big Data and Data Science • Web Application Development, REST API Development • Distributed System, Concurrency and Parallelism • Scientific Computation like NLP, Numerical Computing and Data Visualization 20
  • 22. Scala Use Cases Big Data and Data Science • Apache Spark is written in Scala.You can use Spark for machine learning, graph processing, streaming and generally as an in-memory distributed, fault-tolerant data processing engine. 21
  • 23. Scala Use Cases Big Data and Data Science • Apache Kafka is written in Scala and Java. It provides a unified, high- throughput, low-latency platform for handling real-time data feeds. 22
  • 24. Scala Use Cases Big Data and Data Science • Apache Samza is a distributed stream processing framework written in Java and Scala. It uses Apache Kafka for messaging, and Apache HadoopYARN to provide fault tolerance, processor isolation, security, and resource management. 23
  • 25. Scala Use Cases Big Data and Data Science • Apache Flink is a distributed streaming dataflow engine written in Java and Scala. 24
  • 26. Scala Use Cases Web Application Development, REST API Development • Play is a stateless, asynchronous, and non-blocking framework that uses an underlying fork-join thread pool to do work stealing for network operations, and can leverage Akka for user level operations. • Play Framework makes it easy to build web applications with Java & Scala. 25
  • 27. Scala Use Cases Web Application Development, REST API Development • Lift claim that it is the most powerful, most secure web framework available today. • It’s Secure, Scalable, Modular, Designer friendly, and Developer centric. 26
  • 28. Scala Use Cases Web Application Development, REST API Development • Spray is an open-source toolkit for building REST/HTTP-based integration layers on top of Scala and Akka. • Being asynchronous, actor-based, fast, lightweight, modular and testable it's a great way to connect your Scala applications to the world. 27
  • 29. Scala Use Cases Web Application Development, REST API Development • Scalatra is a simple, accessible and free web micro-framework. • It combines the power of the JVM with the beauty and brevity of Scala, helping you quickly build high-performance web sites and APIs. 28
  • 30. Scala Use Cases Distributed System, Concurrency and Parallelism • Akka is open source middleware for building highly concurrent, distributed and fault-tolerant systems on the JVM. • Akka is built with Scala, but offers both Scala and Java APIs to developers. • At the heart of Akka is the concept ofActors, which provide an ideal model for thinking about highly concurrent and scalable systems. 29
  • 31. Scala Use Cases Scientific Computation • Scala NLP library including Breeze, Epic, Puck. • Wisp is a web-based plotting library. • ADAM is a genomics processing engine and specialized file format built using Apache Avro, Apache Spark and Parquet. • Scala-Chart is another library for creating and working with carts. • Scalalab is an easy and efficient MATLAB-like scientific computing library in Scala 30
  • 32. They all use Scala https://www.lightbend.com/resources/case-studies-and-storie 31
  • 33. We’ve found that Scala has enabled us to deliver things faster with less code. GrahamTackley from TheGuardian. “ ” 32
  • 34. Features of Language • Scala Language Design • The Basics of Scala • Functional Programming in Scala • Object-Oriented Programming in Scala 33
  • 35. Scala Language Design • ScalaType System • Everything is an Expression • Lexical scope • Scopes 34
  • 36. ScalaType System Scala, unlike some of the other statically typed languages (C, Pascal, Rust, etc.), does not expect you to provide redundant type information.You don't have to specify a type in most cases, and you certainly don't have to repeat it. Scala has a unified type system, enclosed by the type Any at the top of the hierarchy and the type Nothing at the bottom of the hierarchy 35
  • 38. ScalaType System • Null: Its aTrait. • null: Its an instance of Null- Similar to Java null. • Nil: Represents an empty List of anything of zero length. Its not that it refers to nothing but it refers to List which has no contents. • Nothing: is aTrait. Its a subtype of everything. But not superclass of anything.There are no instances of Nothing. • None: Used to represent a sensible return value. Just to avoid null pointer exception. Option has exactly 2 subclasses- Some and None. None signifies no result from the method. • Unit: Type of method that doesn’t return a value of anys sort. 37
  • 39. Everything is An Expression In programming language terminology, an "expression" is a combination of values and functions that are combined and interpreted by the compiler to create a new value, as opposed to a "statement" which is just a standalone unit of execution and doesn't return anything def ifThenElseExpression(aBool:Boolean) = if aBool then 42 else 0 38
  • 40. Lexical Scope (Static) • Scala using Lexical scoping like many other languages (why?) • Much easier for the user (programmer) • Much easier for the compiler to optimize 39
  • 41. Scopes In a Scala program, an inner variable is said to shadow a like-named outer variable, because the outer variable becomes invisible in the inner scope. 𝐿𝑜𝑐𝑎𝑙 𝐷𝑒𝑓𝑖𝑛𝑖𝑡𝑖𝑜𝑛𝑠 → 𝐸𝑥𝑝𝑙𝑖𝑐𝑖𝑡𝑠 𝑖𝑚𝑝𝑜𝑟𝑡𝑠 → 𝑊𝑖𝑙𝑑 𝑐𝑎𝑟𝑑 𝑖𝑚𝑝𝑜𝑟𝑡𝑠 → 𝑃𝑎𝑐𝑘𝑎𝑔𝑒𝑠 40
  • 42. The Basics of Language • DataTypes • Casting • Opperations • If Expression • Arrays &Tuples & Lists • For & while Comprehension • Functions • Call By ... • Pattern Matching 41
  • 43. DataTypes • Byte • Short • Int • Long • Float • Double • Char • Boolean • Unit scala> var a:Int=2 a: Int = 2 scala> var a:Double=2.2 a: Double = 2.2 scala> var a:Float=2.2f a: Float = 2.2 scala> var a:Byte=4 a: Byte = 4 scala> var a:Boolean=false a: Boolean = false 42
  • 44. Casting • asInstanceOf scala> var a:Char=(Char)955//Compile error <console>:1: error: ';' expected but integer literal found. var a:Char=(Char)955//Compile error ^ scala> var a:Int=955 a: Int = 955 scala> var b=a.asInstanceOf[Char] b: Char = λ 43
  • 45. Operations scala> var a=955 a: Int = 955 scala> import scala.math._ import scala.math._ scala> print(4-3/5.0) //compile time they will change to primitive not object any more to run faster 3.4 scala> print(a+3)//a.add(3) add=>+ 958 scala> println(math.sin(4*Pi/3).abs) //1)you can import classes 2)=>math.abs(math.sin(4*Pi/3)) 0.8660254037844385 scala> if(a==955) | print("lambda") Lambda scala> println("HOLY".>=("EVIL")) true 44
  • 46. If Expression scala> var m="wood" m: String = wood scala> println(m.length()) 4 scala> println(s"$m is brown") wood is brown scala> println(f"$m%5s") wood scala> if(m=="wood"){//== is equivalent to equal | print("brown"); | }else if(m.equals("grass")){ | println("green"); | }else{ | print("i don't know") | } brown 45
  • 47. Arrays scala> var arr=Array(5,4,47,7,8,7) arr: Array[Int] = Array(5, 4, 47, 7, 8, 7) scala> println(arr(1));println(arr(2));println(arr(3)); 4 47 7 scala> var array=new Array[String](3); array: Array[String] = Array(null, null, null) scala> var at=Array(4,4.7,"Gasai Yuno") at: Array[Any] = Array(4, 4.7, Gasai Yuno) scala> var matrix=Array.ofDim[Int](2,2) matrix: Array[Array[Int]] = Array(Array(0, 0), Array(0, 0)) 46
  • 48. Tuples scala> var tuples=(2*5,"ten",10.0d,10.0f,10.0,(9,"NINE")) tuples: (Int, String, Double, Float, Double, (Int, String)) = (10,ten,10.0,10.0,10.0,(9,NINE)) scala> print(tuples._1) 10 scala> print(tuples._2) ten scala> print(tuples._6._2) NINE 47
  • 49. Lists scala> var lst=List("b","c","d") lst: List[String] = List(b, c, d) scala> print(lst.head) b scala> print(lst.tail) List(c, d) scala> var lst2="a"::lst lst2: List[String] = List(a, b, c, d) scala> var l=1::2::3::4::Nil l: List[Int] = List(1, 2, 3, 4) scala> var l2=l::List(5,6) l2: List[Any] = List(List(1, 2, 3, 4), 5, 6) scala> var l3=l:::List(5,6) l3: List[Int] = List(1, 2, 3, 4, 5, 6) 48
  • 50. While • while (Boolean Expression) { Expression } • do { Expression } while (Boolean Expression) scala> var i=0; i: Int = 0 scala> while(i<10){ | i+=1; | print(i+" ") | } 1 2 3 4 5 6 7 8 9 10 Note : In functional , It is preferred to not use while and in general imperative style. 49
  • 51. For Comprehension • for (Iterations and Conditions) val books = List("Beginning Scala", "Beginning Groovy", "Beginning Java", "Scala in easy steps", "Scala in 24 hours") for (book<-books) println(book) var scalabooks = for{ book <-books if book.contains("Scala") }yield book for(book<-books if book.contains("Scala") ) println(book) 50
  • 52. foreach  foreach (Conditions) scala> val list = List("Human","Dog","Cat") list: List[String] = List(Human, Dog, Cat) scala> list.foreach((s : String) => println(s)) Human Dog Cat scala> list.foreach(s => println(s)) Human Dog Cat scala> list.foreach(println) Human Dog Cat 51
  • 53. Foreach vs For Comprehension  Foreach VS for each scala> for (s<- list) println(s)//it is actually calling foreach Human Dog Cat scala> for(s<-list if s.length==3) println(s) Dog Cat scala> list.foreach((s : String) => if(s.length()==3) println(s)) Dog Cat 52
  • 54. Functions scala> import scala.math._ import scala.math._ scala> def add(x:Int,y:Int):Int = { | x+y//the last value if you dont specify return | | } add: (x: Int, y: Int)Int scala> def add(x:Double,y:Double) = x+y add: (x: Double, y: Double)Double Note: if you add “return” you need to specify return type else you are not obligated and one line function no need to bracket. 53
  • 55. Functions scala> def printAdd(x:Int,y:Int){// no equal mark no return | println(x+y) | } printAdd: (x: Int, y: Int)Unit scala> def printAdd(x:Double,y:Double):Unit ={// Unit = void | println(x+y) | } printAdd: (x: Double, y: Double)Unit 54
  • 56. Functions scala> def distance1(x1:Double,y1:Double,x2:Double,y2:Double):Double={ | def dif(x1:Double,x2:Double)={ | pow(x2-x1,2) | } | return sqrt(dif(x1,x2)+dif(y1,y2)) | } distance1: (x1: Double, y1: Double, x2: Double, y2: Double)Double scala> def distance2(x1:Double,y1:Double,x2:Double,y2:Double,dif:(Double,Double)=>Double):Double={ | return sqrt(dif(x1,x2)+dif(y1,y2)) | } distance2: (x1: Double, y1: Double, x2: Double, y2: Double, dif: (Double, Double) => Double)Double 55
  • 57. Functions scala> println(add(4.7,3.2)) 7.9 scala> println(distance1(0, 0, 3, 0)) 3.0 scala> var dif:(Double,Double)=>Double=(x:Double,y:Double)=>{pow(x-y,2)} dif: (Double, Double) => Double = <function2> scala> println(distance2(0, 0, 3, 0, dif))//unanonymous 3.0 scala> println(distance2(0, 0, 3, 0, (x:Double,y:Double)=>pow(x-y,2)))//anonymous 3.0 56
  • 58. Tail Recursion import scala.annotation.tailrec // 1 - basic recursive factorial method def factorial(n: Int): Int = { if (n == 0) 1 else n * factorial(n-1) } // 2 - tail-recursive factorial method def factorial2(n: Long): Long = { @tailrec def factorialAccumulator(acc: Long, n: Long): Long = { if (n == 0) acc else factorialAccumulator(n*acc, n-1) } factorialAccumulator(1, n) } 57
  • 59. Call By Name def delayed(t:=> Long) = { println("Indelayed method") println("Param:"+t) t } 58
  • 60. Call By Ref def notDelayed(t:Long) = { println("Innotdelayed method") println("Param:"+t) t } Note : In Java, all method invocations are call-by-reference or call- by-value (for primitive types) . Scala gives you an additional mechanism for passing parameters to methods (and functions): call-by-name, which passes a code block to the callee. Each time the callee accesses the parameter, the code block is executed and the value is calculated. Call-by-name allows you to pass parameters that might take a longtime to calculate but may not be used. 59
  • 61. Pattern Matching scala> def matchChecking(a:Any):Unit={ | a match{ | case a:Int => { | println("One"); | "ali"*5; | } | case "two" | "One" => { | println("Two"); | 2*8; | } | case a if a<4.7 =>{ | println("four point seven"); | 3.8*2; | } | case _ => { | println("Recognizing ..."); | a; | }}} matchChecking: (a: Any)Unit scala> matchChecking(1); One 60
  • 62. Pattern Matching scala> def simple_fun(list: List[Char]): List[Nothing] = list match { | case x :: xs => { | println(x) | simple_fun(xs) | } | case _ => Nil | } simple_fun: (list: List[Char])List[Nothing] scala> simple_fun(simplelist) a b c d res22: List[Nothing] = List() 61
  • 63. Functional Programming in Scala • Lazy val & Eager Evaluation • Currying • Concurrency • Closures 62
  • 64. Lazy val & Eager Evaluation  lazy val vs. val The difference between them is, that a val is executed when it is defined whereas a lazy val is executed when it is accessed the first time. In contrast to a method (defined with def) a lazy val is executed once and then never again.This can be useful when an operation takes long time to complete and when it is not sure if it is later used. languages (like Scala) are strict by default, but lazy if explicitly specified for given variables or parameters. 63
  • 65. Currying Methods may define multiple parameter lists.When a method is called with a fewer number of parameter lists, then this will yield a function taking the missing parameter lists as its arguments. scala> def nDividesM(m : Int)(n : Int) = (n % m == 0) nDividesM: (m: Int)(n: Int)Boolean scala> val isEven = nDividesM(2)_ isEven: Int => Boolean = <function1> scala> println(isEven(4)) true Note : when you give only a subset of the parameters to the function, the result of the expression is a partially applied function. 64
  • 66. Closures A closure is a function, whose return value depends on the value of one or more variables declared outside this function. scala> var votingAge = 18 votingAge: Int = 18 scala> val isVotingAge = (age: Int) => age >= votingAge isVotingAge: Int => Boolean = <function1> scala> isVotingAge(16) res2: Boolean = false 65
  • 67. Concurrency • You have three options in concurrent programming: • Akka Actor Model • Thread • Apache Spark 66
  • 68. Actor • Concurrency using threads is hard • Shared state – locks, race conditions, deadlocks • Solution – message passing + no shared state • Inspired by Erlang language • Erlang used at Ericsson since 1987, open source since 1998 • Facebook chat backend runs on Erlang 67
  • 69. What is an Actor? • Actor is an object that receives messages • Actor has a mailbox – queue of incoming messages • Message send is by default asynchronous • Sending a message to an actor immediately returns 68
  • 70. Object-Oriented Programming in Scala • Classes • Objects • Traits • Case Classes • Exceptions 69
  • 71. Classes /** A Person class. * Constructor parameters become * public members of the class.*/ class Person(val name: String, var age: Int) {} var p = new Person(“Peter", 21); p.age += 1; 70
  • 72. Objects • Scala’s way for “statics” • not quite – see next slide • (in Scala, there is no static keyword) • “Companion object” for a class • = object with same name as the class 71
  • 73. Objects // we declare singleton object "Person" // this is a companion object of class Person object Person { def defaultName() = "nobody" } class Person(val name: String, var age: Int) { def getName() : String = name } // surprise, Person is really an object val singleton = Person; var p:Person=new Person(" ",0) 72
  • 74. Case Classes Implicitely override toString, equals, hashCode take object’s structure into account Usefull in pattern matching abstract class Expr case class Number(n: Int) extends Expr case class Sum(e1: Expr, e2: Expr) extends Expr // true thanks to overriden equals Sum(Number(1), Number(2)) == Sum(Number(1), Number(2)) 73
  • 75. Exceptions object Main { def main(args: Array[String]) { try { val elems = args.map(Integer.parseInt) println("Sum is: " + elems.foldRight(0) (_ + _)) } catch { case e: NumberFormatException => println("Usage: scala Main <n1> <n2> ... ") } } } 74
  • 76. Traits Like Java interfaces But can contain implementations and fields trait Pet { var age: Int = 0 def greet(): String = { return "Hi" } } 75
  • 77. ExtendingTraits class Dog extends Pet { override def greet() = "Woof" } trait ExclamatoryGreeter extends Pet { override def greet() = super.greet() + " !" } 76
  • 78. Mixins traits Traits can be “mixed in” at instation time trait ExclamatoryGreeter extends Pet { override def greet() = super.greet() + " !" } val pet = new Dog with ExclamatoryGreeter println(pet.greet()) // Woof ! 77
  • 79. Scala has Multiple inheritance!!! Solving the Diamond Problem Scala’s solution to the Diamond Problem is actually fairly simple: it considers the order in which traits are inherited. If there are multiple implementors of a given member, the implementation in the supertype that is furthest to the right (in the list of supertypes) “wins.” Of course, the body of the class or trait doing the inheriting is further to the right than the entire list of supertypes, so it “wins” all conflicts, should it provide an overriding implementation for a member 78
  • 80. Programming Environment 1. Download & Install JDK 2. Download & Install Scala http://www.scala-lang.org/download/. 3. Add the installed software to your environment 4. Type scala in Console 5. Have fun  Note:You can download plugins in eclipse and intelij and code 79

Notas del editor

  1. Pizza já tinha: - Generics - Class cases - Pattern matching
  2. Pizza já tinha: - Generics - Class cases - Pattern matching
  3. Pizza já tinha: - Generics - Class cases - Pattern matching
  4. Criada na Suiça Hoje mantêm o Scala e os frameworks Play e Akka
  5. Tem esse nome pq é designada para crescer de acordo com a demanda do usuário. criar linguagens (DSL)
  6. “Se eu escolhesse uma língua para usar hoje além de Java, seria Scala”
  7. Pizza já tinha: - Generics - Class cases - Pattern matching
  8. - Nós descobrimos que Scala nos permitiu entregar as coisas mais rápido, com menos código. - Falar algum fato sobre eles. ????????????