SlideShare una empresa de Scribd logo
1 de 21
Descargar para leer sin conexión
Scalable Language
JVM
Scala Conventions
Return is almost optional ; is optional
No args functions doesn’t need ()
def sum(a: Int, b: Int) = a + b def sum(a: Int, b: Int) = {
println(a)
println(b)
a+b
}
def count() = {...}
val cnt = list.count
Type Inference
Scala is strongly typed Type is inferred by scala
val a: Int = 1 def funz(a: Int) = a*10.0
def funz2(a: Int):Double = a*10.0
Value vs Variable
A value is immutable A variable is mutable
scala val ~= java final attribute
val a = 1
a = 2 // error: reassignment to val
var a = 1
a = 2 // ok
Object Oriented
Classes
Constructor is class body itself! Costructors override
class Person(name:String) {
var age = 0
println(name)
}
class Person(name:String) {
var age = 0
def this(name:String, anAge:Int) {
this(name)
age = anAge
}
}
Case Classes
Equals() and hashcode() are already
implemented!!
case class Color(name:String, code: Int)
val c = Color("red", 34567)
Embedded singleton pattern
Scala hasn't static
because Scala is object oriented…. allows you define object
Object and class work togheter
object Obj {
def doSomething() = println
}
Obj.doSomething()
class Color(name:String)
object Color { // this is the singleton
private val colors = Map(
"red" -> new Color("red"),
"green" -> new Color("green"),
"blue" -> new Color("blue"))
def mk(name:String) = colors(name)
}
Traits
Similar to interfaces, but much more powerful!
trait Equal {
def isEqual(x: Any): Boolean //Scala allows traits to be partially implemented
def isNotEqual(x: Any): Boolean = !isEqual(x)
}
class Point(xc: Int, yc: Int) extends Equal {
val x = xc
val y = yc
def isEqual(obj: Any) = obj.isInstanceOf[Point] && obj.asInstanceOf[Point].x == x
}
Multiple Inheritance
Trait rules
trait Swimming { def swim() = println("I'm swimming") }
abstract class Bird { def fly() = println("I'm flying") }
class Bird1 extends Bird
class Bird2 extends Bird with Swimming
new Bird1().fly() // I'm flying
new Bird2().swim() //I'm swimming
(new Bird1() with Swimming).swim() //composable objects at runtime
Functional
First class function
def f1(x: Int) = x
def f2(x: Int) = x * 2
def g(f:Int=>Int, x:Int) = f(x) + 1
g(f1, 3) // f1(3) + 1 → 4
g(f2, 3) // f2(3) + 1 → 7
Pattern Matching
can match int, string, List, case class!
Match is a function too
case class Color(name: String, code: String)
val obj : Any = _
obj match {
case "string" => println("obj String")
case a: Int => println("obj is Int with value: "+a)
case l: List[_] => println("obj is a List")
case Color(name, code) => println("obj is the color: "+name)
case "string" :: item :: other => println("")
case _ => println("")
}
Scala vs Java
def products = orders.flatMap(_.products)
.filter(_.category == category)
val list = List(1,2,3)
public List<Product> getProducts() {
List<Product> products = new ArrayList<Product>();
for(Order order : orders) {
for(Product product : order.getProducts()) {
if(category.equals(product.getCategory())){
products.add(product);
}
}
}
return products;
}
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
Scala XML
val foo = <foo>
<bar type="greet">hi</bar>
<bar type="count">1</bar>
<bar type="color">yellow</bar>
</foo>
(foo  "bar").map(_  "@type")
Enterprise Ready
Scala JS
Scala.js compiles Scala code to JavaScript, allowing you to
write your web application entirely in Scala!
Jquery , AngularJS, NodeJS , etc... are already integrated!
Scalable
"Prefer vals, immutable objects,
and methods without side effects.
Reach for them first. Use vars,
mutable objects, and methods with
side effects when you have a
specific need and justification for
them."
Functional is statelessImmutable is stateless
shared or mutable states are scalability killers
Actors react to received messages by
executing a behavior function
Actors never share state and thus
never need to compete for locks for
access to shared data
Scala Features
Lazy val 
Streams 
String interpolation 
Runtime code generation 
Runtime reflection 
Regex 
Macros, quasiquotes, sequence comprehension, lambda, currying, tuple...etc.
lazy val funcVal = { println("executing"); 3 }
lazy val fibs = BigInt(0) #:: BigInt(1)
#:: Stream.empty
val str = s"the user ${username} has ${numOfTokens} tokens"
toolbox.eval(toolbox.parse("case class D(a: Int, b: Int)"))
def getTypeTag[T: ru.TypeTag](obj: T) = ru.typeTag[T]
val theType = getTypeTag(List(1,2,3)).tpe
val pattern = "(S|s)cala".r
pattern findFirstIn "Scala is Scalable and cool"
Any questions ?

