SlideShare a Scribd company logo
1 of 38
Download to read offline
Scala in a Java 8 World
Takeaways
•  Why Scala?
•  Scala still relevant in Java 8 world?
What do we need in a
language?
Developers should start thinking
about tens, hundreds, and
thousands of cores now
“
”- Intel
Parallel processing
is hard
Mutable State
public void setX(int x) {
this.x = x;
}
setX(0)
async { setX(getX()) + 1) }
async { setX(getX()) * 2) }
Scala can help
Functional
Object Oriented
JVM Based
All logos owned by respective companies.
Isn’t Java 8
enough?
It’s all about
developer
productivity
class	
  Point	
  {	
  
	
  	
  	
  	
  private	
  int	
  x;	
  
	
  	
  	
  	
  private	
  int	
  y;	
  
	
  	
  
	
  	
  	
  	
  public	
  Point(int	
  x,	
  int	
  y)	
  {	
  
	
  	
  	
  	
  	
  	
  setX(x);	
  
	
  	
  	
  	
  	
  	
  setY(y);	
  
	
  	
  	
  	
  }	
  
	
  	
  
	
  	
  	
  	
  public	
  int	
  getX()	
  {	
  return	
  x;	
  }	
  
	
  	
  	
  	
  public	
  void	
  setX(int	
  x)	
  {	
  this.x	
  =	
  x;}	
  
	
  	
  	
  	
  public	
  int	
  getY()	
  {	
  return	
  y;	
  }	
  
	
  	
  	
  	
  public	
  void	
  setY(int	
  y)	
  {	
  this.y	
  =	
  y;}	
  
	
  	
  
	
  	
  	
  	
  public	
  boolean	
  equals(Object	
  other)	
  {	
  
	
  	
  	
  	
  	
  	
  if	
  (other	
  instanceof	
  Point)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  Point	
  otherPoint	
  =	
  (Point)	
  other;	
  
	
  	
  	
  	
  	
  	
  	
  	
  return	
  otherPoint.getX()	
  ==	
  getX()	
  &&	
  otherPoint.getY()	
  ==	
  getY();	
  
	
  	
  	
  	
  	
  	
  }	
  else	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  return	
  false;	
  
	
  	
  	
  	
  	
  	
  }	
  
	
  	
  	
  	
  }	
  
	
  	
  
	
  	
  	
  	
  public	
  int	
  hashCode()	
  {	
  
	
  	
  	
  	
  	
  	
  return	
  (new	
  Integer[]	
  {getX(),	
  getY()}).hashCode();	
  
	
  	
  	
  	
  }	
  
}
case class Point(var x: Int, var y: Int)
Traits
abstract class Animal {
def speak
}
trait FourLeggedAnimal {
def walk
def run
}
trait WaggingTail {
val tailLength: Int
def startTail { println("tail started") }
def stopTail { println("tail stopped") }
}
class Dog extends Animal with WaggingTail with FourLeggedAnimal {
def speak { println("Dog says 'woof'") }
def walk { println("Dog is walking") }
def run { println("Dog is running") }
}
Immutable Classes
public final class Point {
private final int x;
private final int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() { return x; }
public int getY() { return y; }
}
Java
Scala case class Point(x: Int, y: Int)	
  
Immutable Data Structures
Scala
List(1, 2, 3)
Set(1, 2, 3)
Map(("foo", 1), ("bar", 2))	
  
