SlideShare a Scribd company logo
1 of 51
Download to read offline
Scala
f o r J a v a P r o g r a m m e r s
Hello, Scala!
Copyright © 2013 Akira Koyasu. Some rights reserved.
Hello, World!
3
Copyright © 2013 Akira Koyasu. Some rights reserved.
Hello, World!
object HelloWorld {
def main(args: Array[String])
= println("Hello, World!")
}
3
Copyright © 2013 Akira Koyasu. Some rights reserved.
Agenda
About Scala
Features
4
Copyright © 2013 Akira Koyasu. Some rights reserved.
Motivation
Scalable language. To be scalable in the sense
that the same concepts can describe small as
well as large parts.
A unified and generalized object-oriented and
functional programming language provides
scalable support.
From Inventor
5
Copyright © 2013 Akira Koyasu. Some rights reserved.
Motivation
More productive as “better Java” with
existing Java resources.
Several concepts not in Java bring more
posibilities to you.
For Java programmers
6
Copyright © 2013 Akira Koyasu. Some rights reserved.
the Programming
Language
Language Specification
API
Runtime
7
Copyright © 2013 Akira Koyasu. Some rights reserved.
API
8
Scaladoc
Copyright © 2013 Akira Koyasu. Some rights reserved.
Runtime
scalac
.scala
.class
the compiler for .NET
is out of date
JVM
scala
Running on JVM
Compiler generates
class files
9
Copyright © 2013 Akira Koyasu. Some rights reserved.
Influencers
Java C#
Smalltalk
Haskell
Algol Simula
Eiffel
SML F#
Erlang
Iswim
Lisp
Python
Ruby
10
Copyright © 2013 Akira Koyasu. Some rights reserved.
Inventor
Martin Odersky
Professor of
programming methods at
EPFL in Switzerland
Designer of Java
generics
photo#1
11
Copyright © 2013 Akira Koyasu. Some rights reserved.
Object, Operator
val apple = new Apple
val orange = new Orange
println(apple + orange)
?
12
Copyright © 2013 Akira Koyasu. Some rights reserved.
Object, Operator
val apple = new Apple
val orange = new Orange
println(apple + orange)
?
(A) "Apple@xxxxOrange@xxxx"
(B) 2
(C) Compile error
(D) Runtime exception
(E) Others
12
Copyright © 2013 Akira Koyasu. Some rights reserved.
Features
Static typing & Suitable type inference
Object-oriented & Functional
Trait
Collaborating with Java
13
Copyright © 2013 Akira Koyasu. Some rights reserved.
Vorbose Java
Type declaration
public String suffix(String str) {
	 int pos = str.indexOf("-");
	 return str.substring(pos);
}
14
Copyright © 2013 Akira Koyasu. Some rights reserved.
Vorbose Java
Type declaration
def suffix(str: String) = {
val pos = str.indexOf("-")
str.substring(pos)
}
14
Copyright © 2013 Akira Koyasu. Some rights reserved.
Vorbose Java
JavaBeans
public class JavaBeans {
	 private String name;
	 public String getName() {
	 	 return name;
	 }
	 public void setName(String name) {
	 	 this.name = name;
	 }
}
15
Copyright © 2013 Akira Koyasu. Some rights reserved.
Vorbose Java
JavaBeans
case class ScalaCase(name: String)
15
Copyright © 2013 Akira Koyasu. Some rights reserved.
Functional
Programming
variables
method parameters
method returns
Functions are the first-class values
16
Copyright © 2013 Akira Koyasu. Some rights reserved.
Functional
Programming
Consider a method signature sending mails to
appropriate addresses from listing
def send() {
for(c: Contact <- listing()) {
mail(c)
}
}
17
Copyright © 2013 Akira Koyasu. Some rights reserved.
Functional
Programming
18
Copyright © 2013 Akira Koyasu. Some rights reserved.
Functional
Programming
age==20
18
Copyright © 2013 Akira Koyasu. Some rights reserved.
Functional
Programming
age==20 def send(age: Int)
18
Copyright © 2013 Akira Koyasu. Some rights reserved.
Functional
Programming
age==20
35<=age, age<=60
def send(age: Int)
18
Copyright © 2013 Akira Koyasu. Some rights reserved.
Functional
Programming
age==20
35<=age, age<=60
def send(age: Int)
def send(minAge: Int, maxAge: Int)
18
Copyright © 2013 Akira Koyasu. Some rights reserved.
Functional
Programming
age==20
35<=age, age<=60
age<30, gender:Male
def send(age: Int)
def send(minAge: Int, maxAge: Int)
18
Copyright © 2013 Akira Koyasu. Some rights reserved.
Functional
Programming
age==20
35<=age, age<=60
age<30, gender:Male
def send(age: Int)
def send(minAge: Int, maxAge: Int)
def send(minAge: Int, maxAge: Int, g: Gender)
18
Copyright © 2013 Akira Koyasu. Some rights reserved.
Functional
Programming
age==20
35<=age, age<=60
age<30, gender:Male
gender:Female, in Tokyo
def send(age: Int)
def send(minAge: Int, maxAge: Int)
def send(minAge: Int, maxAge: Int, g: Gender)
18
Copyright © 2013 Akira Koyasu. Some rights reserved.
Functional
Programming
age==20
35<=age, age<=60
age<30, gender:Male
gender:Female, in Tokyo
def send(age: Int)
def send(minAge: Int, maxAge: Int)
def send(minAge: Int, maxAge: Int, g: Gender)
def send(minAge: Int, maxAge: Int, g: Gender, pref: String)
18
Copyright © 2013 Akira Koyasu. Some rights reserved.
Functional
Programming
def send(p: Contact => Boolean) {
for(c: Contact <- listing()) {
if (p(c)) mail(c)
}
}
Apply condition function to method
19
Copyright © 2013 Akira Koyasu. Some rights reserved.
Functional
Programming
y = f(x)
Avoiding side effects
Conscious of immutability
20
Copyright © 2013 Akira Koyasu. Some rights reserved.
Partially applied
Function
21
def sum(a: Int, b: Int, c: Int) = a + b + c
val f1 = sum _
val f2 = sum(1, _: Int, 3)
def main(args: Array[String]) {
println(f1(1, 2, 3)) // 6
println(f2(2)) // 6
println(f2(5)) // 9
}
Copyright © 2013 Akira Koyasu. Some rights reserved.
Curried Function
22
def sum(a: Int)(b: Int) = a + b
def main(args: Array[String]) {
println(sum(1)(2)) // 3
}
Copyright © 2013 Akira Koyasu. Some rights reserved.
Curried Function
23
def withResource(r: Closeable)(op: => Unit) {
try {
op
} finally {
r.close()
}
}
	 	 	