Más contenido relacionado

La actualidad más candente

Intro to Functional Programming in Scala
Intro to Functional Programming in ScalaIntro to Functional Programming in Scala
Intro to Functional Programming in ScalaShai Yallin
 
JavaScript Web Development
JavaScript Web DevelopmentJavaScript Web Development
JavaScript Web Developmentvito jeng
 
Scala introduction
Scala introductionScala introduction
Scala introductionvito jeng
 
Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Derek Chen-Becker
 
First-Class Patterns
First-Class PatternsFirst-Class Patterns
First-Class PatternsJohn De Goes
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesTomer Gabel
 
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 ScalaDerek Chen-Becker
 
Functional Objects & Function and Closures
Functional Objects  & Function and ClosuresFunctional Objects  & Function and Closures
Functional Objects & Function and ClosuresSandip Kumar
 
Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: NotesRoberto Casadei
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scalafanf42
 
Metaprogramming in Scala 2.10, Eugene Burmako,
Metaprogramming  in Scala 2.10, Eugene Burmako, Metaprogramming  in Scala 2.10, Eugene Burmako,
Metaprogramming in Scala 2.10, Eugene Burmako, Vasil Remeniuk
 

La actualidad más candente (20)

Intro to Functional Programming in Scala
Intro to Functional Programming in ScalaIntro to Functional Programming in Scala
Intro to Functional Programming in Scala
 
Workshop Scala
Workshop ScalaWorkshop Scala
Workshop Scala
 
Scala
ScalaScala
Scala
 
JavaScript Web Development
JavaScript Web DevelopmentJavaScript Web Development
JavaScript Web Development
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010
 
First-Class Patterns
First-Class PatternsFirst-Class Patterns
First-Class Patterns
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
 
scala
scalascala
scala
 
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
 
Functional Objects & Function and Closures
Functional Objects  & Function and ClosuresFunctional Objects  & Function and Closures
Functional Objects & Function and Closures
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 
Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: Notes
 
Scala coated JVM
Scala coated JVMScala coated JVM
Scala coated JVM
 
1.2 scala basics
1.2 scala basics1.2 scala basics
1.2 scala basics
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scala
 
Scala fundamentals
Scala fundamentalsScala fundamentals
Scala fundamentals
 
Scalaz
ScalazScalaz
Scalaz
 
Metaprogramming in Scala 2.10, Eugene Burmako,
Metaprogramming  in Scala 2.10, Eugene Burmako, Metaprogramming  in Scala 2.10, Eugene Burmako,
Metaprogramming in Scala 2.10, Eugene Burmako,
 
Scala for curious
Scala for curiousScala for curious
Scala for curious
 

Destacado

Maven c'est bien, SBT c'est mieux
Maven c'est bien, SBT c'est mieuxMaven c'est bien, SBT c'est mieux
Maven c'est bien, SBT c'est mieuxFabrice Sznajderman
 
Agile Lab_BigData_Meetup_AKKA
Agile Lab_BigData_Meetup_AKKAAgile Lab_BigData_Meetup_AKKA
Agile Lab_BigData_Meetup_AKKAPaolo Platter
 
Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010JUG Lausanne
 