List<Integer> uList = Arrays.asList(1, 2, 3);
Set<Integer> set = new HashSet<>();
set.add(1);
set.add(2);
Set<Integer> uSet = Collections.unmodifiableSet(set);
Map<String, Integer> map = new HashMap<>();
map.put("foo", 1);
map.put("bar", 2);
Map<String, Integer> uMap = Collections.unmodifiableMap(map);
Java
Lambdas
Scala
peoples.filter(person => person.firstName == “Jon”)!
!
peoples.stream().filter( person -> !
person.firstName.equals(”Jon”)).collect(Collectors.toList())
Java
peoples.map(person => person.firstName)
List(1, 2, 3).reduce(_+_) // 6
List(1, 2, 3).foreach(println)
public class Person {
private String lastName;
private String firstName;
private String middleName;
private String salutation;
private String suffix;
public Person(String lastName, String firstName, String middleName,
String salutation, String suffix) {
this.lastName = lastName;
this.firstName = firstName;
this.middleName = middleName;
this.salutation = salutation;
this.suffix = suffix;
}
}
public class Person {
public static class PersonBuilder {
public PersonBuilder lastName(String newLastName) {
this.lastName = newLastName;
return this;
}
public PersonBuilder firstName(String newFirstName) {
this.firstName = newFirstName;
return this;
}
public PersonBuilder middleName(String newMiddleName) {
this.middleName = newMiddleName;
return this;
}
public PersonBuilder salutation(String newSalutation) {
this.salutation = newSalutation;
return this;
}
public PersonBuilder suffix(String newSuffix) {
this.suffix = newSuffix;
return this;
}
public Person build() { return new Person(this); }
}
}
Named and Default Parameters
case class Person(salutation: String = "Unknown", firstName: String = "Unknown”,
middleName: String = "Unknown", lastName: String = "Unknown",
suffix: String = "Unknown")
Person("Mr", "John", "M”, "Doe”, ”Sr")
Person(salutation = "Mr", firstName = "John", lastName = "Doe")
Person(firstName = "John", middleName = "M", lastName = "Doe")
Person(firstName = "John")
Person(lastName = "Doe")
Person(firstName = "John", lastName = "Doe")
Pattern Matching
def	
  parseArgument(arg	
  :	
  String)
Pattern Matching
def	
  parseArgument(arg	
  :	
  String)	
  =	
  arg	
  match	
  {	
  
}	
  
Pattern Matching
def	
  parseArgument(arg	
  :	
  String)	
  =	
  arg	
  match	
  {	
  
	
  	
  case	
  ("-­‐h"	
  |	
  "-­‐-­‐help”)	
  =>	
  displayHelp()	
  
}
Pattern Matching
def	
  parseArgument(arg	
  :	
  String)	
  =	
  arg	
  match	
  {	
  
	
  	
  case	
  ("-­‐h"	
  |	
  "-­‐-­‐help”)	
  =>	
  displayHelp()	
  
	
  	
  case	
  bad	
  =>	
  badArgument(bad)	
  
}
Pattern Matching
def	
  parseArgument(arg	
  :	
  String,	
  value:	
  Any)
Pattern Matching
def	
  parseArgument(arg	
  :	
  String,	
  value:	
  Any)	
  =	
  (arg,	
  value)	
  match	
  {	
  
}	
  
Pattern Matching
def	
  parseArgument(arg	
  :	
  String,	
  value:	
  Any)	
  =	
  (arg,	
  value)	
  match	
  {	
  
	
  	
  case	
  ("-­‐h"	
  |	
  "-­‐-­‐help",	
  null)	
  =>	
  displayHelp()	
  
	
  	
  case	
  ("-­‐l",	
  lang)	
  =>	
  setLanguageTo(lang)	
  
	
  	
  case	
  bad	
  =>	
  badArgument(bad)	
  
}
Pattern Matching
def	
  parseArgument(arg	
  :	
  String,	
  value:	
  Any)	
  =	
  (arg,	
  value)	
  match	
  {	
  
	
  	
  case	
  ("-­‐h"	
  |	
  "-­‐-­‐help",	
  null)	
  =>	
  displayHelp()	
  
	
  	
  case	
  ("-­‐l",	
  lang)	
  =>	
  setLanguageTo(lang)	
  
	
  	
  case	
  ("-­‐o"	
  |	
  "-­‐-­‐optim",	
  n	
  :	
  Int)	
  if	
  ((0	
  <	
  n)	
  &&	
  (n	
  <=	
  5))	
  =>	
  setOptimizationLevelTo(n)	
  
	
  	
  case	
  ("-­‐o"	
  |	
  "-­‐-­‐optim",	
  badLevel)	
  =>	
  badOptimizationLevel(badLevel)	
  
	
  	
  case	
  bad	
  =>	
  badArgument(bad)	
  
}
Patterns
// constant patterns
case 0 => "zero”
case true => "true”
case "hello" => "you said 'hello'”
case Nil => "an empty List"
// sequence patterns
case List(0, _, _) => "a three-element list with 0 as the first element”
case List(1, _*) => "a list beginning with 1, having any number of elements”
case Vector(1, _*) => "a vector starting with 1, having any number of elements”
// constructor patterns
case Person(first, "Alexander") => s"found an Alexander, first name = $first”
case Dog("Suka") => "found a dog named Suka”
I call it my billion-dollar mistake. It
was the invention of the null
reference in 1965.
“
”- Tony Hoare
Option
def toInt(in: String): Option[Int] = {
    try {
        Some(Integer.parseInt(in.trim))
    } catch {
        case ex: NumberFormatException => None
    }
}
toInt(someString) match {
    case Some(i) => println(i)
    case None => println("That didn't work.")
}
Collections with Option
val bag = List("1", "2", "foo", "3", "bar")
bag.map(toInt) // List[Option[Int]] = List(Some(1), Some(2), None, Some(3), None)
bag.flatMap(toInt) // List(1, 2, 3)
Summary
•  Parallel Processing made easier
•  Developer Productivity
•  Java interoperable
•  Still relevant in a Java 8 world

More Related Content

What's hot

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 Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedSusan Potter
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecLoïc Descotte
 
Functional Objects & Function and Closures
Functional Objects  & Function and ClosuresFunctional Objects  & Function and Closures
Functional Objects & Function and ClosuresSandip Kumar
 
Haskell in the Real World
Haskell in the Real WorldHaskell in the Real World
Haskell in the Real Worldosfameron
 
Feel of Kotlin (Berlin JUG 16 Apr 2015)
Feel of Kotlin (Berlin JUG 16 Apr 2015)Feel of Kotlin (Berlin JUG 16 Apr 2015)
Feel of Kotlin (Berlin JUG 16 Apr 2015)intelliyole
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodecamp Romania
 
JavaScript Web Development
JavaScript Web DevelopmentJavaScript Web Development
JavaScript Web Developmentvito jeng
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Jonas Bonér
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlinintelliyole
 
Fun never stops. introduction to haskell programming language
Fun never stops. introduction to haskell programming languageFun never stops. introduction to haskell programming language
Fun never stops. introduction to haskell programming languagePawel Szulc
 

What's hot (20)

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 Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids Applied
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
1.2 scala basics
1.2 scala basics1.2 scala basics
1.2 scala basics
 
Functional Objects & Function and Closures
Functional Objects  & Function and ClosuresFunctional Objects  & Function and Closures
Functional Objects & Function and Closures
 
Haskell in the Real World
Haskell in the Real WorldHaskell in the Real World
Haskell in the Real World
 
Beyond java8
Beyond java8Beyond java8
Beyond java8
 
scala
scalascala
scala
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
Feel of Kotlin (Berlin JUG 16 Apr 2015)
Feel of Kotlin (Berlin JUG 16 Apr 2015)Feel of Kotlin (Berlin JUG 16 Apr 2015)
Feel of Kotlin (Berlin JUG 16 Apr 2015)
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
 
Hammurabi
HammurabiHammurabi
Hammurabi
 
All about scala
All about scalaAll about scala
All about scala
 
JavaScript Web Development
JavaScript Web DevelopmentJavaScript Web Development
JavaScript Web Development
 
Scala on Android
Scala on AndroidScala on Android
Scala on Android
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlin
 
Fun never stops. introduction to haskell programming language
Fun never stops. introduction to haskell programming languageFun never stops. introduction to haskell programming language
Fun never stops. introduction to haskell programming language
 
Why Haskell
Why HaskellWhy Haskell
Why Haskell
 

Viewers also liked

Gradle: From Extreme to Mainstream
Gradle: From Extreme to MainstreamGradle: From Extreme to Mainstream
Gradle: From Extreme to MainstreamBTI360
 
Migrating Legacy Web Applications to AngularJS
Migrating Legacy Web Applications to AngularJSMigrating Legacy Web Applications to AngularJS
Migrating Legacy Web Applications to AngularJSBTI360
 
AWS Lambda: Coding Without Infrastructure
AWS Lambda: Coding Without InfrastructureAWS Lambda: Coding Without Infrastructure
AWS Lambda: Coding Without InfrastructureBTI360
 
Learn to Speak AWS
Learn to Speak AWSLearn to Speak AWS
Learn to Speak AWSBTI360
 
Scala in practice - 3 years later
Scala in practice - 3 years laterScala in practice - 3 years later
Scala in practice - 3 years laterpatforna
 
A noobs lesson on solr (configuration)
A noobs lesson on solr (configuration)A noobs lesson on solr (configuration)
A noobs lesson on solr (configuration)BTI360
 
Tackling Big Data with the Elephant in the Room
Tackling Big Data with the Elephant in the RoomTackling Big Data with the Elephant in the Room
Tackling Big Data with the Elephant in the RoomBTI360
 
Search Concepts & Tools
Search Concepts & ToolsSearch Concepts & Tools
Search Concepts & ToolsBTI360
 
Microservices a Double-Edged Sword
Microservices a Double-Edged SwordMicroservices a Double-Edged Sword
Microservices a Double-Edged SwordBTI360
 
Java to Scala: Why & How
Java to Scala: Why & HowJava to Scala: Why & How
Java to Scala: Why & HowGraham Tackley
 
Intro to Apache Spark
Intro to Apache SparkIntro to Apache Spark
Intro to Apache SparkBTI360
 
Scala For Java Programmers
Scala For Java ProgrammersScala For Java Programmers
Scala For Java ProgrammersEnno Runne
 
Spock Testing Framework - The Next Generation
Spock Testing Framework - The Next GenerationSpock Testing Framework - The Next Generation
Spock Testing Framework - The Next GenerationBTI360
 
Why Not Make the Transition from Java to Scala?
Why Not Make the Transition from Java to Scala?Why Not Make the Transition from Java to Scala?
Why Not Make the Transition from Java to Scala?BoldRadius Solutions
 
Programming Android Application in Scala.
Programming Android Application in Scala.Programming Android Application in Scala.
Programming Android Application in Scala.Brian Hsu
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to ScalaRahul Jain
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to ScalaTim Underwood
 

Viewers also liked (20)

Gradle: From Extreme to Mainstream
Gradle: From Extreme to MainstreamGradle: From Extreme to Mainstream
Gradle: From Extreme to Mainstream
 
Migrating Legacy Web Applications to AngularJS
Migrating Legacy Web Applications to AngularJSMigrating Legacy Web Applications to AngularJS
Migrating Legacy Web Applications to AngularJS
 
AWS Lambda: Coding Without Infrastructure
AWS Lambda: Coding Without InfrastructureAWS Lambda: Coding Without Infrastructure
AWS Lambda: Coding Without Infrastructure
 
Learn to Speak AWS
Learn to Speak AWSLearn to Speak AWS
Learn to Speak AWS
 
Scala in practice - 3 years later
Scala in practice - 3 years laterScala in practice - 3 years later
Scala in practice - 3 years later
 
A noobs lesson on solr (configuration)
A noobs lesson on solr (configuration)A noobs lesson on solr (configuration)
A noobs lesson on solr (configuration)
 
Tackling Big Data with the Elephant in the Room
Tackling Big Data with the Elephant in the RoomTackling Big Data with the Elephant in the Room
Tackling Big Data with the Elephant in the Room
 
Search Concepts & Tools
Search Concepts & ToolsSearch Concepts & Tools
Search Concepts & Tools
 
Microservices a Double-Edged Sword
Microservices a Double-Edged SwordMicroservices a Double-Edged Sword
Microservices a Double-Edged Sword
 
Java to Scala: Why & How
Java to Scala: Why & HowJava to Scala: Why & How
Java to Scala: Why & How
 
Intro to Apache Spark
Intro to Apache SparkIntro to Apache Spark
Intro to Apache Spark
 
Scala in Practice
Scala in PracticeScala in Practice
Scala in Practice
 
Scala For Java Programmers
Scala For Java ProgrammersScala For Java Programmers
Scala For Java Programmers
 
Spock Testing Framework - The Next Generation
Spock Testing Framework - The Next GenerationSpock Testing Framework - The Next Generation
Spock Testing Framework - The Next Generation
 
Why Not Make the Transition from Java to Scala?
Why Not Make the Transition from Java to Scala?Why Not Make the Transition from Java to Scala?
Why Not Make the Transition from Java to Scala?
 
Programming Android Application in Scala.
Programming Android Application in Scala.Programming Android Application in Scala.
Programming Android Application in Scala.
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Why Scala?
Why Scala?Why Scala?
Why Scala?
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to Scala
 

Similar to Scala vs Java 8 in a Java 8 World

Scala in a Java 8 World
Scala in a Java 8 WorldScala in a Java 8 World
Scala in a Java 8 WorldDaniel Blyth
 
Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Jesper Kamstrup Linnet
 
Ast transformations
Ast transformationsAst transformations
Ast transformationsHamletDRC
 
ハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使うハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使うbpstudy
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)HamletDRC
 
Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7Paulo Morgado
 
An Introduction to Scala (2014)
An Introduction to Scala (2014)An Introduction to Scala (2014)
An Introduction to Scala (2014)William Narmontas
 
여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala Language여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala LanguageAshal aka JOKER
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
2.1 recap from-day_one
2.1 recap from-day_one2.1 recap from-day_one
2.1 recap from-day_onefuturespective
 
Why Scala is the better Java
Why Scala is the better JavaWhy Scala is the better Java
Why Scala is the better JavaThomas Kaiser
 
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
 

Similar to Scala vs Java 8 in a Java 8 World (20)

Scala
ScalaScala
Scala
 
Benefits of Kotlin
Benefits of KotlinBenefits of Kotlin
Benefits of Kotlin
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Scala in a Java 8 World
Scala in a Java 8 WorldScala in a Java 8 World
Scala in a Java 8 World
 
Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?
 
Scala - en bedre Java?
Scala - en bedre Java?Scala - en bedre Java?
Scala - en bedre Java?
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
ハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使うハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使う
 
Scala 2013 review
Scala 2013 reviewScala 2013 review
Scala 2013 review
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)
 
Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7
 
What's New In C# 7
What's New In C# 7What's New In C# 7
What's New In C# 7
 
An Introduction to Scala (2014)
An Introduction to Scala (2014)An Introduction to Scala (2014)
An Introduction to Scala (2014)
 
여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala Language여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala Language
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
2.1 recap from-day_one
2.1 recap from-day_one2.1 recap from-day_one
2.1 recap from-day_one
 
Why Scala is the better Java
Why Scala is the better JavaWhy Scala is the better Java
Why Scala is the better Java
 
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
 

Recently uploaded

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 

Recently uploaded (20)

DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 

Scala vs Java 8 in a Java 8 World

  • 1. Scala in a Java 8 World
  • 2. Takeaways •  Why Scala? •  Scala still relevant in Java 8 world?
  • 3. What do we need in a language?
  • 4.
  • 5. Developers should start thinking about tens, hundreds, and thousands of cores now “ ”- Intel
  • 7. Mutable State public void setX(int x) { this.x = x; } setX(0) async { setX(getX()) + 1) } async { setX(getX()) * 2) }
  • 10.
  • 13. All logos owned by respective companies.
  • 16. class  Point  {          private  int  x;          private  int  y;              public  Point(int  x,  int  y)  {              setX(x);              setY(y);          }              public  int  getX()  {  return  x;  }          public  void  setX(int  x)  {  this.x  =  x;}          public  int  getY()  {  return  y;  }          public  void  setY(int  y)  {  this.y  =  y;}              public  boolean  equals(Object  other)  {              if  (other  instanceof  Point)  {                  Point  otherPoint  =  (Point)  other;                  return  otherPoint.getX()  ==  getX()  &&  otherPoint.getY()  ==  getY();              }  else  {                  return  false;              }          }              public  int  hashCode()  {              return  (new  Integer[]  {getX(),  getY()}).hashCode();          }   }
  • 17. case class Point(var x: Int, var y: Int)
  • 18.
  • 19. Traits abstract class Animal { def speak } trait FourLeggedAnimal { def walk def run } trait WaggingTail { val tailLength: Int def startTail { println("tail started") } def stopTail { println("tail stopped") } } class Dog extends Animal with WaggingTail with FourLeggedAnimal { def speak { println("Dog says 'woof'") } def walk { println("Dog is walking") } def run { println("Dog is running") } }
  • 20. Immutable Classes public final class Point { private final int x; private final int y; public Point(int x, int y) { this.x = x; this.y = y; } public int getX() { return x; } public int getY() { return y; } } Java Scala case class Point(x: Int, y: Int)  
  • 21. Immutable Data Structures Scala List(1, 2, 3) Set(1, 2, 3) Map(("foo", 1), ("bar", 2))   List<Integer> uList = Arrays.asList(1, 2, 3); Set<Integer> set = new HashSet<>(); set.add(1); set.add(2); Set<Integer> uSet = Collections.unmodifiableSet(set); Map<String, Integer> map = new HashMap<>(); map.put("foo", 1); map.put("bar", 2); Map<String, Integer> uMap = Collections.unmodifiableMap(map); Java
  • 22. Lambdas Scala peoples.filter(person => person.firstName == “Jon”)! ! peoples.stream().filter( person -> ! person.firstName.equals(”Jon”)).collect(Collectors.toList()) Java peoples.map(person => person.firstName) List(1, 2, 3).reduce(_+_) // 6 List(1, 2, 3).foreach(println)
  • 23. public class Person { private String lastName; private String firstName; private String middleName; private String salutation; private String suffix; public Person(String lastName, String firstName, String middleName, String salutation, String suffix) { this.lastName = lastName; this.firstName = firstName; this.middleName = middleName; this.salutation = salutation; this.suffix = suffix; } }
  • 24. public class Person { public static class PersonBuilder { public PersonBuilder lastName(String newLastName) { this.lastName = newLastName; return this; } public PersonBuilder firstName(String newFirstName) { this.firstName = newFirstName; return this; } public PersonBuilder middleName(String newMiddleName) { this.middleName = newMiddleName; return this; } public PersonBuilder salutation(String newSalutation) { this.salutation = newSalutation; return this; } public PersonBuilder suffix(String newSuffix) { this.suffix = newSuffix; return this; } public Person build() { return new Person(this); } } }
  • 25. Named and Default Parameters case class Person(salutation: String = "Unknown", firstName: String = "Unknown”, middleName: String = "Unknown", lastName: String = "Unknown", suffix: String = "Unknown") Person("Mr", "John", "M”, "Doe”, ”Sr") Person(salutation = "Mr", firstName = "John", lastName = "Doe") Person(firstName = "John", middleName = "M", lastName = "Doe") Person(firstName = "John") Person(lastName = "Doe") Person(firstName = "John", lastName = "Doe")
  • 27. Pattern Matching def  parseArgument(arg  :  String)  =  arg  match  {   }  
  • 28. Pattern Matching def  parseArgument(arg  :  String)  =  arg  match  {      case  ("-­‐h"  |  "-­‐-­‐help”)  =>  displayHelp()   }
  • 29. Pattern Matching def  parseArgument(arg  :  String)  =  arg  match  {      case  ("-­‐h"  |  "-­‐-­‐help”)  =>  displayHelp()      case  bad  =>  badArgument(bad)   }
  • 30. Pattern Matching def  parseArgument(arg  :  String,  value:  Any)
  • 31. Pattern Matching def  parseArgument(arg  :  String,  value:  Any)  =  (arg,  value)  match  {   }  
  • 32. Pattern Matching def  parseArgument(arg  :  String,  value:  Any)  =  (arg,  value)  match  {      case  ("-­‐h"  |  "-­‐-­‐help",  null)  =>  displayHelp()      case  ("-­‐l",  lang)  =>  setLanguageTo(lang)      case  bad  =>  badArgument(bad)   }
  • 33. Pattern Matching def  parseArgument(arg  :  String,  value:  Any)  =  (arg,  value)  match  {      case  ("-­‐h"  |  "-­‐-­‐help",  null)  =>  displayHelp()      case  ("-­‐l",  lang)  =>  setLanguageTo(lang)      case  ("-­‐o"  |  "-­‐-­‐optim",  n  :  Int)  if  ((0  <  n)  &&  (n  <=  5))  =>  setOptimizationLevelTo(n)      case  ("-­‐o"  |  "-­‐-­‐optim",  badLevel)  =>  badOptimizationLevel(badLevel)      case  bad  =>  badArgument(bad)   }
  • 34. Patterns // constant patterns case 0 => "zero” case true => "true” case "hello" => "you said 'hello'” case Nil => "an empty List" // sequence patterns case List(0, _, _) => "a three-element list with 0 as the first element” case List(1, _*) => "a list beginning with 1, having any number of elements” case Vector(1, _*) => "a vector starting with 1, having any number of elements” // constructor patterns case Person(first, "Alexander") => s"found an Alexander, first name = $first” case Dog("Suka") => "found a dog named Suka”
  • 35. I call it my billion-dollar mistake. It was the invention of the null reference in 1965. “ ”- Tony Hoare
  • 36. Option def toInt(in: String): Option[Int] = {     try {         Some(Integer.parseInt(in.trim))     } catch {         case ex: NumberFormatException => None     } } toInt(someString) match {     case Some(i) => println(i)     case None => println("That didn't work.") }
  • 37. Collections with Option val bag = List("1", "2", "foo", "3", "bar") bag.map(toInt) // List[Option[Int]] = List(Some(1), Some(2), None, Some(3), None) bag.flatMap(toInt) // List(1, 2, 3)
  • 38. Summary •  Parallel Processing made easier •  Developer Productivity •  Java interoperable •  Still relevant in a Java 8 world