Next Generation Java
Ceylon, Kotlin, Scala & Fantom im Überblick

Autor: dogmadic : http://www.sxc.hu/photo/436457
http://www.sxc.hu/photo/36128
Disclaimer

Java

2 | Next Generation JVM Languages
Überblick

3.
3 | Next Generation JVM Languages
Überblick

3.
4 | Next Generation JVM Languages
Ist Java das neue Cobol?

–
–
–
–
–

5 | Next Generation JVM Languages

http://www.sxc.hu/photo/1389360
Ein BLick auf die .NET Plattform

l
l

l

–
–
–
–
–
–
–

6 | Next Generation JVM Languages
The JVM at a glance

l
l

l

–
–
–
–
–
–
–

7 | Next Generation JVM Languages
Das Java- Universum
8 | Next Generation JVM Languages
Überblick

3.
9 | Next Generation JVM Languages
Warum neue JVM Sprachen?

10 | Next Generation JVM Languages
Beginning Buzz-Word Bingo….

11 | Next Generation JVM Languages

http://www.sxc.hu/photo/377913
Warum neue JVM Sprachen?

12 | Next Generation JVM Languages
Von Lambdas und „1. Klasse“-Rechnen

13 | Next Generation JVM Languages
Imperativ vs. Funktional: Beispiel #1 Quicksort
public void quicksort(int array[]) {
quicksort(array, 0, array.length - 1);
}
public void quicksort(int array[], int start, int end){
int i = start;
int k = end;
if (end - start >= 1) {
int pivot = array[start];
while (k > i) {
while (array[i] <= pivot && i <= end && k > i) i++;
while (array[k] > pivot && k >= start && k >= i) k--;
if (k > i) swap(array, i, k);
}
swap(array, start, k);
quicksort(array, start, k - 1);
quicksort(array, k + 1, end);
} else {
return;
}
}
public void swap(int array[], int index1, int index2) {
int temp = array[index1];
array[index1] = array[index2];
array[index2] = temp;
}

14 | Next Generation JVM Languages
Imperativ vs. Funktional: Beispiel #1 Quicksort
public void quicksort(int array[]) {
quicksort(array, 0, array.length - 1);
}
public void quicksort(int array[], int start, int end){
int i = start;
int k = end;
if (end - start >= 1) {
int pivot = array[start];
while (k > i) {
while (array[i] <= pivot && i <= end && k > i) i++;
while (array[k] > pivot && k >= start && k >= i) k--;
if (k > i) swap(array, i, k);
}
swap(array, start, k);
quicksort(array, start, k - 1);
quicksort(array, k + 1, end);
} else {
return;
}
}
public void swap(int array[], int index1, int index2) {
int temp = array[index1];
array[index1] = array[index2];
array[index2] = temp;
}

15 | Next Generation JVM Languages
Imperativ vs. Funktional: Beispiel #2
int sum = 0;
for (int i = 0; i < 150; i++)
{
if (i % 5 != 0)
sum += i;
}

int sum = Enumerable.Range(0, 150).Where(i => i % 5 != 0).Sum();
f1(

16 | Next Generation JVM Languages

f2(

f3(

f4())))
Objektorientierte vs. Funktionale Programmierung

FP
Sammlung von Funktionen
Zustandlos & Unveränderlich
Rekursiv
Auswertung: Lazy
17 | Next Generation JVM Languages

OOP
Sammlung von Objekten
Zustandsbehaftet
Iterativ
Imperativer Ablauf
Warum neue JVM Sprachen?

18 | Next Generation JVM Languages
Dynamic Typing

Parsen und
Auflisten der Daten
19 | Next Generation JVM Languages

Practically Groovy: Building, parsing, and slurping XML
http://www.ibm.com/developerworks/java/library/j-pg05199/
Dynamic Typing
import
import
import
import

org.xml.sax.SAXException;
org.w3c.dom.*;
javax.xml.parsers.*;
java.io.IOException;