Agile Lab_BigData_Meetup
Agile Lab_BigData_MeetupAgile Lab_BigData_Meetup
Agile Lab_BigData_MeetupPaolo Platter
 
Scala in Action - Heiko Seeburger
Scala in Action - Heiko SeeburgerScala in Action - Heiko Seeburger
Scala in Action - Heiko SeeburgerJAX London
 
Getting Functional with Scala
Getting Functional with ScalaGetting Functional with Scala
Getting Functional with ScalaJorge Paez
 
Paris stormusergroup intrudocution
Paris stormusergroup intrudocutionParis stormusergroup intrudocution
Paris stormusergroup intrudocutionParis_Storm_UG
 
Introduction to Spark with Scala
Introduction to Spark with ScalaIntroduction to Spark with Scala
Introduction to Spark with ScalaHimanshu Gupta
 
Scala - A Scalable Language
Scala - A Scalable LanguageScala - A Scalable Language
Scala - A Scalable LanguageMario Gleichmann
 
Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008Yardena Meymann
 
Mémoire de fin d'étude - La big data et les réseaux sociaux
Mémoire de fin d'étude - La big data et les réseaux sociauxMémoire de fin d'étude - La big data et les réseaux sociaux
Mémoire de fin d'étude - La big data et les réseaux sociauxChloé Marty
 
Lagom, reactive framework(chtijug2016)
Lagom, reactive framework(chtijug2016) Lagom, reactive framework(chtijug2016)
Lagom, reactive framework(chtijug2016) Fabrice Sznajderman
 
Démystifions le machine learning avec spark par David Martin pour le Salon B...
Démystifions le machine learning avec spark par David Martin pour le Salon B...Démystifions le machine learning avec spark par David Martin pour le Salon B...
Démystifions le machine learning avec spark par David Martin pour le Salon B...Ippon
 
BDX 2016 - Tzach zohar @ kenshoo
BDX 2016 - Tzach zohar  @ kenshooBDX 2016 - Tzach zohar  @ kenshoo
BDX 2016 - Tzach zohar @ kenshooIdo Shilon
 

Destacado (20)

Maven c'est bien, SBT c'est mieux
Maven c'est bien, SBT c'est mieuxMaven c'est bien, SBT c'est mieux
Maven c'est bien, SBT c'est mieux
 
Universitélang scala tools
Universitélang scala toolsUniversitélang scala tools
Universitélang scala tools
 
Les monades Scala, Java 8
Les monades Scala, Java 8Les monades Scala, Java 8
Les monades Scala, Java 8
 
Université des langages scala
Université des langages   scalaUniversité des langages   scala
Université des langages scala
 
Lagom, reactive framework
Lagom, reactive frameworkLagom, reactive framework
Lagom, reactive framework
 
Agile Lab_BigData_Meetup_AKKA
Agile Lab_BigData_Meetup_AKKAAgile Lab_BigData_Meetup_AKKA
Agile Lab_BigData_Meetup_AKKA
 
Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010
 
Agile Lab_BigData_Meetup
Agile Lab_BigData_MeetupAgile Lab_BigData_Meetup
Agile Lab_BigData_Meetup
 
Scala in Action - Heiko Seeburger
Scala in Action - Heiko SeeburgerScala in Action - Heiko Seeburger
Scala in Action - Heiko Seeburger
 
Getting Functional with Scala
Getting Functional with ScalaGetting Functional with Scala
Getting Functional with Scala
 
Paris stormusergroup intrudocution
Paris stormusergroup intrudocutionParis stormusergroup intrudocution
Paris stormusergroup intrudocution
 
Introduction to Spark with Scala
Introduction to Spark with ScalaIntroduction to Spark with Scala
Introduction to Spark with Scala
 
Hammurabi
HammurabiHammurabi
Hammurabi
 
Soutenance ysance
Soutenance ysanceSoutenance ysance
Soutenance ysance
 