def main(args: Array[String]) {
val writer = new FileWriter("test.txt")
withResource(writer) {
writer.write("foo bar")
}
}
Copyright © 2013 Akira Koyasu. Some rights reserved.
Trait
a special form of an abstract class
which can be used as mixins
24
Copyright © 2013 Akira Koyasu. Some rights reserved.
Trait
25
to enrich interface
class MyInt(val n: Int) extends Ordered[MyInt] {
def compare(that: MyInt)
= this.n - that.n
}
val n1 = new MyInt(1)
val n2 = new MyInt(2)
println(n1 < n2)
println(n1 > n2)
println(n1 <= n2)
println(n1 >= n2)
Copyright © 2013 Akira Koyasu. Some rights reserved.
Trait
26
stackable modifications
abstract class Sale {
def price(): Double
}
class BasicSale extends Sale {
def price() = 100;
}
trait OffTenPercent extends Sale {
abstract override
def price() = { super.price.toDouble * 0.9 }
}
trait OffTwenty extends Sale {
abstract override
def price() = { super.price - 20 }
}
-10%
-¥20
¥100
Copyright © 2013 Akira Koyasu. Some rights reserved.
Trait
27
stackable modifications
class UnbelievableSale
extends BasicSale with OffTenPercent
class UnbelievableSale2
extends BasicSale with OffTwenty
class UnbelievableSale3
extends BasicSale with OffTenPercent with OffTwenty
class UnbelievableSale4
extends BasicSale with OffTwenty with OffTenPercent
def main(args: Array[String]) {
println((new BasicSale).price) // 100.0
println((new UnbelievableSale).price) // 90.0
println((new UnbelievableSale2).price) // 80.0
println((new UnbelievableSale3).price) // 70.0
println((new UnbelievableSale4).price) // 72.0
}
-10%
-¥20
-10%, -¥20
-¥20, -10%
Copyright © 2013 Akira Koyasu. Some rights reserved.
Pattern Match
28
case class ScalaCase(name: String)
def test(x: Any) = x match {
case 1 => println("1")
case str: String => println(str)
case ScalaCase(name) => println("name: " + name)
case _ => println("other")
}
def main(args: Array[String]) {
test(1) // 1
test("Hello!") // Hello!
test(ScalaCase("apple")) // name: apple
test(2.5) // other
}
Copyright © 2013 Akira Koyasu. Some rights reserved.29
Scala in Action
Copyright © 2013 Akira Koyasu. Some rights reserved.
Collection
Operation
31
getting the highest score in 2013
case class Student(year: Int, score: Int)
def students(): List[Student] =
List(Student(2013, 92), Student(2012, 98), Student(2013, 70))
def students2(): List[Student] =
Student(2013, 92)::Student(2012, 98)::Student(2013, 70)::Nil
def highestScoreIn2013() = students()
.filter(s => s.year == 2013)
.map(s => s.score)
.foldLeft(0)((a, b) => max(a, b))
Copyright © 2013 Akira Koyasu. Some rights reserved.
Actor
32
actor
A
actor
B
actor
C
actor
D
No shared data
Exchanging messages
Concurrency model
Copyright © 2013 Akira Koyasu. Some rights reserved.
Actor (Akka)
33
object Actors {
implicit val system = ActorSystem("MySystem")
val a, b = actor(new Act {
become {
case ("ping", actor: ActorRef) => {
println("received ping")
Thread.sleep(1000)
actor ! ("pong", self)
}
case ("pong", actor: ActorRef) => {
println("received pong")
Thread.sleep(1000)
actor ! ("ping", self)
}
}
})
def main(args: Array[String]) {
a ! ("ping", b)
}
}
received ping
received pong
received ping
received pong
received ping
received pong
...
Copyright © 2013 Akira Koyasu. Some rights reserved.
Practical Scala
34
Copyright © 2013 Akira Koyasu. Some rights reserved.
Practical Scala
Killer framework Play (+)
Java on the bench (+)
Interactive shell (+)
There are many concepts (-)
the compiler needs more resources (-)
Backward compatibility? (-)
34
Copyright © 2013 Akira Koyasu. Some rights reserved.
Next Step
Implicit conversions
Extractor
Abstract type
Type parameter & variance
35
Copyright © 2013 Akira Koyasu. Some rights reserved.
Reference
An Overview of the Scala Programming
Language Second Edition (pdf)
A Scala Tutorial for Java programmers (pdf)
Programming in Scala, Second Edition
(Japanese version: Scala スケーラブルプロ
グラミング 第2版)
36
Copyright © 2013 Akira Koyasu. Some rights reserved.
Notes
This work is licensed under the Creative Commons Attribution-
NonCommercial 3.0 Unported License. To view a copy of this
license, visit http://creativecommons.org/licenses/by-nc/3.0/.
37
photo#1: http://en.wikipedia.org/wiki/File:Mark_Odersky_photo_by_Linda_Poeng.jpg
Feed backs Welcome!
http://twitter.com/akirakoyasu
http://fb.me/akirakoyasu
Thank you!