public class ParseXml {
public static void main(String[] args) {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse("src/languages.xml");
//print the "type" attribute
Element langs = doc.getDocumentElement();
System.out.println("type = " + langs.getAttribute("type"));
//print the "language" elements
NodeList list = langs.getElementsByTagName("language");
for(int i = 0 ; i < list.getLength();i++) {
Element language = (Element) list.item(i);
System.out.println(language.getTextContent());
}
}catch(ParserConfigurationException pce) {
pce.printStackTrace();
}catch(SAXException se) {
se.printStackTrace();
}catch(IOException ioe) {
ioe.printStackTrace();
}
}
}
20 | Next Generation JVM Languages

Parsen und
Auflisten der
Daten
Practically Groovy: Building, parsing, and slurping XML
http://www.ibm.com/developerworks/java/library/j-pg05199/
Dynamic Typing

def langs = new XmlParser().parse("languages.xml")
println "type = ${langs.attribute("type")}"
langs.language.each{
println it.text()
}

Parsen und
Auflisten der
Daten
21 | Next Generation JVM Languages

Practically Groovy: Building, parsing, and slurping XML
http://www.ibm.com/developerworks/java/library/j-pg05199/
Warum neue JVM Sprachen?

22 | Next Generation JVM Languages
Schlankere Syntax : Listen befüllen
List<String> languages = new LinkedList<String>();
languages.add("Java");
languages.add("Ruby");
languages.add("Python");
languages.add("Perl");

stuff = []
stuff << "Java", "Ruby", "Python"

23 | Next Generation JVM Languages

Practically Groovy: Building, parsing, and slurping XML
http://www.ibm.com/developerworks/java/library/j-pg05199/
Schlankere Syntax : Getter/Setter
Class Circle
private Coordinate center, float radius;
public void setCenter(Coordinate center){
this.center = center;
}
public Coordinate getCenter(){
return center;
}
public void setRadius(float radius){
this.radius = radius;
}
public Coordinate getRadius(){
return radius;
}
}

class Circle
attr_accessor :center, :radius
end

24 | Next Generation JVM Languages

Practically Groovy: Building, parsing, and slurping XML
http://www.ibm.com/developerworks/java/library/j-pg05199/
Warum neue JVM Sprachen?

25 | Next Generation JVM Languages
Warum neue JVM Sprachen?

26 | Next Generation JVM Languages
java.lang.NullPointerException
at
at
at
at
at
at
at
at
at
at

com.sun.tools.javac.comp.Check.checkCompatibleConcretes(Check.java:1141)
com.sun.tools.javac.comp.Check.checkCompatibleSupertypes(Check.java:1495)
com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:2451)
com.sun.tools.javac.comp.Attr.attribClass(Attr.java:2406)
com.sun.tools.javac.comp.Attr.attribClass(Attr.java:2355)
com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:444)
com.sun.tools.javac.main.Main.compile(Main.java:592)
com.sun.tools.javac.main.Main.compile(Main.java:544)
com.sun.tools.javac.Main.compile(Main.java:67)
com.sun.tools.javac.Main.main(Main.java:52)

27 | Next Generation JVM Languages
Die Null zügeln

l

l

28 | Next Generation JVM Languages
Warum neue JVM Sprachen?

29 | Next Generation JVM Languages
Domain Specific Languages

l

30 | Next Generation JVM Languages
Warum neue JVM Sprachen?

31 | Next Generation JVM Languages
Warum neue JVM Sprachen?

32 | Next Generation JVM Languages
33 | Next Generation JVM Languages
Alternativen zur Threads & Co.

l

–

–
–
l

–
–

34 | Next Generation JVM Languages

http://www.sxc.hu/photo/515995
Warum neue JVM Sprachen?

35 | Next Generation JVM Languages
Warum neue JVM Sprachen?

36 | Next Generation JVM Languages
Scripting

l

l

–

–
–
–

37 | Next Generation JVM Languages
Warum neue JVM Sprachen?

38 | Next Generation JVM Languages
Meta-Programmierung
Programmen, die sich oder andere P. als Daten behandeln und verändert.

l

–
–
–

l
l

–
–

39 | Next Generation JVM Languages
Warum neue JVM Sprachen?

40 | Next Generation JVM Languages
Dynamic & Weak Typing

