Presented to the Belfast Java User Group in April 2014 this talk explores if the changes made to Java in version 8 are enough to keep it the dominant programming platform.
6. Some Thoughts from React 2014
Architecture is back in fashion
No more ‘just use the stack’ or ‘wait for speedup’
Design so there is no bottleneck
Be ready for the ‘Internet of Things’
The same lessons apply at different levels
Key concepts:
Actors, Futures, Reactive Extensions (RX)
Eventually consistent data storage
Convergent replicated data types
Coding becomes increasingly declarative
Send code to data and ensure ‘data knows where to go’
14. Only Rockets Will Be Insured
From the late 1950's until the early 1980's, the ownership and operation of
satellites was generally undertaken only by government agencies like National
Aeronautics and Space Administration (NASA) and the European Space
Agency (ESA). While commercial satellite insurance has been available since
1964, very little was purchased until the mid 1980's because government
agencies generally self-insure the risk. Starting in the early 1980's, the
commercial satellite industry began to take off and with it came the increased
need for satellite insurance since commercial enterprises are not ordinarily
willing to self-insure such high valued assets that are subject to relatively high
loss frequencies. Market capacity soared in the 1990's, from around $300
million in 1990 to almost $1.2 billion in 1999, 3 well in excess of the $175 to
$250 million of coverage required for most satellites. Occasionally a satellite
may require as much as $400 million of coverage.
Estimating Satellite Insurance Liabilities
Allen J. Gould and Orin M. Linden
25. The Horsemen of the
Javapocalypse…
Inner
Classes
Non-Reified
Generics
Checked
Exceptions
Value
Types
26. The Road Not Taken…
The newest version of the Microsoft Visual J++ development environment supports a language
construct called delegates or bound method references…
It is unlikely that the Java programming language will ever include this construct. Sun
already carefully considered adopting it in 1996, to the extent of building and discarding
working prototypes. Our conclusion was that bound method references are unnecessary
and detrimental to the language…
We believe bound method references are unnecessary because another design alternative, inner
classes, provides equal or superior functionality. In particular, inner classes fully support the
requirements of user-interface event handling, and have been used to implement a user-interface
API at least as comprehensive as the Windows Foundation Classes.
We believe bound method references are harmful because they detract from the simplicity of the
Java programming language and the pervasively object-oriented character of the APIs….
Extracts From: About Microsoft’s “Delegates"
Whitepaper by the Java language team at JavaSoft
32. Our Industry Has Issues…
The Proposition:
Work till 2 am for 20 years,
hunting bugs fuelled by cold
pizza and warm coke.
The Rewards:
Kudos from peers
Detach from ‘civilian’ life
Grow neckbeard
Present at QCon
35. Agile Values
Feedback cycles
Working as a team
Universal ownership
Sustainable pace
Asking for assistance
Clear prioritization
Retrospectives
No prima-donnas
36. That he which hath no stomach to this fight,
Let him depart; his passport shall be made,
And crowns for convoy put into his purse;
We would not die in that man's company
...
From this day to the ending of the world,
But we in it shall be remembered-
We few, we happy few, we band of brothers;
43. The Solution
Thread 11 just returned after waiting 10 secs
Thread 13 just returned after waiting 14 secs
Thread 1 just returned after waiting 18 secs
Thread 14 just returned after waiting 22 secs
Thread 10 just returned after waiting 26 secs
Thread 12 just returned after waiting 30 secs
44. public class Program {
public static void main(String [] args) {
List<Integer> input = Arrays.asList(30,26,22,18,14,10);
input.stream()
.parallel()
.map(Program::waitAndReturn)
.forEach(System.out::println);
}
…
Thread 1 just returned after waiting 30 secs
Thread 1 just returned after waiting 26 secs
Thread 1 just returned after waiting 22 secs
Thread 1 just returned after waiting 18 secs
Thread 1 just returned after waiting 14 secs
Thread 1 just returned after waiting 10 secs
45. The Functional Toolkit
Lambdas
Method References
Optional Monad
Streams (new style)
And also:
Implementations
allowed in interfaces
New data / time library
46. Lambdas
Supplier<String> ref1 = () -> "Scooby";
Consumer<String> ref2 = s -> System.out.println(s);
Function<String,Integer> ref3 = s -> s.length();
IntToDoubleFunction ref4 = num -> num * 1.0;
Predicate<String> ref5 = s -> s.length() == 5;
UnaryOperator<String> ref6 = s -> s + "wobble";
BinaryOperator<String> ref7 = (s1,s2) -> s1 + s2;
Converter<String,Double> ref8 = s -> Double.parseDouble(s);
@FunctionalInterface
public interface Converter<T,U> {
public U convert(T input);
}
57. The Theoretical Solution
S U P E R
C A L A
I S T I C
F R A G I L
E X P Y
A L I
D O T I O U S
flatMap(String char [ ])
58. The Solution in Scala
object Program {
def main(args : Array[String]) {
val data = Array("super","cala","fragil","istic","expy","ali","dotious")
val result = data.flatMap(_.toCharArray)
for(c <- result) {
printf(" %s", c);
}
}
}
s u p e r c a l a f r a g i l i s t i c e x p y a l i d o t i o u s
60. The Solution in Java (Part 2)
import static java.util.Arrays.*;
public class Program {
public static void main(String [] args) {
String [] data = {"super","cala","fragil","istic","expy","ali","dotious"};
asList(data).flatMap(s -> null);
}
}
61. The Solution in Java (Part 3)
import static java.util.Arrays.*;
public class Program {
public static void main(String [] args) {
String [] data = {"super","cala","fragil","istic","expy","ali","dotious"};
asList(data).stream().flatMap(s -> null);
}
}
62. The Solution in Java (Part 4)
asList(data).stream().flatMap(s -> s.toCharArray());
66. The Solution in Java (Part 5)
Stream<char[]> results = asList(data)
.stream()
.flatMap(s -> stream(s.toCharArray()));
67. The Solution in Java (Part 6)
import java.util.Arrays;
import java.util.stream.Stream;
public class MyUtils {
public static Stream toStream(String input) {
Character[] output = new Character[input.length()];
for (int i = 0; i < input.length(); i++) {
output[i] = input.charAt(i);
}
return Arrays.stream(output);
}
}
68. The Solution in Java (Part 6)
import static java.util.Arrays.asList;
import java.util.stream.Stream;
public class Program {
public static void main(String [] args) {
String [] data = {"super","cala","fragil","istic","expy","ali","dotious"};
Stream<char[]> results = asList(data).stream().flatMap(MyUtils::toStream);
for(Object obj : results.toArray()) {
System.out.printf("%s ",obj);
}
}
}
s u p e r c a l a f r a g i l i s t i c e x p y a l i d o t i o u s
69.
70. Is Java 8 More Complex?
Is NOT about absolute complexity
Its about accidental vs. essential complexity
Scala has higher essential complexity
But all the features ‘hang together’
You don’t have to meet it all at once
71. Is Java 8 More Complex?
Primitive types and boxing
and arrays and collections
and non-reified generics
and var-args and lambdas
and method refs. Oh My!
83. Concluding Thought
Its not about making everything scalable
today. Its about opening the door to making
arbitrary things scalable tomorrow, and
enabling that decision to be transparent to
the user of the service…