$30 off During Our Annual Pro Sale. View Details »

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

    View Slide

  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

    View Slide

  3. Data Demo!

    View Slide

  4. 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

    View Slide

  5. Java 17 Features
    Graph version!

    View Slide

  6. Selected features for today
    • Sealed classes

    • Pattern matching for switch statements

    • InstantSource in Java 17

    View Slide

  7. 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)

    View Slide

  8. 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

    View Slide

  9. 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?

    View Slide

  10. Switch pattern syntax
    • Syntax:

    • case -> do something

    • case + 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

    View Slide

  11. 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

    View Slide

  12. InstantSource syntax
    • Syntax:

    • InstantSource.system().instant();

    • Instant = InstantSource.
    Source: https://github.com/eugenp/tutorials/tree/master/core-java-modules/core-java-17

    View Slide

  13. App Demo!

    View Slide

  14. Why approach learning this way?
    • Natural curiosity

    • Self-driven learning

    • Data-driven learning

    • Relationships to connect known to unknown concepts

    View Slide

  15. 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

    View Slide