l
“A programming language is said to be dynamically typed when the majority
of its type checking is performed at run-time as opposed to at compile-time.
In dynamic typing values have types, but variables do not […]”
https://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing

l
[…] strong typing when it specifies one or more restrictions on how operations
involving values of different data types can be intermixed.
Weak typing means that a language implicitly converts (or casts) types when used.
https://en.wikipedia.org/wiki/Dynamic_typing#Dynamic_typing

41 | Next Generation JVM Languages
Warum neue JVM Sprachen?

42 | Next Generation JVM Languages
Überblick

3.
43 | Next Generation JVM Languages
Auszug neuer JVM Sprachen

Inzwischen über 50-250 verschiedene Sprachen auf der JVM…
44 | Next Generation JVM Languages
Anforderungen für den Industriellen Einsatz

–
–

–
–
45 | Next Generation JVM Languages
Sprachen im industriellen Einsatz

[...] programming by larger groups of people or by smaller groups over
longer time periods [...] result in large, and hence complicated, programs
[...] place emphasis on partitioning work into modules with preciselyspecified interactions.
http://en.wikipedia.org/wiki/Programming_in_the_large_and_programming_in_the_small

–
–

46 | Next Generation JVM Languages
Auszug neuer JVM Sprachen

47 | Next Generation JVM Languages
Übersicht & Entwicklung JVM Sprachen

48 | Next Generation JVM Languages
Statisch-typisierte JVM Sprachen im Überblick

49 | Next Generation JVM Languages
50 | Next Generation JVM Languages

http://www.flickr.com/photos/tonino62/2295302323/

.
Scala im Portrait

l

–

51 | Next Generation JVM Languages
Scala im Portrait

l
l

–
–
–

52 | Next Generation JVM Languages
Traits & Mixins

trait Similarity {
def isSimilar(x: Any): Boolean
def isNotSimilar(x: Any): Boolean = !isSimilar(x)
}

53 | Next Generation JVM Languages
Extension Methods

l
l
54 | Next Generation JVM Languages
TL;DR
Too long; didn‘t read

Scala & Ko-/Kontravarianz
55 | Next Generation JVM Languages

http://www.sxc.hu/photo/330223
Scala im Portrait

l
l

l

–
–
–
–
–

56 | Next Generation JVM Languages
Scala - Implicit Conversion

object A {
implicit def aToB(a: A) : B = {
new B()
}
}

57 | Next Generation JVM Languages

object MainClass {
def main(args: Array[String]) {
val b : B = new A()
}
}
58 | Next Generation JVM Languages
Pattern Matching = Switch/Instanceof++

59 | Next Generation JVM Languages
Beherrschbarkeit?
http://bit.ly/LP2Spb

60 | Next Generation JVM Languages
Erfahrungen

l

–
–
–

l

–
–
–

61 | Next Generation JVM Languages
Erfahrungen

l

l

–
–
–
–
–

62 | Next Generation JVM Languages
JVM Sprachen im Überblick (Features)










































63 | Next Generation JVM Languages





















Scala Summary

l

–
–

l
l

–
–
–

64 | Next Generation JVM Languages
Fantom

65 | Next Generation JVM Languages

http://www.sxc.hu/photo/366158
Fantom : Portabilität

l
„one portable system, graphics, and widget library
that just works everywhere”

l
–
–
–

66 | Next Generation JVM Languages
Fantom im Portrait

l

l

l

–
–
–
–
–
–
–
–

67 | Next Generation JVM Languages
Fantom : Quadratur der Kreise

l
l
l
obj.methode()
obj->methode()

l
l

68 | Next Generation JVM Languages
Fantom : Multi-Threading

–
–
–

69 | Next Generation JVM Languages
Fantom : Elegante APIs und Sprache

–
–
–
–
–
–
–
–
70 | Next Generation JVM Languages
Fantom Hello World (Webapp)
using util
using web
using wisp
class WebHello : AbstractMain
{
@Opt { help = "http port" }
Int port := 8080
override Int run()
{
wisp := WispService
{
it.port = this.port
it.root = HelloMod()
}
return runServices([wisp])
}
}

71 | Next Generation JVM Languages

