Lunch and Learn
Nearly 4 years in the making
Biggest upgrade to the Java programming model ever
Over 50 new features
Goals:
Lambda Expressions & Virtual Extension Methods
Lambda-Form Representation for Method Handles
Leverage CPU Instructions for AES Cryptography
Mechanical Checking of Caller-Sensitive Methods
Document JDK API Support and Stability
Reduce Cache Contention on Specified Fields
Lambda Expressions
Functional Interfaces
Method References
Default Methods
Streams
Type Annotations
Modularisation
Date-Time
Misc
A Lambda is a function; a computation that takes parameters and returns a value.
A method that is implemented inside the interface.
Previously if a method was added to an interface, an old implementation of a class would throw an error.
Default implementation is used for classes that do not provide their own.
Defaults can be overridden by subclasses.
List.sort(Function<T, R>)
// takes an object of type T and returns R.
Iterable.forEach(Consumer<T>)
// performs an action with given object of type T.
Collection.removeIf(Predicate<T>)
// returns a boolean value based on input of type T.
List.replaceAll(UnaryOperator<T>)
// returns a result of type T.
The complete list of new functional interfaces can be found in java.util.function
A stream can be obtained from any type of collection.
Introduces the ability to perform bulk data operations on multiple threads.
List.Stream()
// from a list
(There are lots)
map.values().Stream() // from a map
"string".chars() // from a string
Stream.of("a", "b", "c") // from elements
Stream.iterate(0, i -> i+1) // iteration
Stream.generate(() -> Math.random()) // generation
Stream.builder().add("one").build() // building
Stream.of("a1", "a2", "a3")
.findFirst()
.ifPresent(System.out::println); // a1
IntStream.range(1, 4)
.forEach(System.out::println);
// 1
// 2
// 3
Supplier<Stream<String>> streamSupplier =
() -> Stream.of("d2", "a2", "b1", "b3", "c")
.filter(s -> s.startsWith("a"));
streamSupplier.get().anyMatch(s -> true); // ok
streamSupplier.get().noneMatch(s -> true); // ok
Previously annotations could only be applied to declarations.
@Encrypted String data;
List<@NonNull String> strings;
myGraph = (@Immutable Graph) tmpGraph;
" Java 8 introduces a new concept called, Compact Profiles, which enable reduced memory footprint for applications that do not require the entire Java platform "
Long standing issue is the inadequate support for the date and time:
- Not thread-safe, potential concurrency issues.
- Unintuitive API design in some cases.
- Led to the popularity of third-party libraries (Joda-Time).
Found in java.time
- Improve IDE capabilities
Parallel array sorting: java.util.Arrays.parallelSort()
Base64 encoding and decoding: java.util.Base64.Encoder and java.util.Base64.Decoder
Previously the JDK shipped with a JavaScript scripting engine based on Mozilla Rhino, this has been rewritten from the ground up, now called Nashorn.
Retired rarely used garbage collection combinations.
GitHub:
Useful Links:
http://www.oracle.com/technetwork/java/javase/8-whats-new-2157071.html
https://www.youtube.com/watch?v=DCBIegEqKuo
https://www.youtube.com/watch?v=eYROV3FTMh8&spfreload=1
https://www.youtube.com/watch?v=SmAFtvff4fE
http://openjdk.java.net/projects/jdk8/features
https://leanpub.com/whatsnewinjava8/read
http://www.javacodegeeks.com/2014/03/8-new-features-for-java-8.html