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

Be a Kid Again: Learn the Latest Java Features through Exploration

Be a Kid Again: Learn the Latest Java Features through Exploration

Learning how to apply the changes and features in the latest release of Java might seem like a daunting task, but we will see how to hack our own hesitation and make it fun. By putting the version diffs of Java in a graph database, the presenter tapped into natural curiosity, helping her tackle the new features in a fun and exploratory way.
Use the graph as a tool to understand levels of changes and things we might need to upgrade in existing code or new features we might want to take advantage of. We can use the graph as a reference as we navigate code projects where we will put the Java language improvements to the test.

Jennifer Reif

August 08, 2022
Tweet

More Decks by Jennifer Reif

Other Decks in Technology

Transcript

  1. Jennifer Reif Email: [email protected] Twitter: @JMHReif LinkedIn: linked.com/in/jmhreif Github: github.com/JMHReif

    Website: jmhreif.com Be a Kid Again: Learn the Latest Java Features through Exploration
  2. Who Am I? • Developer + Advocate • Continuous learner

    • Blogger • Conference speaker • Other: geek Jennifer Reif Email: [email protected] Twitter: @JMHReif LinkedIn: linkedin.com/in/jmhreif Github: GitHub.com/JMHReif Website: jmhreif.com
  3. Java 17 Features • Sealed classes • Pattern matching for

    switch statements • Always-strict floating-point semantics • Pseudo-random number generators • Strongly encapsulate JDK internals • Foreign function and memory API • Vector API • AArch64 port • MacOS rendering pipeline • Deprecate Security Manager • Deprecate Applet API • Remove RMI activation • Remove Exp. AOT/JIT compiler
  4. Selected features for today • Sealed classes • Pattern matching

    for switch statements • InstantSource in Java 17
  5. Sealed classes • More control over inheritance • Works with

    classes, interfaces, records • Allow or restrict subclasses at the parent class level • 3 constraints: • Subclasses must belong to same module as sealed class • Permitted subclass must extend sealed class • Subclass must have modifier (final, sealed, non-sealed)
  6. Sealed class syntax • Syntax: • Parent class - sealed

    + permits • Sub class - modifier + extends/implements Source: https://github.com/eugenp/tutorials/blob/master/core-java-modules/core-java-17/src/main/java/com/baeldung/sealed/classes/Vehicle.java
  7. Switch patterns • Preview feature • More options for comparisons

    • Opens up more switch data types • 3 pattern types: • Type pattern - is x a Type1 using instanceof operator? • Guarded pattern - is x a Type1 along with other criteria? • Parenthesized pattern - is x a Type1 along with conditional criteria?
  8. Switch pattern syntax • Syntax: • case <Type> -> do

    something • case <Type> + other check -> do something Source: https://github.com/eugenp/tutorials/blob/master/core-java-modules/core-java-17/src/main/java/com/baeldung/switchpatterns/TypePatterns.java
  9. InstantSource • Customizable instant with timezone abstraction • Dates/times/zones are

    developer nightmares! • 2 problems it solves: • Testing issue - default implementation that is customizable • Time zone issue - default java.time.Clock, creates consistent instant with timezone abstracted • Methods for truncation, fixed, offsets, instant, epoch, and zoneId
  10. InstantSource syntax • Syntax: • InstantSource.system().instant(); • Instant <variable> =

    InstantSource.<method> Source: https://github.com/eugenp/tutorials/tree/master/core-java-modules/core-java-17
  11. Why approach learning this way? • Natural curiosity • Self-driven

    learning • Data-driven learning • Relationships to connect known to unknown concepts
  12. Resources • Source code: github.com/JMHReif/java17-explore • Java 17 features: baeldung.com/java-17-new-features

    • Neo4j AuraDB free tier: dev.neo4j.com/aura-java • Cypher/Java data types: bit.ly/cypher-java-types • NODES 2022 (virtual): dev.neo4j.com/NODES-cfp Jennifer Reif Email: [email protected] Twitter: @JMHReif LinkedIn: linked.com/in/jmhreif Github: github.com/JMHReif Website: jmhreif.com