const class HelloMod : WebMod
{
override Void onGet()
{
res.headers["Content-Type"] =
"text/plain; charset=utf-8"
res.out.print("hello world #4")
}
}
Fantom: Summary

l

–
–
–

l
l

–
–
–

72 | Next Generation JVM Languages
JVM Sprachen im Überblick (Features)










































73 | Next Generation JVM Languages





















http://bit.ly/LKM5YG

74 | Next Generation JVM Languages
Ceylon im Portrait
„Ceylon’s goal is to design the language that Java would have been
if its designers had been able to predict the future.”

–
–
–
–
–

75 | Next Generation JVM Languages
Ceylon: Code Example
doc "A component"
shared abstract class Component() {
OpenList<Callable<Void,Event>> observers =
OpenList<Callable<Void,Event>>();
shared void addObserver(void observe(Event event)) {
observers.append(observe);
}
shared void fire(Event event) {
for (void observe(Event event) in observers) {
observe(event);
}
}
}

76 | Next Generation JVM Languages
…bisschen Spannendes hat Ceylon aber schon…

l
l
l
77 | Next Generation JVM Languages

http://www.sxc.hu/photo/732192
Nullables

78 | Next Generation JVM Languages
Von Typen mit und ohne Charakter

79 | Next Generation JVM Languages
Ceylon: Summary

l
l

–
–
–
–
–
–

80 | Next Generation JVM Languages
JVM Sprachen im Überblick (Features)










































81 | Next Generation JVM Languages





















82 | Next Generation JVM Languages

http://www.sxc.hu/photo/1339625
Kotlin im Portrait
“General-purpose language intended for industrial use”
Kotlin = Java++ bzw. Scala--

l

–
–
–
–
–

83 | Next Generation JVM Languages
Kotlin Motivation & Hintergrund

“Although we’ve developed support for several JVM-targeted programming languages,
we are still writing all of our IntelliJ-based IDEs almost entirely in Java.
We want to become more productive by switching to a more expressive language.”

l

–
–
–
–

84 | Next Generation JVM Languages
85 | Next Generation JVM Languages
Kotlin Sprach-Features

–
–

86 | Next Generation JVM Languages
Kotlin Sprach-Features

l
l
interface Collection<E> ... {
void addAll(Collection<? extends E> items);
}

abstract class Source<out T> {
fun nextT() : T
}
fun fill(dest : Array<in String>, value : String) {
// ...
}
87 | Next Generation JVM Languages
Kotlin Sprach-Features

l
l
l
l
l
l
l

88 | Next Generation JVM Languages
Kotlin: Online Demo

89 | Next Generation JVM Languages
Kotlin Summary:

l
l
l
l
l
l

90 | Next Generation JVM Languages
JVM Sprachen im Überblick (Features)










































91 | Next Generation JVM Languages





















Überblick

3.
92 | Next Generation JVM Languages
Blick über den Tellerrand

93 | Next Generation JVM Languages

http://www.sxc.hu/photo/1167119/
Resumee

94 | Next Generation JVM Languages

http://www.sxc.hu/photo/1022369
Anforderungen für den Industriellen Einsatz

–
–

–
–
95 | Next Generation JVM Languages
Wertung JVM Sprachen für den Industrie-Einsatz















































96 | Next Generation JVM Languages















Resumée

l
l
l
l

–
–

–

l
l
l

97 | Next Generation JVM Languages
Resumée

98 | Next Generation JVM Languages
Weiterführende Information
Benjamin.Schmid@exxcellent.de
Scala: http://www.scala-lang.org/
Ceylon: http://ceylon-lang.org/
Kotlin: http://blog.jetbrains.com/kotlin/
Kotlin Demo: http://kotlin-demo.jetbrains.com/
Fantom vs. Kotlin http://fantom.org/sidewalk/topic/1581
99 | Next Generation JVM Languages

Gosu: http://gosu-lang.org/
Search for a better Java:
http://blog.joda.org/2011/07/kotlin-and-search-forbetter-java_9066.html

Autor: woodleywonderworks
http://www.flickr.com/photos/wwworks/4759535950/

Next Generation Java - Ceylon, Kotlin, Scala & Fantom im Überblick