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

Your Java isn't the same

Your Java isn't the same

This deck covers some of the JDK changes between versions 9 to 21.

Rodrigo Graciano

June 07, 2023
Tweet

More Decks by Rodrigo Graciano

Other Decks in Programming

Transcript

  1. Your Java isn't Your Java isn't the same the same

    Rodrigo Graciano / Paula Santana
  2. About Backend Developer MVP Microsoft JUG Leader @DevsJavaGirl Paula Santana

    Java Champion Ace PRO JCP EC Member JUG Leader @NYJavaSIG Director of Data Engineering Rodrigo Graciano
  3. 60% 48% 30% Java 8 Versions in Production Java 11

    Java 17 https://www.jetbrains.com/lp/devecosystem-2022/java/
  4. Projects Loom Panama Amber Project Amber is to explore and

    incubate smaller, productivity-oriented Java language features explore and incubate Java VM features and APIs built on top of them for the implementation of lightweight user-mode threads (fibers), delimited continuations (of some form), and related features, such as explicit tail-call. improving and enriching the connections between the Java virtual machine and well-defined but “foreign” (non-Java) APIs, including many interfaces commonly used by C programmers. Valhalla Project Valhalla is augmenting the Java object model with value objects and user-defined primitives, combining the abstractions of object-oriented programming with the performance characteristics of simple primitives
  5. Switch Expressions Switch Expressions Java 12 - Preview Java 13

    - Second Preview Java 14 - released --enable-preview
  6. Text Blocks Text Blocks Java 12 - Preview Java 13

    - second Preview Java 14 - released
  7. start and end with a “”” (three double-quote marks) followed

    by optional white spaces and a newline. It allows us to include literal fragments of HTML, JSON, SQL, or whatever we need, in a more elegant and readable way.
  8. Before Required significant editing with escapes and concatenation The snippet

    was often difficult to read and arduous to maintain.
  9. After The result type of a text block is still

    a String. Text blocks just give us another way to write String .
  10. More The content may include line terminators directly. So in

    this example, both are equivalent. If we need carriage returns (\r) to be present, we have to explicitly add them to the text block if you use identation, use the position of closing triple quotes relative to the position of the last line
  11. Pay attention USE TEXT BLOCK TO CLARIFY THE CODE, SPECIALLY

    IN MULTIPLE LINE STRINGS IF THE CONTENT IS SHORT, PREFER TO USE STRINGS AVOID USING TEXT BLOCKS INSIDE OF COMPLEX EXPRESSIONS, LIKE LAMBDA
  12. Pattern Matching for Pattern Matching for instanceof instanceof Java 14

    - Preview Java 15 - second Preview Java 16 - released
  13. Sealed Classes Sealed Classes Java 15 - Preview Java 16

    - Second Preview Java 17 - Released
  14. PROVIDE a more declarative way than access modifiers to restrict

    the use of a superclass. THE PURPOSE A SEALED class or interface can be extended or implemented only by those classes and interfaces permitted to do so. of sealing a class is to let client code reason clearly and conclusively about all permitted subclasses.
  15. non-sealed A permitted subclass may also be declared sealed. However,

    if we declare it non-sealed, then it is open for extension:
  16. Pattern Matching for switch (the saga) Pattern Matching for switch

    (the saga) Java 17 - Preview Java 18 - Second Preview Java 19 - Third Preview Java 20 - Fourth Preview Java 21 - Final season
  17. wow

  18. Record Pattern Record Pattern Java 19 - Preview Java 20

    - Second Preview Java 21 - released
  19. Type Patterns remove many occurrences of casting at a stroke

    THE FIRST step towards a more declarative, data-focused style of programming.
  20. Replace the type of variables Extract values of the pattern

    variable location into variables using pattern matching It's possible to
  21. Template expressions are a new kind of expression in the

    Java programming language. Template expressions can perform string interpolation but are also programmable in a way that helps developers compose strings safely and efficiently. Consists of: A template processor (STR); A dot character (U+002E), as seen in other kinds of expressions; and A template ("My name is \{name}") which contains an embedded expression (\{name}).
  22. With these changes, we can now write Hello, World! as:

    Top-level members or using fields are interpreted as members of the unnamed class. and run as:
  23. Java’s collections framework lacks a collection type that represents a

    sequence of elements with a defined encounter order. It also lacks a uniform set of operations that apply across such collections. The problem.
  24. About this feature New family of interfaces that represent the

    concept of a collection whose elements are arranged in a well-defined sequence or ordering, as a structural property of the collection.
  25. Introduce new interfaces to represent collections with a defined encounter

    order and provide uniform APIs for accessing their first and last elements and processing them in reverse order. The framework will become more intuitive and efficient for developers.
  26. ZGC Shenandoah Epsilon No-op collector Perfect for benchmarking Allocate memory

    but does not recycle it Low-latency Works with all sizes of heaps – From small to Terabytes Pause time must not exceed 10ms Not a replacement for G1 Shenandoah is the low pause time garbage collector that reduces GC pause times by performing more garbage collection work concurrently with the running Java program G1 Enhance to G1. Automatically return Java heap memory to the operating system when idle Garbage Collectors Don't let the JVM pick your GC