Speaking at JavaOne!

This year was my first visit to JavaOne and I got to go as a speaker! This wasn’t my first year applying, but it was my first year being accepted. If you are looking for my live blog posts, see the table of contents.

Applying

In addition to the usual (summary/abstract and bio), you had to submit a description of the session. You also had to submit a video of you speaking. I used the Mutation Testing talk from the NY Java User Group.

Getting accepted

On July 28th, I got an email saying my “JUnit 5 Hands On Lab” was accepted and I had two weeks to accept/decline. (I know people who got accepted two weeks earlier so I had originally thought I was rejected rather than being in “Phase 2.”) Then in later August, I got accepted for my “Intro to Mutation Testing” talk. This was about 5 weeks before the conference; luckily the mutation testing talk already existed and just needed minor edits/review. The on August 25th, I got the date/time of my sessions. Here’s my two sessions!

Picking Sessions

Before the conference, you have the opportunity to pre-register for sessions. Some fill up; especially hands on labs. If you don’t pre-register for a session, you can still try to attend off a physical wait list. But you get in earlier (and guaranteed) if you sign up. If a session got cancelled or changed rooms after pre-registering, you also got an email.

Getting Ready

I had done the mutation testing session before (well a shorter version of it). The JUnit 5 lab was new. It was fun to write. Like writing a chapter in a book (see it in github). But easier because I’d get to meet my audience. Steve Moyer from Penn State University and his two teammates offered to help me proctor the lab. This was immensely helpful. I practice both sessions a few times. Then I was ready!

There was some confusion about the Hands On Lab. Originally we were told that all labs would use VMs. After setting up my VM and submitting it, they said JavaOne sessions would use attendee laptop. Oh well, at least I got to play with Windows 10.

At the event

I got there and saw Duke inviting us in. Well, a cardboard Duke!

I also saw the JavaOne bookstore and took pictures with Scott and my books. I even went back later to see them with less books there.

Oh, and outside the conference, I rode a Segway. First time on a city street.

During a JUnit 5 session, Steve Moyer plugged my session:

And then there were my sessions:

 

 

 

 

 

 

 

 

 

After hours, I was on the winning team at IBM’s escape room with Sai (from the NY Java Sig) and three people we just met from Canada.

And of course I got to give Duke a hug!

After the conference
Shortly after each session, you could see the number of people who came to your session. I was at room capacity (or one under) for both sessions. I had a physical wait list line for both. For the JUnit 5 lab, someone even got on line 30 minutes early to ensure he’d get in!

In about a month, we get feedback from attendee surveys. Neither of my rooms was in a room with a thumbs up/side/down button so I’ll only get feedback from those who filled out the survey online. I got good feedback out loud though!

JavaOne – Modern Java Recipes

“Modern Java Recipes”

Speaker: Ken Kousen

For more blog posts from JavaOne, see the table of contents


All examples in this talk are in:
https://github.com/kousen/java_8_recipes

Lazy Streams

  • Streams – doesn’t store elements, doesn’t modify source, lazy when possible, destructive (can only run once)
  • Showed how findFirst() doesn’t cause all intermediate operations to run against all data in stream
  • findFirst() is a short circuiting terminal operation
  • Not many short circuiting stream operations. limit() is one as well for intermediate operation

Debugging streams

  • Eclipse and IntelliJ let you put breakpoints in stream
  • IntelliJ has plugin to see values in stream as go by
  • peek() method
  • Tip: Use a debug log library with peek so easy to turn off

Strings as Streams

  • String does not implement Iterable
  • Arrays.stream() doesn’t work for char[]
  • str.codePoints() returns int stream
  • StringBilder::appendCodePoint gets it back into stringish form
  • Obscure case; source: stack overflow

allMatch, anyMatch, noneMatch

  • all short circuiting terminal operations
  • showed with prime number checker – noneMatch returns as soon as finds example that proves number isn’t prime
  • also showed the assertFalse and anyMatch. I didn’t understand why this wasn’t assertTrue and noneMatch in the book