More Related Content

What's hot

JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
JDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation streamJDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation stream
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation streamRuslan Shevchenko
 
Scala introduction
Scala introductionScala introduction
Scala introductionvito jeng
 
Functional Programming In Java
Functional Programming In JavaFunctional Programming In Java
Functional Programming In JavaAndrei Solntsev
 
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
 
Should I Use Scalding or Scoobi or Scrunch?
Should I Use Scalding or Scoobi or Scrunch? Should I Use Scalding or Scoobi or Scrunch?
Should I Use Scalding or Scoobi or Scrunch? DataWorks Summit
 
awesome groovy
awesome groovyawesome groovy
awesome groovyPaul King
 
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
 
Intro to Functional Programming in Scala
Intro to Functional Programming in ScalaIntro to Functional Programming in Scala
Intro to Functional Programming in ScalaShai Yallin
 
Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: NotesRoberto Casadei
 
Introduction to Scalding and Monoids
Introduction to Scalding and MonoidsIntroduction to Scalding and Monoids
Introduction to Scalding and MonoidsHugo Gävert
 
Spark Schema For Free with David Szakallas
 Spark Schema For Free with David Szakallas Spark Schema For Free with David Szakallas
Spark Schema For Free with David SzakallasDatabricks
 

What's hot (20)

JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
JDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation streamJDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation stream
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
 
Scala
ScalaScala
Scala
 
Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Polyglot Grails
Polyglot GrailsPolyglot Grails
Polyglot Grails
 
