Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[WiT38] Java 8 - What Could Possibly Go Wrong?

[WiT38] Java 8 - What Could Possibly Go Wrong?

Slides from presentation given at 38. meetup of Women In Technology (organized with Polish JUG and Akamai) - "
All you want to know about Java".

---

Links to SO questions (CC / MIT Licensed) and other sources:

http://stackoverflow.com/a/22269778/708434
http://stackoverflow.com/a/22269778/708434

---

Other links:

http://www.baeldung.com/java-8-adoption-march-2016
http://www.oracle.com/technetwork/java/javase/8-whats-new-2157071.html
https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ForkJoinPool.html

---

Links to images used in presentation (CC licensed):

http://jay-wick.deviantart.com/art/Source-Code-Icons-VS2012-Style-447108904
http://www.thebluediamondgallery.com/scrabble/a/agenda.html
https://en.wikipedia.org/wiki/A_Sunday_Afternoon_on_the_Island_of_La_Grande_Jatte#/media/File:Georges_Seurat_-_A_Sunday_on_La_Grande_Jatte_--_1884_-_Google_Art_Project.jpg
http://www.thebluediamondgallery.com/tablet/a/adoption.html
https://en.wikipedia.org/wiki/Guernica_(Picasso)#/media/File:PicassoGuernica.jpg
https://commons.wikimedia.org/wiki/File:Arthur_Rubinstein_mural,_%C5%81%C3%B3d%C5%BA_Sienkiewicza_%26_Traugutta_Streets.jpg
http://stackoverflow.com/a/602457/708434
https://en.wikipedia.org/wiki/Young_Man_with_a_Skull#/media/File:Young_Man_with_a_Skull,_Frans_Hals,_National_Gallery,_London.jpg
https://en.wikipedia.org/wiki/The_Persistence_of_Memory#/media/File:The_Persistence_of_Memory.jpg
https://www.flickr.com/photos/97595808@N00/3758018781/
https://commons.wikimedia.org/wiki/File:James_Malton_Trinity_College_Library_Dublin.jpg
https://en.wikipedia.org/wiki/Isle_of_the_Dead_(painting)#/media/File:Arnold_B%C3%B6cklin_-_Die_Toteninsel_I_(Basel,_Kunstmuseum).jpg
https://en.wikipedia.org/wiki/San_Giorgio_Maggiore_at_Dusk#/media/File:Claude_Monet,_Saint-Georges_majeur_au_cr%C3%A9puscule.jpg

Grzegorz Rożniecki

September 20, 2016
Tweet

More Decks by Grzegorz Rożniecki

Other Decks in Programming

Transcript

  1. About me @xaerxess Important: Images used in this presentation (and

    the presentation itself) are free to use under Creative Commons Attribution License. Code (reviews) addict Open Source advocate I’m a software engineer who enjoys learning and likes sharing his knowledge. Big GNU/Linux fan and Open Source Software advocate. I’ve developed software in various languages, including Perl, JavaScript, Java, Python, PHP and Lisp (and experimented with few others). • Being a programmer is mostly reading code, not writing • You are not your code! • Freedom is important • You can read how libraries, languages, even operating systems are built - and learn! • Contribute, it’s easy!
  2. Java 8 adoption Java versions as of March 2016 October

    2014 27% 38% 64% May 2015 March 2016
  3. Programming styles Imperative Declarative Functional The focus is on what

    steps the computer should take rather than what the computer will do (ex. C, C++, Java). The focus is on what the computer should do rather than how it should do it (ex. SQL). A subset of declarative languages that has heavy focus on recursion.
  4. Optional To be, or not to be… • OptionalResult •

    Optional#getOrElseThrowNoSuchElementException() • Implements Serializable? • Optional#stream() Sigh, why does everything related to Optional have to take 300 messages? ” Brian Goetz (2013-10-23 on lambda-libs-spec-experts) “ Junior Developer taking advice before starting work on a legacy project (aka avoiding null)
  5. Date API java.time The main API for dates, times, instants,

    and durations. (...) They are based on the ISO calendar system, which is the de facto world calendar following the proleptic Gregorian rules. All the classes are immutable and thread-safe. “
  6. Streams java.util.stream Classes in the new java.util.stream package provide a

    Stream API to support functional-style operations on streams of elements. The Stream API is integrated into the Collections API, which enables bulk operations on collections, such as sequential or parallel map-reduce transformations. • Sequential • Parallel • Unordered? “
  7. Parallel streams Tasks in ForkJoinPool into smaller pieces split new

    subtasks fork computed tasks join 1 2 3 4 results from pieces compose
  8. Parallel streams List<Integer> primes = IntStream .range(1, 1_000_000) .parallel() .filter(PrimesPrint::isPrime)

    .collect(toList()); // how many threads is this using? // how do I configure that? Defaluts // see ForkJoinPool Javadoc -Djava.util.concurrent.ForkJoinPool.common.parallelism=4
  9. Parallel streams ForkJoinPool forkJoinPool = new ForkJoinPool(2); forkJoinPool.submit(() -> IntStream.range(1,

    1_000_000).parallel() .filter(PrimesPrint::isPrime) .collect(toList()) ).get(); Custom ForkJoinPool