collect

  • showed three arg version – Supplier, BiConsumer to add single element to the result and anoher BiConsumer ot combine two interim results
  • the combiner isn’t mentioned in the JavaDoc pseudocoe
  • the combiner also gets used for parallel streams
  • reduce() is similar

Reduction

  • count() == mapToLong(e -> 1L).sum()
  • Added a few methods like Integer.sum(a,b) so can use as a BinaryOperator
  • The two argument version of reduce takes an identity for the binary operator. This lets it return a value instead of an Optional
  • Use reduce that takes BiFunction if reducing into a different type

Transforming streams

  • map – one to one mapping
  • flatMap – function from T to a stream. It is one to many where many is a stream
  • Optional also has a flatMap() which is for flattening Optional<Optional<T>> to Optional<T>

Deferred execution

  • Showed logger and how doesn’t build complex string if not needed to log
  • Overload methods to take supplier for this case. Caller just needs to add () ->
  • Don’t worry about this if you string is just a constant
  • Optional.orElseGet works the same way

Partioning and Grouping

  • downstream collectors – use when don’t want list back

Words

  • showed the /user/share/dict/words example
  • need to use try with resources when use Files.lines
  • Comparator.comparingInt(..).reversed().thenComparing(..)

Finally, showed demo of Anartica time zone map. The South pole follows New Zealand time. Which eans has daylight savings time despite getting 6 months of light vs 6 mnonths of dark

My take: Everything in this talk is from the book which I’ve already heard. But I’ve never seen Ken speak and wanted to. And it’s fun seeing things presented out loud. His umor while writing and out loud are similar which is good. I learned a few things in the comments like the IntelliJ debugging plugin.

JavaOne – How to Make a Project Java 9 Compatible

“How to Make a Project Java 9 Compatible”

Speaker: Nikhil Nanivadekar

For more blog posts from JavaOne, see the table of contents


Examples use Eclipse Collections

Examples from:
https://github.com/nikhilnanivadekar/Java9Compatibility
https://github.com/nikhilnanivadekar/Java9Modules

Reflection

  • Used ArrayListAdapter which uses reflection
  • Got illegal-access warning (when default was warn; now it is permit
  • If run with illegal-access=deny, it fails
  • Lesson: have lots of regression tests so know about such errors
  • Lesson: Allow a lot of time to migrate. Don’t start Friday evening. Long sequence of “just one more compilation error to fix”

Infering types

  • Compler error because can’t assume generictype to return
  • Comes up when class doesn’t have a generic type and try to store it in one that does.
  • Compiler not supposed to infer type
  • Fix is to cast or store in a local variable
  • Similarly need to declare types on class instatiation if not diamond operator usage

NullPointerException

  • collect() now calls Objects.requireNotNull(combiner).
  • In Java 8, a null combiner worked in serial mode because not used.

“I love compiler errors vs runtime exceptions”

Migrating a Java 8 Maven project to Java 9

  • Migrated a maze solving project. Was written recently so not legacy code
  • Switch source/target of maven-compiler-plugin to “9”.
  • Changed JDK in IntelliJ.
  • Maven itself works fine with Java 9. Compiling works. JavaDoc and Enforcer plugins work fine with milestone version; not yet for released versions. Seewiki on support for Java 9 in Maven plugins
  • Looking at modularizing library in future
  • Runs without adding module info file or doing anything else
  • Once add module file, more enforcement happens. ex: error on unnamed packages
  • Eclipse and IntelliJ have quick tip to add requires
  • Important: start with base module
  • If not using a build tool, need to ensure no cyclic dependencies. (build tool takes care of this for you)
  • Add exports clause for module. The compiler error just says the class isn’t found. It doesn’t say it is because the export is missing.
  • Move code in split package to another package updating all callers
  • Delete empty package; can’t have empty package
  • Hide internal packages by not exporting sub-packages

My take: Nice to see issues by example. And nice to see that it wasn’t “all about Jigsaw.” It was a good mix of problem types!