Slide 1

Slide 1 text

Your Java isn't Your Java isn't the same the same Rodrigo Graciano / Paula Santana

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

Topics Some information Features about developer Experience GC's and Performance What's next 01 02 03 04

Slide 4

Slide 4 text

1- Some Information 1- Some Information

Slide 5

Slide 5 text

60% 48% 30% Java 8 Versions in Production Java 11 Java 17 https://www.jetbrains.com/lp/devecosystem-2022/java/

Slide 6

Slide 6 text

Versions LTS Mar 2014 Sep 2018 Sep 2021 Sep 2023 8 11 17 21

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

2- Features about developer Experience 2- Features about developer Experience

Slide 9

Slide 9 text

Local-Variable Local-Variable Type Inference Type Inference Java 10

Slide 10

Slide 10 text

Before

Slide 11

Slide 11 text

After

Slide 12

Slide 12 text

more

Slide 13

Slide 13 text

Local-Variable Syntax Local-Variable Syntax for Lambda Parameters for Lambda Parameters Java 11

Slide 14

Slide 14 text

Before After

Slide 15

Slide 15 text

more

Slide 16

Slide 16 text

don't do that

Slide 17

Slide 17 text

Switch Expressions Switch Expressions Java 12 - Preview Java 13 - Second Preview Java 14 - released --enable-preview

Slide 18

Slide 18 text

Before

Slide 19

Slide 19 text

After

Slide 20

Slide 20 text

Yield

Slide 21

Slide 21 text

don't do that

Slide 22

Slide 22 text

Text Blocks Text Blocks Java 12 - Preview Java 13 - second Preview Java 14 - released

Slide 23

Slide 23 text

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.

Slide 24

Slide 24 text

Before Required significant editing with escapes and concatenation The snippet was often difficult to read and arduous to maintain.

Slide 25

Slide 25 text

After The result type of a text block is still a String. Text blocks just give us another way to write String .

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

Pattern Matching for Pattern Matching for instanceof instanceof Java 14 - Preview Java 15 - second Preview Java 16 - released

Slide 29

Slide 29 text

Before

Slide 30

Slide 30 text

After

Slide 31

Slide 31 text

Helpful Helpful NullPointerExceptions NullPointerExceptions Java 14

Slide 32

Slide 32 text

Cast the first stone who never received a NullPointerException

Slide 33

Slide 33 text

Before After

Slide 34

Slide 34 text

The filename and line number do not pinpoint exactly which variable was null

Slide 35

Slide 35 text

Before After

Slide 36

Slide 36 text

Records Records Java 14 - Preview Java 15 - Second Preview Java 16 - Released

Slide 37

Slide 37 text

Before

Slide 38

Slide 38 text

After Is Final Not Serializable by default No Setters getId() -> id()

Slide 39

Slide 39 text

Sealed Classes Sealed Classes Java 15 - Preview Java 16 - Second Preview Java 17 - Released

Slide 40

Slide 40 text

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.

Slide 41

Slide 41 text

non-sealed A permitted subclass may also be declared sealed. However, if we declare it non-sealed, then it is open for extension:

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

wow

Slide 44

Slide 44 text

Sealed Class

Slide 45

Slide 45 text

Record Pattern Record Pattern Java 19 - Preview Java 20 - Second Preview Java 21 - released

Slide 46

Slide 46 text

Type Patterns remove many occurrences of casting at a stroke THE FIRST step towards a more declarative, data-focused style of programming.

Slide 47

Slide 47 text

Replace the type of variables Extract values of the pattern variable location into variables using pattern matching It's possible to

Slide 48

Slide 48 text

3- what's next 3- what's next

Slide 49

Slide 49 text

String Templates String Templates Java 21 - Preview

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

It may consist of Strings Perform Arithmetic invoke methods and access fields

Slide 52

Slide 52 text

Multi-line template expressions

Slide 53

Slide 53 text

Unnamed Classes and Instance Main Methods Unnamed Classes and Instance Main Methods Java 21 - Preview

Slide 54

Slide 54 text

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:

Slide 55

Slide 55 text

Sequenced Collections Sequenced Collections Java 21 - Preview

Slide 56

Slide 56 text

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.

Slide 57

Slide 57 text

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.

Slide 58

Slide 58 text

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.

Slide 59

Slide 59 text

4- GC's and Performance 4- GC's and Performance

Slide 60

Slide 60 text

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

Slide 61

Slide 61 text

Any questions? @psanrosa13 @rodrigograciano