1. Scala coated JVM
@ Joint meeting of Java User Group Scotland
and Scala Scotland
Stuart Roebuck
stuart.roebuck@proinnovate.com
2. The basics…
• Created by Martin Odersky (EPFL)
• JVM
• Object oriented and functional
• ‘scalable language’
• Scala 1.0—late 2003
• Scala 2.8.0—July 2010
3. “If I were to pick a language to
use today other than Java, it
would be Scala”
James Gosling
4. Commercial users of Scala
• Twitter—Scala back end Ruby front end
• LinkedIn
• Foursquare—Scala and Lift
• Siemens—Scala and Lift
• SAP
• EDF
• Sony Pictures (ImageWorks)
• Nature Magazine
• TomTom
• …and Google
5. Try this at home!
• Scala home: http://www.scala-lang.org/
• Downloadable for Mac, Linux & Windows
• Shell interpreter: scala
• Compilers: scalac and fsc
• Documentation generator scaladoc
• Plugins for Eclipse, Netbeans, IntelliJ
• Popular build tool “sbt” (simple-build-tool)
8. How does Scala differ
from Java?
• Everything is an object • Pattern matching and
Extractors
• First-class functions
(‘closures’) • XML literals
• Singleton objects • Case classes
• Mixin composition • Lazy evaluation
with Traits • Tuples
9. Everything is an object
“Answer = ” + 6 * 4
“Answer = ”.+((6).*(4))
10. First class functions
def time(f: => Unit): Double = {
val start = System.nanoTime
f
val end = System.nanoTime
(end - start) / 1000000.0
}
val timeTaken = time {
Thread.sleep(100)
}
11. Singleton Objects (Java)
public class Singleton {
private Singleton() {
}
private static class SingletonHolder {
public static final Singleton INSTANCE = new Singleton();
}
public static Singleton getInstance() {
return SingletonHolder.INSTANCE;
}
}