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

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
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
 
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 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
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
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
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Recently uploaded (20)

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
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
 
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 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
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
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
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

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