[2019 oracle code one] JPMS Modules with Gradle

Building JPMS Modules with Gradle

Speakers: Paul Bakker @pbakker

For more blog posts, see The Oracle Code One table of contents


General

  • Nobody in room yet using module system
  • Often takes several years after a feature release to be adopted.
  • Took 2-3 years after lambda use was common
  • Most open source provides a real module or at least a module name in the meta-inf

Plugin

  • Maven supported module system early on and still does.
  • Gradle did not so developed a plugin
  • https://github.com/java9-modularity/gradle-modules-plugin

IntelliJ

  • Shows modules as folders

Gradle

  • Each module has own build.gradle
  • Root build.gradle file is where the modular plugin is applied
  • external plugin so set classpath and apply to all java projects
  • Dependencies are defined in both build.gradle and module-info.java. Have to do this in Maven too.
  • Plugin adds gradle configuration when compile/test.

Flags

  • Showed exports – plugin has addExports option when compile
  • Showed opens – plugin has addOpens option when compile
  • Also supports AddModules and addReads like the Java options

Application plugin

  • Creates tar/zip with lib and bin folder
  • Supports module path

Packages

  • Split packages
  • “The classpath always works – as long as you don’t have expectations”
  • Always a problem; now in your face
  • patch-module as workaround. Puts library in patchlibs instead of being on module path

Multiple start scripts

  • Out of box, can create one zip file/one starting point
  • Module plugin allows creating custom startup scripts

Testing

  • For whitebox testing, ok to break encapsulation.
    • Classpath is ok
    • Plugin provides moduleOptions on test to choose
  • Black box testing – want module path to test how module works from outside module boundaries.
    • Use module path
    • Need additional module for this approach for tests

Java versions

  • plugin has modularity.mixedJavaReleases
  • compiler runs in two steps
  • compiles everything module-info.java using recent java version (presumably Java 9) and pulls out module-info.java
  • compiles other sources using java 8
  • the module-info.java is ignored by Java 8

My take

I found the gradle files hard/impossible to read (red/purple/green) on dark background. That made it hard for me to follow the parts I didn’t already know. I did learn some though so it was worth going. And it’s great that gradle has a JPMS plugin! I like how he mapped the command line to Gradle code.

[2019 oracle code one] exploring collectors

Exploring Collectors

Speakers: Venkat Subramaniam

For more blog posts, see The Oracle Code One table of contents


General

  • Common operations; filter, map, reduce
  • Filter – like a coin sorter. Will let some values through and discard others
  • Reduce – go from a stream to a non stream
  • Collect is a reduce operation
  • Functions should be pure – doesn’t change anything *and* doesn’t depend on anything that could change

Collectors – concepts

  • Don’t call add() in a forEach. Should be using a Collector
  • Can’t parallelize code when have shared mutability (ex: add() in forEach)
  • Can’t say “the code worked”. Can say “the code behaved”
  • If use ConcurrentList, it’s a ticking time bomb for when someone changes the list type.
  • Should write collect(Collectors.toList()) or collect(toList()). Already handles concurrency (when running with a parallel stream)
  • Venkat prefers using Collectors as a static import and just calling toList()
  • Collectors are recursive data structures. The second parameter is another Collector
  • Often need to chain collectors to do what want.
  • Ok to write code “the long way” and then refactor once have passing tests

Collectors – Code

  • Java 10+: toUnmodifiableList() – immutable list
  • partitioningBy – when need both the matching and non matching results. Avoids needing two passes of data to get result.
  • joining(“, “) – comma separated
  • groupingBy(Person::getName) – create map with key as name and value as list of Person objects. Conceptualize as buckets. Put items in bucket by key
  • groupingBy(Person::getName, mapping(Person::getAge, toList())) – map after group. Perform mapping right before throw data into bucket.
  • groupingBy(Person::getName, counting()) – value is # matching values
  • groupingBy(Person::getName, collectingAndThen(counting(), Long::intValue)) – transform the result of a collector to a different type

My take

I like that Venkat talked about how to write code “the long way” to explain the power of collectors. This was a good review. And good motivation as we update our OCP book (I have the streams chapter). I like the bucket analogy for groupingBy(). I didn’t know about collectingAndThen() The 45 minutes flew!

[2019 oracle code one] community keynote

For more blog posts, see The Oracle Code One table of contents


Fun

  • Throwing spaghetti code in toxic waste
  • 80s – Ken as pac man and Mala as ghost.
    • 8 bit characters.
    • Power pill.
    • Make pong and spaghetti code monster.
    • Text based code scrolls by
    • Duke scares it off
  • 90’s – Mario and Lugi 64 bit.
    • Netscape “Browser” as Bowser.
    • ”Applets are full of security holes. That should defeat bowser”.
    • Henri opened Visual Cafe and Visual J++
  • 2000 – Angry Birds and Lasagna code. The eagle as an inflatable costume is awesome.
    • XML and EJB and Struts
    • “XML is like human. Cute when small. Gets annoying as it gets bigger”.
    • Groovy and Scala.
    • I like Venkat coding in Sublime just like in his real presentations.
    • Other languages motivate Java to move forward (ex: pattern matching, lambdas).
    • Spring – giant slinky.
    • Convention over configuration. Grails.
  • 2010’s – Minecraft
    • Minecraft written in Java in 2009
    • As a service
    • Ravioli code
    • Java acquired superpowers – Invoke dynamic, Method handles, lambdas
    • Java ascends to cloud
    • New heros – spring cloud, micronaut, microprofile, quarkus

My take

This was hilarious. I like that they wrote who the people were on the screen. The historic references were incredible. Happy ending. “Community wins” and Duke comes out. Throw clouds at bad guys