Scala vs java 8
Scala vs java 8Scala vs java 8
Scala vs java 8
 
Scala - brief intro
Scala - brief introScala - brief intro
Scala - brief intro
 
Functional programming in java
Functional programming in javaFunctional programming in java
Functional programming in java
 
Functional Programming In Java
Functional Programming In JavaFunctional Programming In Java
Functional Programming In Java
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
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,
 
Should I Use Scalding or Scoobi or Scrunch?
Should I Use Scalding or Scoobi or Scrunch? Should I Use Scalding or Scoobi or Scrunch?
Should I Use Scalding or Scoobi or Scrunch?
 
awesome groovy
awesome groovyawesome groovy
awesome groovy
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 
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?
 
Groovy intro for OUDL
Groovy intro for OUDLGroovy intro for OUDL
Groovy intro for OUDL
 
Intro to Functional Programming in Scala
Intro to Functional Programming in ScalaIntro to Functional Programming in Scala
Intro to Functional Programming in Scala
 
Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: Notes
 
Introduction to Scalding and Monoids
Introduction to Scalding and MonoidsIntroduction to Scalding and Monoids
Introduction to Scalding and Monoids
 
Spark Schema For Free with David Szakallas
 Spark Schema For Free with David Szakallas Spark Schema For Free with David Szakallas
Spark Schema For Free with David Szakallas
 

Viewers also liked

Garbage Collection for Dummies
Garbage Collection for DummiesGarbage Collection for Dummies
Garbage Collection for Dummies輝 子安
 
Java, Moving Forward
Java, Moving ForwardJava, Moving Forward
Java, Moving Forward輝 子安
 
Java, Up to Date
Java, Up to DateJava, Up to Date
Java, Up to Date輝 子安
 
Tricks and Tips With NIO Using the Grizzly Framework
Tricks and Tips With NIO Using the Grizzly FrameworkTricks and Tips With NIO Using the Grizzly Framework
Tricks and Tips With NIO Using the Grizzly Frameworkelliando dias
 
Concurrency in Scala - the Akka way
Concurrency in Scala - the Akka wayConcurrency in Scala - the Akka way
Concurrency in Scala - the Akka wayYardena Meymann
 
Akka -- Scalability in Scala and Java
Akka -- Scalability in Scala and JavaAkka -- Scalability in Scala and Java
Akka -- Scalability in Scala and JavaNadav Wiener
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at TwitterAlex Payne
 
Comparing JVM Web Frameworks - Devoxx France 2013
Comparing JVM Web Frameworks - Devoxx France 2013Comparing JVM Web Frameworks - Devoxx France 2013
Comparing JVM Web Frameworks - Devoxx France 2013Matt Raible
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaYevgeniy Brikman
 
Above the clouds: introducing Akka
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akkanartamonov
 

Viewers also liked (12)

Garbage Collection for Dummies
Garbage Collection for DummiesGarbage Collection for Dummies
Garbage Collection for Dummies
 
Java, Moving Forward
Java, Moving ForwardJava, Moving Forward
Java, Moving Forward
 
Grizzly1.9.3x
Grizzly1.9.3xGrizzly1.9.3x
Grizzly1.9.3x
 
Java, Up to Date
Java, Up to DateJava, Up to Date
Java, Up to Date
 
Tricks and Tips With NIO Using the Grizzly Framework
Tricks and Tips With NIO Using the Grizzly FrameworkTricks and Tips With NIO Using the Grizzly Framework
Tricks and Tips With NIO Using the Grizzly Framework
 
Concurrency in Scala - the Akka way
Concurrency in Scala - the Akka wayConcurrency in Scala - the Akka way
Concurrency in Scala - the Akka way
 
Akka -- Scalability in Scala and Java
Akka -- Scalability in Scala and JavaAkka -- Scalability in Scala and Java
Akka -- Scalability in Scala and Java
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
Comparing JVM Web Frameworks - Devoxx France 2013
Comparing JVM Web Frameworks - Devoxx France 2013Comparing JVM Web Frameworks - Devoxx France 2013
Comparing JVM Web Frameworks - Devoxx France 2013
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
 
Event-sourced architectures with Akka
Event-sourced architectures with AkkaEvent-sourced architectures with Akka
Event-sourced architectures with Akka
 
Above the clouds: introducing Akka
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akka
 

Similar to Scala for Java Programmers Guide to Features and Benefits

Scala is java8.next()
Scala is java8.next()Scala is java8.next()
Scala is java8.next()daewon jeong
 
FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondFP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondMario Fusco
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Wsloffenauer
 
Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017Sunghyouk Bae
 
6 Programming Languages under investigation
6 Programming Languages under investigation6 Programming Languages under investigation
6 Programming Languages under investigationHosam Aly
 
Reactive cocoa
Reactive cocoaReactive cocoa
Reactive cocoagillygize
 
Introduction to Oracle Groovy
Introduction to Oracle GroovyIntroduction to Oracle Groovy
Introduction to Oracle GroovyDeepak Bhagat
 
From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019Leonardo Borges
 
Dart structured web apps
Dart   structured web appsDart   structured web apps
Dart structured web appschrisbuckett
 
TechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
TechkTalk #12 Grokking: Writing code that writes code – Nguyen LuongTechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
TechkTalk #12 Grokking: Writing code that writes code – Nguyen LuongGrokking VN
 
Writing code that writes code - Nguyen Luong
Writing code that writes code - Nguyen LuongWriting code that writes code - Nguyen Luong
Writing code that writes code - Nguyen LuongVu Huy
 
Introduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demoIntroduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demoMuhammad Abdullah
 
Dart, unicorns and rainbows
Dart, unicorns and rainbowsDart, unicorns and rainbows
Dart, unicorns and rainbowschrisbuckett
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalMichael Stal
 

Similar to Scala for Java Programmers Guide to Features and Benefits (20)

Scala in a nutshell by venkat
Scala in a nutshell by venkatScala in a nutshell by venkat
Scala in a nutshell by venkat
 
Scala is java8.next()
Scala is java8.next()Scala is java8.next()
Scala is java8.next()
 
FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondFP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyond
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
 
Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017
 
6 Programming Languages under investigation
6 Programming Languages under investigation6 Programming Languages under investigation
6 Programming Languages under investigation
 
Reactive cocoa
Reactive cocoaReactive cocoa
Reactive cocoa
 
Introduction to Oracle Groovy
Introduction to Oracle GroovyIntroduction to Oracle Groovy
Introduction to Oracle Groovy
 
Workshop Scala
Workshop ScalaWorkshop Scala
Workshop Scala
 
Scala - en bedre Java?
Scala - en bedre Java?Scala - en bedre Java?
Scala - en bedre Java?
 
Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...
Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...
Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...
 
From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019
 
Dart structured web apps
Dart   structured web appsDart   structured web apps
Dart structured web apps
 
TechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
TechkTalk #12 Grokking: Writing code that writes code – Nguyen LuongTechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
TechkTalk #12 Grokking: Writing code that writes code – Nguyen Luong
 
Writing code that writes code - Nguyen Luong
Writing code that writes code - Nguyen LuongWriting code that writes code - Nguyen Luong
Writing code that writes code - Nguyen Luong
 
Introduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demoIntroduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demo
 
Dart, unicorns and rainbows
Dart, unicorns and rainbowsDart, unicorns and rainbows
Dart, unicorns and rainbows
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation Stal
 
C++ theory
C++ theoryC++ theory
C++ theory
 

More from 輝 子安

Protractor under the hood
Protractor under the hoodProtractor under the hood
Protractor under the hood輝 子安
 
そろそろLambda(CI/CD編)
そろそろLambda(CI/CD編)そろそろLambda(CI/CD編)
そろそろLambda(CI/CD編)輝 子安
 
Dockerで構成するWebサービス 〜EmotionTechの場合〜
Dockerで構成するWebサービス 〜EmotionTechの場合〜Dockerで構成するWebサービス 〜EmotionTechの場合〜
Dockerで構成するWebサービス 〜EmotionTechの場合〜輝 子安
 
Workshop: Docker on Elastic Beanstalk
Workshop: Docker on Elastic BeanstalkWorkshop: Docker on Elastic Beanstalk
Workshop: Docker on Elastic Beanstalk輝 子安
 
PHP conference 2013 ja report
PHP conference 2013 ja reportPHP conference 2013 ja report
PHP conference 2013 ja report輝 子安
 
JavaOne Guide for the Petite Bourgeoisie
JavaOne Guide for the Petite BourgeoisieJavaOne Guide for the Petite Bourgeoisie
JavaOne Guide for the Petite Bourgeoisie輝 子安
 
Java, Up to Date Sources
Java, Up to Date SourcesJava, Up to Date Sources
Java, Up to Date Sources輝 子安
 