Scala - A Scalable Language
Scala - A Scalable LanguageScala - A Scalable Language
Scala - A Scalable Language
 
Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008
 
Mémoire de fin d'étude - La big data et les réseaux sociaux
Mémoire de fin d'étude - La big data et les réseaux sociauxMémoire de fin d'étude - La big data et les réseaux sociaux
Mémoire de fin d'étude - La big data et les réseaux sociaux
 
Lagom, reactive framework(chtijug2016)
Lagom, reactive framework(chtijug2016) Lagom, reactive framework(chtijug2016)
Lagom, reactive framework(chtijug2016)
 
Démystifions le machine learning avec spark par David Martin pour le Salon B...
Démystifions le machine learning avec spark par David Martin pour le Salon B...Démystifions le machine learning avec spark par David Martin pour le Salon B...
Démystifions le machine learning avec spark par David Martin pour le Salon B...
 
BDX 2016 - Tzach zohar @ kenshoo
BDX 2016 - Tzach zohar  @ kenshooBDX 2016 - Tzach zohar  @ kenshoo
BDX 2016 - Tzach zohar @ kenshoo
 

Similar a Scala Intro

(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?Tomasz Wrobel
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
The Scala Programming Language
The Scala Programming LanguageThe Scala Programming Language
The Scala Programming Languageleague
 
Intro to scala
Intro to scalaIntro to scala
Intro to scalaJoe Zulli
 
Scala-对Java的修正和超越
Scala-对Java的修正和超越Scala-对Java的修正和超越
Scala-对Java的修正和超越Caoyuan Deng
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to ScalaTim Underwood
 
Ten-page Brief Overview of Swift for Scala Developers
Ten-page Brief Overview of Swift for Scala DevelopersTen-page Brief Overview of Swift for Scala Developers
Ten-page Brief Overview of Swift for Scala Developersihji
 
Scala for ruby programmers
Scala for ruby programmersScala for ruby programmers
Scala for ruby programmerstymon Tobolski
 
1.2 scala basics
1.2 scala basics1.2 scala basics
1.2 scala basicswpgreenway
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scalapramode_ce
 
ハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使うハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使うbpstudy
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kirill Rozov
 

Similar a Scala Intro (20)

(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
The Scala Programming Language
The Scala Programming LanguageThe Scala Programming Language
The Scala Programming Language
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Intro to scala
Intro to scalaIntro to scala
Intro to scala
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Scala-对Java的修正和超越
Scala-对Java的修正和超越Scala-对Java的修正和超越
Scala-对Java的修正和超越
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to Scala
 
Ten-page Brief Overview of Swift for Scala Developers
Ten-page Brief Overview of Swift for Scala DevelopersTen-page Brief Overview of Swift for Scala Developers
Ten-page Brief Overview of Swift for Scala Developers
 
Meet scala
Meet scalaMeet scala
Meet scala
 
Scala for ruby programmers
Scala for ruby programmersScala for ruby programmers
Scala for ruby programmers
 
1.2 scala basics
1.2 scala basics1.2 scala basics
1.2 scala basics
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
 
ハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使うハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使う
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2
 
Scala
ScalaScala
Scala
 

Último

cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptrcbcrtm
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 

Último (20)

cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.ppt
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 

Scala Intro

  • 2. JVM
  • 3. Scala Conventions Return is almost optional ; is optional No args functions doesn’t need () def sum(a: Int, b: Int) = a + b def sum(a: Int, b: Int) = { println(a) println(b) a+b } def count() = {...} val cnt = list.count
  • 4. Type Inference Scala is strongly typed Type is inferred by scala val a: Int = 1 def funz(a: Int) = a*10.0 def funz2(a: Int):Double = a*10.0
  • 5. Value vs Variable A value is immutable A variable is mutable scala val ~= java final attribute val a = 1 a = 2 // error: reassignment to val var a = 1 a = 2 // ok
  • 7. Classes Constructor is class body itself! Costructors override class Person(name:String) { var age = 0 println(name) } class Person(name:String) { var age = 0 def this(name:String, anAge:Int) { this(name) age = anAge } }
  • 8. Case Classes Equals() and hashcode() are already implemented!! case class Color(name:String, code: Int) val c = Color("red", 34567)
  • 9. Embedded singleton pattern Scala hasn't static because Scala is object oriented…. allows you define object Object and class work togheter object Obj { def doSomething() = println } Obj.doSomething() class Color(name:String) object Color { // this is the singleton private val colors = Map( "red" -> new Color("red"), "green" -> new Color("green"), "blue" -> new Color("blue")) def mk(name:String) = colors(name) }
  • 10. Traits Similar to interfaces, but much more powerful! trait Equal { def isEqual(x: Any): Boolean //Scala allows traits to be partially implemented def isNotEqual(x: Any): Boolean = !isEqual(x) } class Point(xc: Int, yc: Int) extends Equal { val x = xc val y = yc def isEqual(obj: Any) = obj.isInstanceOf[Point] && obj.asInstanceOf[Point].x == x }
  • 11. Multiple Inheritance Trait rules trait Swimming { def swim() = println("I'm swimming") } abstract class Bird { def fly() = println("I'm flying") } class Bird1 extends Bird class Bird2 extends Bird with Swimming new Bird1().fly() // I'm flying new Bird2().swim() //I'm swimming (new Bird1() with Swimming).swim() //composable objects at runtime
  • 13. First class function def f1(x: Int) = x def f2(x: Int) = x * 2 def g(f:Int=>Int, x:Int) = f(x) + 1 g(f1, 3) // f1(3) + 1 → 4 g(f2, 3) // f2(3) + 1 → 7
  • 14. Pattern Matching can match int, string, List, case class! Match is a function too case class Color(name: String, code: String) val obj : Any = _ obj match { case "string" => println("obj String") case a: Int => println("obj is Int with value: "+a) case l: List[_] => println("obj is a List") case Color(name, code) => println("obj is the color: "+name) case "string" :: item :: other => println("") case _ => println("") }
  • 15. Scala vs Java def products = orders.flatMap(_.products) .filter(_.category == category) val list = List(1,2,3) public List<Product> getProducts() { List<Product> products = new ArrayList<Product>(); for(Order order : orders) { for(Product product : order.getProducts()) { if(category.equals(product.getCategory())){ products.add(product); } } } return products; } ArrayList<Integer> list = new ArrayList<Integer>(); list.add(1); list.add(2); list.add(3);
  • 16. Scala XML val foo = <foo> <bar type="greet">hi</bar> <bar type="count">1</bar> <bar type="color">yellow</bar> </foo> (foo "bar").map(_ "@type")
  • 18. Scala JS Scala.js compiles Scala code to JavaScript, allowing you to write your web application entirely in Scala! Jquery , AngularJS, NodeJS , etc... are already integrated!
  • 19. Scalable "Prefer vals, immutable objects, and methods without side effects. Reach for them first. Use vars, mutable objects, and methods with side effects when you have a specific need and justification for them." Functional is statelessImmutable is stateless shared or mutable states are scalability killers Actors react to received messages by executing a behavior function Actors never share state and thus never need to compete for locks for access to shared data
  • 20. Scala Features Lazy val  Streams  String interpolation  Runtime code generation  Runtime reflection  Regex  Macros, quasiquotes, sequence comprehension, lambda, currying, tuple...etc. lazy val funcVal = { println("executing"); 3 } lazy val fibs = BigInt(0) #:: BigInt(1) #:: Stream.empty val str = s"the user ${username} has ${numOfTokens} tokens" toolbox.eval(toolbox.parse("case class D(a: Int, b: Int)")) def getTypeTag[T: ru.TypeTag](obj: T) = ru.typeTag[T] val theType = getTypeTag(List(1,2,3)).tpe val pattern = "(S|s)cala".r pattern findFirstIn "Scala is Scalable and cool"