A summary of new things in Java 8.
This is a little rough. Check the rest of the links on my Twitter account for more in depth articles.
Lambda
() ->Method reference
::
Allows retrofitting existing method in as a lambda argument.
Interfaces
- allows adding default methods to interface
- functional interfaces
Types of lambdas:
Predicate
Consumer
- performs function on argument passed into it
Suppliers
- provide things
New forEach:
Collections now have forEach method
coll.forEach((blah)
if(ship .... Etc
)
c.forEach((x)
x::method
)
streams / parallelStreams
- have to synchronize collection to use parallelStream - old way is faster - if done incorrectly. Correct way is to use new Collectors object. e.g. Collectors.toList(), Collectors.toSet()
Variables within a function are thread safe - supports parallel execution. Supports distribution of load across multiple cores.
JVM in Java 8 can run JavaScript. Can execute JavaScript from command line http://www.takipiblog.com/2014/02/10/java-8-compiling-lambda-expressions-in-the-new-nashorn-js-engine/
Nashorn to replace Rhino
New Java Time package.
LocalDate
.toEpochDay()
.plusDays(2)
Human readable time:
d.getYear()
d.getMonth()
Clock
c = Clock.systemUTC()
Timezone
Calculations
Time Gap
Optional
- optional gets you away from nulls
- deals with nullable return values
IDE Support
- NetBeans
- IntelliJ
Code coverage:
Jacoco
Most tools working
FindBugs fails