Hello, Guava ! samples
Hello, Guava ! samplesHello, Guava ! samples
Hello, Guava ! samples輝 子安
 
Tokyo Cabinet & Tokyo Tyrant
Tokyo Cabinet & Tokyo TyrantTokyo Cabinet & Tokyo Tyrant
Tokyo Cabinet & Tokyo Tyrant輝 子安
 

More from 輝 子安 (9)

Protractor under the hood
Protractor under the hoodProtractor under the hood
Protractor under the hood
 
そろそろLambda(CI/CD編)
そろそろLambda(CI/CD編)そろそろLambda(CI/CD編)
そろそろLambda(CI/CD編)
 
Dockerで構成するWebサービス 〜EmotionTechの場合〜
Dockerで構成するWebサービス 〜EmotionTechの場合〜Dockerで構成するWebサービス 〜EmotionTechの場合〜
Dockerで構成するWebサービス 〜EmotionTechの場合〜
 
Workshop: Docker on Elastic Beanstalk
Workshop: Docker on Elastic BeanstalkWorkshop: Docker on Elastic Beanstalk
Workshop: Docker on Elastic Beanstalk
 
PHP conference 2013 ja report
PHP conference 2013 ja reportPHP conference 2013 ja report
PHP conference 2013 ja report
 
JavaOne Guide for the Petite Bourgeoisie
JavaOne Guide for the Petite BourgeoisieJavaOne Guide for the Petite Bourgeoisie
JavaOne Guide for the Petite Bourgeoisie
 
Java, Up to Date Sources
Java, Up to Date SourcesJava, Up to Date Sources
Java, Up to Date Sources
 
Hello, Guava ! samples
Hello, Guava ! samplesHello, Guava ! samples
Hello, Guava ! samples
 
Tokyo Cabinet & Tokyo Tyrant
Tokyo Cabinet & Tokyo TyrantTokyo Cabinet & Tokyo Tyrant
Tokyo Cabinet & Tokyo Tyrant
 

Recently uploaded

Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 

Recently uploaded (20)

Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 

