SlideShare a Scribd company logo
Introduction http://www.scala-lang.org Sayeret Lambda January 2011 Yardena Meymann
What is Scala Object oriented and functional Statically typed - advanced type system Compiled to JVM bytecode  but also to CLR, and to JavaScript (in progress) High performance Very good interoperability with Java Support for modularity and extensibility DSL friendly
History 1995 Sun and Netscape team up and announce first beta release of Java
History 1995 Philip Wadler tells Martin Odersky about Java.  Odersky decides to learn the language by writing a compiler
History 1999 Sun buys Java compiler from Martin Odersky, it is shipped with JDK 1.3 OUR JAVA COMPILER ISN’T GOOD ENOUGH I KNOW THIS GUY IN SWITZERLAND, HE WROTE A GREAT JAVA COMPILER !
History 1999 Work on adding generics to Java begins
History 2001 Martin Odersky starts  working on Scala at
Then and Now 2003  Scala 1.0 2006  Scala 2.0 2010  Scala 2.8 “ If I were to pick a language to use today other than Java, it would be  Scala ”  James Gosling
Now Open source projects in Scala:  Akka, Lift, Specs, ScalaCheck, Scalaz, ScalaQuery, … Books: Tools:  built-in REPL, Eclipse, IntelliJ and NetBeans plug-ins integration modules for almost every popular Java framework
Now Used in industry:  LinkedIn, Twitter, Novell, EDF, The Guardian, Xebia, Xerox, Sony, Siemens, … Jobs:
Influences on Scala Design Java, C#  syntax, basic types, and class libraries, Smalltalk  uniform object model, Eiffel  uniform access principle, Beta  systematic nesting, ML, Haskell  many of the functional aspects.
Imagine
No Primitives Everything is an object
No Operators (almost) Everything is a method 1 + 2 1.+(2) 123 toString 123.toString()
No Noise Semicolon inference Type inference Empty and single line blocks don’t need { } Infix notation for method invocations Implicit public Empty parameter lists don’t need ()
No Statements Everything is an expression Return is optional, last expression is returned def  plus2(x:Int) = x + 2 for ,  while ,  if/else  are expressions Unit  equivalent of void
No final val  and  var , memoization def  foo() { val  x = “immutable” var  y = “mutable” lazy   val  z = “lazy” }
No Checked Exceptions All exceptions are  runtime Also, you have  Option[T]  and  Either[A,B]  that can be used instead of checked exceptions
No Statics And no “manual” singletons Instead we have  object  – companion class object HelloWorld { def main(args: Array[String]) = println("Hello, world!") }
First-class Functions val romanNumeral = Map(1 -> "I", 2 -> "II",  3 -> "III", 4 -> "IV", 5 -> "V") An object with apply method can be used as a function val  inc = (x: Int)  =>  x + 1 inc(1)    2
No “Java Bean” Boilerplate Java public class Person { private String name; private int age; public Person(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public int getAge() { return age; } public void setName(String name) { this.name = name; } public void setAge(age: int) { this.age = age; } } Scala class  Person( var name: String, var age: Int)
Case Classes Also generates equals, hashCode and allows decomposition via pattern matching abstract class  Term  case class  Var(name: String)  extends  Term  case class  Fun(arg: String, body: Term) extends Term  case class  App(f: Term, v: Term)  extends  Term
No Switch – Pattern Matching Extractor objects are auto-generated for case classes def  printTerm(term: Term) {  term  match  {  case  Var(n)  =>  print(n)  case  Fun(x, b)  =>   print("^" + x + ".") ; printTerm(b)  case  App(f, v)  =>   Console.print("(");printTerm(f); print(" "); printTerm(v); print(")")  }  }  def  isIdentityFun(term: Term): Boolean = term  match  {  case  Fun(x, Var(y))  if  x == y  =>   true   case  _  =>   false   }
Functions and Closures With some syntax sugar: List(1, 2, 3).map((x: Int) => x + 1)    List(2, 3, 4) List(1, 2, 3).map(x => x + 1) List(1, 2, 3).map(_ + 1) Closures: var  more = 7 val  addMore = (x: Int) => x +  more     10
Lists val  list = 1 :: 2 :: 3 :: Nil list. head      1 list. tail     List(2, 3) list. map (_ + 1)    List(2, 3, 4) list. filter (_ < 2)    List(3) list. exists (_ == 3)    true list. drop (2)    List(3) list. reverse     List(3, 2, 1) list. sort (_ > _)    List(3, 2, 1) List. flatten (list)    List(1, 2, 3) list. slice (2, 3)    List(3) ...
Tuples def  getNameAndAge: Tuple2[String, Int] = { val  name = ... val  age = ... ( name, age ) } val  ( name, age )  = getNameAndAge println(“Name: “ + name) println(“Age: “ + age)
For Comprehensions Find all attendees named Fred that speaks Danish for { att <- attendees if  att.name == “Fred” lang <- att.spokenLanguages if  lang == “Danish” }  yield  att
No Interfaces Trait s for mixin composition  trait  Dad { private var  children: List[Child] = Nil def  addChild(child: Child) = children = child :: children def  getChildren = children.clone } class  Man( val  name: String)  extends  Human val  jonas =  new  Man(“Jonas”)  with  Dad jonas.addChild( new  Child(“Jacob”)) class  Man( val  name: String)  extends  Human  with  Dad
Traits for Multiple Inheritance val  order =  new  Order(customer) with  Entity with  InventoryItemSet with  Invoicable with  PurchaseLimiter with  MailNotifier with  ACL with  Versioned with  Transactional
Traits – Stackable Modification trait  IgnoreCaseSet  extends  java.util.Set[String] { abstract override def  add(e: String) = { super. add(e.toLowerCase) } abstract override def  contains(e: String) = { super. contains(e.toLowerCase) } abstract override def  remove(e: String) = { super. remove(e.toLowerCase) } }
Many More… Far more powerful generics Self types High-order types Structural and dependent types Declaration-site variance and existential types support Views (implicit conversions) and implicit arguments
Many More… Currying, partial functions Continuations Built-in XML support …
This presentation is based on Pragmatic Real-World Scala by Jonas Bonér http://www.slideshare.net/jboner/pragmatic-real-world-scala-45-min-presentation

More Related Content

PDF
Scala at HUJI PL Seminar 2008
PPTX
All about scala
PPTX
Scale up your thinking
PDF
Starting with Scala : Frontier Developer's Meetup December 2010
PDF
scala
PDF
Stepping Up : A Brief Intro to Scala
PDF
Scala coated JVM
PDF
Scala @ TechMeetup Edinburgh
Scala at HUJI PL Seminar 2008
All about scala
Scale up your thinking
Starting with Scala : Frontier Developer's Meetup December 2010
scala
Stepping Up : A Brief Intro to Scala
Scala coated JVM
Scala @ TechMeetup Edinburgh

What's hot (19)

PDF
PDF
Workshop Scala
PPT
Scala - brief intro
PDF
Solid and Sustainable Development in Scala
PPTX
PDF
An Introduction to Scala for Java Developers
PPTX
Scala on Android
PPTX
An introduction to scala
KEY
Scala Introduction
ODP
Functional Objects & Function and Closures
PDF
Scaladroids: Developing Android Apps with Scala
PDF
Pragmatic Real-World Scala (short version)
PPTX
A Brief Intro to Scala
ODP
Meetup slides
PDF
Scala vs Java 8 in a Java 8 World
PPTX
PDF
scalaliftoff2009.pdf
ODP
A Tour Of Scala
PPTX
Scala fundamentals
Workshop Scala
Scala - brief intro
Solid and Sustainable Development in Scala
An Introduction to Scala for Java Developers
Scala on Android
An introduction to scala
Scala Introduction
Functional Objects & Function and Closures
Scaladroids: Developing Android Apps with Scala
Pragmatic Real-World Scala (short version)
A Brief Intro to Scala
Meetup slides
Scala vs Java 8 in a Java 8 World
scalaliftoff2009.pdf
A Tour Of Scala
Scala fundamentals
Ad

Viewers also liked (20)

DOCX
CODA Project- Manisha Arora
PDF
CS 9000 3D presentation
PPT
Google's Go Programming Language - Introduction
PPT
DOCX
3D Internet Report
PPT
3D IC TECHNOLOGY
PPSX
Blue brain seminar report
PDF
3 d internet report
DOCX
light tree documentation by pradeep
PPTX
3D IC Presented by Tripti Kumari, School of Engineering, CUSAT
PPT
Light tree
PDF
Scala : language of the future
PPTX
Seminar_3D INTERNET
DOC
3d i cs_full_seminar_report
PPT
3D Internet
PPT
Blue brain
PPT
Paper battery
PPT
3d internet
PDF
3D PRINTER Seminar fair report (pdf)
PDF
Seminar report on paper battery
CODA Project- Manisha Arora
CS 9000 3D presentation
Google's Go Programming Language - Introduction
3D Internet Report
3D IC TECHNOLOGY
Blue brain seminar report
3 d internet report
light tree documentation by pradeep
3D IC Presented by Tripti Kumari, School of Engineering, CUSAT
Light tree
Scala : language of the future
Seminar_3D INTERNET
3d i cs_full_seminar_report
3D Internet
Blue brain
Paper battery
3d internet
3D PRINTER Seminar fair report (pdf)
Seminar report on paper battery
Ad

Similar to Scala introduction (20)

PDF
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
PDF
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
PDF
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
PDF
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
PPT
Scala presentation by Aleksandar Prokopec
PDF
Scala - en bedre og mere effektiv Java?
PDF
(How) can we benefit from adopting scala?
PDF
Introduction to Scala
PDF
The Scala Programming Language
PPTX
Scala for curious
PDF
Pragmatic Real-World Scala
PDF
Scala - en bedre Java?
PDF
Introduction to scala
PDF
Meet scala
PDF
An Introduction to Scala (2014)
PPT
Scala Talk at FOSDEM 2009
PPTX
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
ODP
ODP
Introduction to Scala
PDF
Scala Bootcamp 1
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
Scala presentation by Aleksandar Prokopec
Scala - en bedre og mere effektiv Java?
(How) can we benefit from adopting scala?
Introduction to Scala
The Scala Programming Language
Scala for curious
Pragmatic Real-World Scala
Scala - en bedre Java?
Introduction to scala
Meet scala
An Introduction to Scala (2014)
Scala Talk at FOSDEM 2009
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
Introduction to Scala
Scala Bootcamp 1

Recently uploaded (20)

PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
KodekX | Application Modernization Development
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Empathic Computing: Creating Shared Understanding
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Machine learning based COVID-19 study performance prediction
Review of recent advances in non-invasive hemoglobin estimation
KodekX | Application Modernization Development
NewMind AI Weekly Chronicles - August'25 Week I
Understanding_Digital_Forensics_Presentation.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Spectral efficient network and resource selection model in 5G networks
Big Data Technologies - Introduction.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Empathic Computing: Creating Shared Understanding
GamePlan Trading System Review: Professional Trader's Honest Take
NewMind AI Monthly Chronicles - July 2025
20250228 LYD VKU AI Blended-Learning.pptx
The AUB Centre for AI in Media Proposal.docx
Advanced Soft Computing BINUS July 2025.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Machine learning based COVID-19 study performance prediction

Scala introduction

  • 2. What is Scala Object oriented and functional Statically typed - advanced type system Compiled to JVM bytecode but also to CLR, and to JavaScript (in progress) High performance Very good interoperability with Java Support for modularity and extensibility DSL friendly
  • 3. History 1995 Sun and Netscape team up and announce first beta release of Java
  • 4. History 1995 Philip Wadler tells Martin Odersky about Java. Odersky decides to learn the language by writing a compiler
  • 5. History 1999 Sun buys Java compiler from Martin Odersky, it is shipped with JDK 1.3 OUR JAVA COMPILER ISN’T GOOD ENOUGH I KNOW THIS GUY IN SWITZERLAND, HE WROTE A GREAT JAVA COMPILER !
  • 6. History 1999 Work on adding generics to Java begins
  • 7. History 2001 Martin Odersky starts working on Scala at
  • 8. Then and Now 2003 Scala 1.0 2006 Scala 2.0 2010 Scala 2.8 “ If I were to pick a language to use today other than Java, it would be Scala ” James Gosling
  • 9. Now Open source projects in Scala: Akka, Lift, Specs, ScalaCheck, Scalaz, ScalaQuery, … Books: Tools: built-in REPL, Eclipse, IntelliJ and NetBeans plug-ins integration modules for almost every popular Java framework
  • 10. Now Used in industry: LinkedIn, Twitter, Novell, EDF, The Guardian, Xebia, Xerox, Sony, Siemens, … Jobs:
  • 11. Influences on Scala Design Java, C# syntax, basic types, and class libraries, Smalltalk uniform object model, Eiffel uniform access principle, Beta systematic nesting, ML, Haskell many of the functional aspects.
  • 13. No Primitives Everything is an object
  • 14. No Operators (almost) Everything is a method 1 + 2 1.+(2) 123 toString 123.toString()
  • 15. No Noise Semicolon inference Type inference Empty and single line blocks don’t need { } Infix notation for method invocations Implicit public Empty parameter lists don’t need ()
  • 16. No Statements Everything is an expression Return is optional, last expression is returned def plus2(x:Int) = x + 2 for , while , if/else are expressions Unit equivalent of void
  • 17. No final val and var , memoization def foo() { val x = “immutable” var y = “mutable” lazy val z = “lazy” }
  • 18. No Checked Exceptions All exceptions are runtime Also, you have Option[T] and Either[A,B] that can be used instead of checked exceptions
  • 19. No Statics And no “manual” singletons Instead we have object – companion class object HelloWorld { def main(args: Array[String]) = println(&quot;Hello, world!&quot;) }
  • 20. First-class Functions val romanNumeral = Map(1 -> &quot;I&quot;, 2 -> &quot;II&quot;, 3 -> &quot;III&quot;, 4 -> &quot;IV&quot;, 5 -> &quot;V&quot;) An object with apply method can be used as a function val inc = (x: Int) => x + 1 inc(1)  2
  • 21. No “Java Bean” Boilerplate Java public class Person { private String name; private int age; public Person(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public int getAge() { return age; } public void setName(String name) { this.name = name; } public void setAge(age: int) { this.age = age; } } Scala class Person( var name: String, var age: Int)
  • 22. Case Classes Also generates equals, hashCode and allows decomposition via pattern matching abstract class Term case class Var(name: String) extends Term case class Fun(arg: String, body: Term) extends Term case class App(f: Term, v: Term) extends Term
  • 23. No Switch – Pattern Matching Extractor objects are auto-generated for case classes def printTerm(term: Term) { term match { case Var(n) => print(n) case Fun(x, b) => print(&quot;^&quot; + x + &quot;.&quot;) ; printTerm(b) case App(f, v) => Console.print(&quot;(&quot;);printTerm(f); print(&quot; &quot;); printTerm(v); print(&quot;)&quot;) } } def isIdentityFun(term: Term): Boolean = term match { case Fun(x, Var(y)) if x == y => true case _ => false }
  • 24. Functions and Closures With some syntax sugar: List(1, 2, 3).map((x: Int) => x + 1)  List(2, 3, 4) List(1, 2, 3).map(x => x + 1) List(1, 2, 3).map(_ + 1) Closures: var more = 7 val addMore = (x: Int) => x + more  10
  • 25. Lists val list = 1 :: 2 :: 3 :: Nil list. head  1 list. tail  List(2, 3) list. map (_ + 1)  List(2, 3, 4) list. filter (_ < 2)  List(3) list. exists (_ == 3)  true list. drop (2)  List(3) list. reverse  List(3, 2, 1) list. sort (_ > _)  List(3, 2, 1) List. flatten (list)  List(1, 2, 3) list. slice (2, 3)  List(3) ...
  • 26. Tuples def getNameAndAge: Tuple2[String, Int] = { val name = ... val age = ... ( name, age ) } val ( name, age ) = getNameAndAge println(“Name: “ + name) println(“Age: “ + age)
  • 27. For Comprehensions Find all attendees named Fred that speaks Danish for { att <- attendees if att.name == “Fred” lang <- att.spokenLanguages if lang == “Danish” } yield att
  • 28. No Interfaces Trait s for mixin composition trait Dad { private var children: List[Child] = Nil def addChild(child: Child) = children = child :: children def getChildren = children.clone } class Man( val name: String) extends Human val jonas = new Man(“Jonas”) with Dad jonas.addChild( new Child(“Jacob”)) class Man( val name: String) extends Human with Dad
  • 29. Traits for Multiple Inheritance val order = new Order(customer) with Entity with InventoryItemSet with Invoicable with PurchaseLimiter with MailNotifier with ACL with Versioned with Transactional
  • 30. Traits – Stackable Modification trait IgnoreCaseSet extends java.util.Set[String] { abstract override def add(e: String) = { super. add(e.toLowerCase) } abstract override def contains(e: String) = { super. contains(e.toLowerCase) } abstract override def remove(e: String) = { super. remove(e.toLowerCase) } }
  • 31. Many More… Far more powerful generics Self types High-order types Structural and dependent types Declaration-site variance and existential types support Views (implicit conversions) and implicit arguments
  • 32. Many More… Currying, partial functions Continuations Built-in XML support …
  • 33. This presentation is based on Pragmatic Real-World Scala by Jonas Bonér http://www.slideshare.net/jboner/pragmatic-real-world-scala-45-min-presentation