How To Troubleshoot Collaboration Apps for the Modern Connected Worker
engage 2016 - Get ready for moving from Java 6 to Java 8 - Now!
1. 1
Get ready for moving from
Java 6 to Java 8 – Now!
René Winkelmeyer
24.03.2016
2. 2
• Skype / Twitter / LinkedIn / Slideshare
muenzpraeger
• Web
https://blog.winkelmeyer.com
• Mail
mail@winkelmeyer.com
OpenNTF
• File Navigator
• Generic NSF View Widget for IBM Connections
About me
René Winkelmeyer
Head of Development
10. 10
Goodbye if-then-elseif-elseif-elseif… for Strings
§ Java 7 added support for java.lang.String in switch
§ Increased readability
§ Produces more efficient byte code
§ Switching based on the hashcode()
§ May (still) throw a NullPointerException
13. 13
Diamonds are developers best friend
§ Java 7 introduced the usage of the <> operator for type inference
§ Removes verbose code
§ Makes usage of 3rd party libs like Google Guava for List creation
obsolete
14. 14
Diamonds are developers best friend
Raw error warning in Eclipse. Technically possible, but not recommended.
How to do it. Imagine HashMap<String, HashMap<String, Object>> i. e.
Diamond operator for less code writing. ;-)
17. 17
Automated resource management
§ Java 7 introduced the new java.lang.AutoCloseable interface
§ Resources that inherit from this interface are automatically closed when
created within a try statement
§ Reduces boilerplate code drastically
§ java.lang.Closeable extends from java.lang.AutoCloseable
§ AutoCloseable.close() shouldn‘t be called twice!
24. 24
Underscore me
§ The with Java 7 introduced capability allows to add underscores to
numeric types (int, double, long).
§ A few rules to obey:
§ Can be used after the decimal point, but not directly before/after it
§ No underscores at the end or the beginning (i. e. _5000 or 5000_)
31. 31
NIO.2
§ The handling of file system related actions has been much improved
with Java 7.
§ Removes the need in a lot of cases to rely on 3rd pary libraries like
Apache Commons Files.
§ Direct implementation in the base JDK
32. 32
NIO.2
§ java.nio.Path
§ Think of it as a replacement for java.io.File
§ Represents a file or a folder – and it doesn‘t need to exist (no
Exception ;-))
§ java.nio.Files
§ Loads of utility classes for file and folder handling
35. 35
Watch your files
Initiates the default WatchService as introduced with Java 7
Assign the to be monitored path using the new java.nio.Path API
Register the created WatchService with the path. Events that can be monitored
are create, update and delete.
38. 38
default
§ Changes in Interfaces always led to changes in the classes they
used them
§ The new default constructor introduces „backward“ compatibility
44. 44
Lambdas
§ One of the biggest changes with Java 8
§ Known from other languages like Closure, Scala, C# and more
§ Defined in Java Specification Request (JSR) 335
§ Knows as closures or functional literals in other languages
§ Love or hate them – there‘s no way around them!
52. 52
What is a stream and what not?
§ It is a pipeline of functions that can be evaluated.
§ They are not a data structure.
§ They can transform data – but cannot mutate them.
57. 57
Streams – a little bit more complete
Source:http://zeroturnaround.com/rebellabs/java-8-streams-cheat-sheet/attachment/java-8-
streams-cheat-sheet-v3/
61. 61
Date and Time – Basic Concept
§ LocalDate, LocalTime, LocalDateTime
§ Instant (amount of time since the epoch, i. e. for timestamps)
§ Period
§ Duration
62. 62
Date and Time – Examples
§ Now -> LocalDate.now()
§ Static -> LocalDate(2013, Month.JANUARY, 21)
§ Parse -> LocalDate.parse()
§ Conversion -> Calendar.getInstance().toInstant()