Scala for Java Programmers Guide to Features and Benefits

  • 1. Scala f o r J a v a P r o g r a m m e r s
  • 3. Copyright © 2013 Akira Koyasu. Some rights reserved. Hello, World! 3
  • 4. Copyright © 2013 Akira Koyasu. Some rights reserved. Hello, World! object HelloWorld { def main(args: Array[String]) = println("Hello, World!") } 3
  • 5. Copyright © 2013 Akira Koyasu. Some rights reserved. Agenda About Scala Features 4
  • 6. Copyright © 2013 Akira Koyasu. Some rights reserved. Motivation Scalable language. To be scalable in the sense that the same concepts can describe small as well as large parts. A unified and generalized object-oriented and functional programming language provides scalable support. From Inventor 5
  • 7. Copyright © 2013 Akira Koyasu. Some rights reserved. Motivation More productive as “better Java” with existing Java resources. Several concepts not in Java bring more posibilities to you. For Java programmers 6
  • 8. Copyright © 2013 Akira Koyasu. Some rights reserved. the Programming Language Language Specification API Runtime 7
  • 9. Copyright © 2013 Akira Koyasu. Some rights reserved. API 8 Scaladoc
  • 10. Copyright © 2013 Akira Koyasu. Some rights reserved. Runtime scalac .scala .class the compiler for .NET is out of date JVM scala Running on JVM Compiler generates class files 9
  • 11. Copyright © 2013 Akira Koyasu. Some rights reserved. Influencers Java C# Smalltalk Haskell Algol Simula Eiffel SML F# Erlang Iswim Lisp Python Ruby 10
  • 12. Copyright © 2013 Akira Koyasu. Some rights reserved. Inventor Martin Odersky Professor of programming methods at EPFL in Switzerland Designer of Java generics photo#1 11
  • 13. Copyright © 2013 Akira Koyasu. Some rights reserved. Object, Operator val apple = new Apple val orange = new Orange println(apple + orange) ? 12
  • 14. Copyright © 2013 Akira Koyasu. Some rights reserved. Object, Operator val apple = new Apple val orange = new Orange println(apple + orange) ? (A) "Apple@xxxxOrange@xxxx" (B) 2 (C) Compile error (D) Runtime exception (E) Others 12
  • 15. Copyright © 2013 Akira Koyasu. Some rights reserved. Features Static typing & Suitable type inference Object-oriented & Functional Trait Collaborating with Java 13
  • 16. Copyright © 2013 Akira Koyasu. Some rights reserved. Vorbose Java Type declaration public String suffix(String str) { int pos = str.indexOf("-"); return str.substring(pos); } 14
  • 17. Copyright © 2013 Akira Koyasu. Some rights reserved. Vorbose Java Type declaration def suffix(str: String) = { val pos = str.indexOf("-") str.substring(pos) } 14
  • 18. Copyright © 2013 Akira Koyasu. Some rights reserved. Vorbose Java JavaBeans public class JavaBeans { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } } 15
  • 19. Copyright © 2013 Akira Koyasu. Some rights reserved. Vorbose Java JavaBeans case class ScalaCase(name: String) 15
  • 20. Copyright © 2013 Akira Koyasu. Some rights reserved. Functional Programming variables method parameters method returns Functions are the first-class values 16
  • 21. Copyright © 2013 Akira Koyasu. Some rights reserved. Functional Programming Consider a method signature sending mails to appropriate addresses from listing def send() { for(c: Contact <- listing()) { mail(c) } } 17
  • 22. Copyright © 2013 Akira Koyasu. Some rights reserved. Functional Programming 18
  • 23. Copyright © 2013 Akira Koyasu. Some rights reserved. Functional Programming age==20 18
  • 24. Copyright © 2013 Akira Koyasu. Some rights reserved. Functional Programming age==20 def send(age: Int) 18
  • 25. Copyright © 2013 Akira Koyasu. Some rights reserved. Functional Programming age==20 35<=age, age<=60 def send(age: Int) 18
  • 26. Copyright © 2013 Akira Koyasu. Some rights reserved. Functional Programming age==20 35<=age, age<=60 def send(age: Int) def send(minAge: Int, maxAge: Int) 18
  • 27. Copyright © 2013 Akira Koyasu. Some rights reserved. Functional Programming age==20 35<=age, age<=60 age<30, gender:Male def send(age: Int) def send(minAge: Int, maxAge: Int) 18
  • 28. Copyright © 2013 Akira Koyasu. Some rights reserved. Functional Programming age==20 35<=age, age<=60 age<30, gender:Male def send(age: Int) def send(minAge: Int, maxAge: Int) def send(minAge: Int, maxAge: Int, g: Gender) 18
  • 29. Copyright © 2013 Akira Koyasu. Some rights reserved. Functional Programming age==20 35<=age, age<=60 age<30, gender:Male gender:Female, in Tokyo def send(age: Int) def send(minAge: Int, maxAge: Int) def send(minAge: Int, maxAge: Int, g: Gender) 18
  • 30. Copyright © 2013 Akira Koyasu. Some rights reserved. Functional Programming age==20 35<=age, age<=60 age<30, gender:Male gender:Female, in Tokyo def send(age: Int) def send(minAge: Int, maxAge: Int) def send(minAge: Int, maxAge: Int, g: Gender) def send(minAge: Int, maxAge: Int, g: Gender, pref: String) 18
  • 31. Copyright © 2013 Akira Koyasu. Some rights reserved. Functional Programming def send(p: Contact => Boolean) { for(c: Contact <- listing()) { if (p(c)) mail(c) } } Apply condition function to method 19
  • 32. Copyright © 2013 Akira Koyasu. Some rights reserved. Functional Programming y = f(x) Avoiding side effects Conscious of immutability 20
  • 33. Copyright © 2013 Akira Koyasu. Some rights reserved. Partially applied Function 21 def sum(a: Int, b: Int, c: Int) = a + b + c val f1 = sum _ val f2 = sum(1, _: Int, 3) def main(args: Array[String]) { println(f1(1, 2, 3)) // 6 println(f2(2)) // 6 println(f2(5)) // 9 }
  • 34. Copyright © 2013 Akira Koyasu. Some rights reserved. Curried Function 22 def sum(a: Int)(b: Int) = a + b def main(args: Array[String]) { println(sum(1)(2)) // 3 }
  • 35. Copyright © 2013 Akira Koyasu. Some rights reserved. Curried Function 23 def withResource(r: Closeable)(op: => Unit) { try { op } finally { r.close() } } def main(args: Array[String]) { val writer = new FileWriter("test.txt") withResource(writer) { writer.write("foo bar") } }
  • 36. Copyright © 2013 Akira Koyasu. Some rights reserved. Trait a special form of an abstract class which can be used as mixins 24
  • 37. Copyright © 2013 Akira Koyasu. Some rights reserved. Trait 25 to enrich interface class MyInt(val n: Int) extends Ordered[MyInt] { def compare(that: MyInt) = this.n - that.n } val n1 = new MyInt(1) val n2 = new MyInt(2) println(n1 < n2) println(n1 > n2) println(n1 <= n2) println(n1 >= n2)
  • 38. Copyright © 2013 Akira Koyasu. Some rights reserved. Trait 26 stackable modifications abstract class Sale { def price(): Double } class BasicSale extends Sale { def price() = 100; } trait OffTenPercent extends Sale { abstract override def price() = { super.price.toDouble * 0.9 } } trait OffTwenty extends Sale { abstract override def price() = { super.price - 20 } } -10% -¥20 ¥100
  • 39. Copyright © 2013 Akira Koyasu. Some rights reserved. Trait 27 stackable modifications class UnbelievableSale extends BasicSale with OffTenPercent class UnbelievableSale2 extends BasicSale with OffTwenty class UnbelievableSale3 extends BasicSale with OffTenPercent with OffTwenty class UnbelievableSale4 extends BasicSale with OffTwenty with OffTenPercent def main(args: Array[String]) { println((new BasicSale).price) // 100.0 println((new UnbelievableSale).price) // 90.0 println((new UnbelievableSale2).price) // 80.0 println((new UnbelievableSale3).price) // 70.0 println((new UnbelievableSale4).price) // 72.0 } -10% -¥20 -10%, -¥20 -¥20, -10%
  • 40. Copyright © 2013 Akira Koyasu. Some rights reserved. Pattern Match 28 case class ScalaCase(name: String) def test(x: Any) = x match { case 1 => println("1") case str: String => println(str) case ScalaCase(name) => println("name: " + name) case _ => println("other") } def main(args: Array[String]) { test(1) // 1 test("Hello!") // Hello! test(ScalaCase("apple")) // name: apple test(2.5) // other }
  • 41. Copyright © 2013 Akira Koyasu. Some rights reserved.29
  • 43. Copyright © 2013 Akira Koyasu. Some rights reserved. Collection Operation 31 getting the highest score in 2013 case class Student(year: Int, score: Int) def students(): List[Student] = List(Student(2013, 92), Student(2012, 98), Student(2013, 70)) def students2(): List[Student] = Student(2013, 92)::Student(2012, 98)::Student(2013, 70)::Nil def highestScoreIn2013() = students() .filter(s => s.year == 2013) .map(s => s.score) .foldLeft(0)((a, b) => max(a, b))
  • 44. Copyright © 2013 Akira Koyasu. Some rights reserved. Actor 32 actor A actor B actor C actor D No shared data Exchanging messages Concurrency model
  • 45. Copyright © 2013 Akira Koyasu. Some rights reserved. Actor (Akka) 33 object Actors { implicit val system = ActorSystem("MySystem") val a, b = actor(new Act { become { case ("ping", actor: ActorRef) => { println("received ping") Thread.sleep(1000) actor ! ("pong", self) } case ("pong", actor: ActorRef) => { println("received pong") Thread.sleep(1000) actor ! ("ping", self) } } }) def main(args: Array[String]) { a ! ("ping", b) } } received ping received pong received ping received pong received ping received pong ...
  • 46. Copyright © 2013 Akira Koyasu. Some rights reserved. Practical Scala 34
  • 47. Copyright © 2013 Akira Koyasu. Some rights reserved. Practical Scala Killer framework Play (+) Java on the bench (+) Interactive shell (+) There are many concepts (-) the compiler needs more resources (-) Backward compatibility? (-) 34
  • 48. Copyright © 2013 Akira Koyasu. Some rights reserved. Next Step Implicit conversions Extractor Abstract type Type parameter & variance 35
  • 49. Copyright © 2013 Akira Koyasu. Some rights reserved. Reference An Overview of the Scala Programming Language Second Edition (pdf) A Scala Tutorial for Java programmers (pdf) Programming in Scala, Second Edition (Japanese version: Scala スケーラブルプロ グラミング 第2版) 36
  • 50. Copyright © 2013 Akira Koyasu. Some rights reserved. Notes This work is licensed under the Creative Commons Attribution- NonCommercial 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/3.0/. 37 photo#1: http://en.wikipedia.org/wiki/File:Mark_Odersky_photo_by_Linda_Poeng.jpg Feed backs Welcome! http://twitter.com/akirakoyasu http://fb.me/akirakoyasu