ASAP. Even extended support is over. 8 or 11 Align code to future. “older Java comments” 9-10, 12-16, 18-19 Upgrade; not on latest LTS 17 Lots of refactoring 20-21 Even more refactoring
Jeanne Boyarsky \s </speaker> <title> Becoming one of the first Java 17 \ certified programmers \ (and learning new features) </title> </session> """; continue on next line without a line break new escape character keeps trailing whitespace tab 15 14
//TODO convert to text block when on Java 17 String json = "{" + " \"query\": \"%s\"" + " \"start\": \"1\"," + " \"end\": \"10\"" + "}"; return String.format(json, search); } 20 Hard to read but positions for future
numPages) { } New type Automatically get * final record * private final instance variables * public accessors * constructor taking both fields * equals * hashCode * toString 31
Book("Breaking and entering", 289); System.out.println(book.title()); System.out.println(book.toString()); No “get” Outputs: Breaking and entering Book[title=Breaking and entering, numPages=289] 32
on Java 17 public final class Book { private String title; private int numPages; public Book(String title, int numPages) { this.title = title; this.numPages = numPages; } public String title() { return title; } public int numPages() { return numPages; } // hash code, equals 35 Be sure to use al fields for equals/ hashCode
= ""; switch (store) { case "Hallmark": result = "KC"; break; case "Crayola": result = "PA"; break; default: result = "anywhere"; } return result; } You remembered the breaks, right? 49
}; Position pos = Position.TOP; int stmt = switch(pos) { case TOP: yield 1; }; int expr = switch(pos) { case BOTTOM -> 0; }; Does not compile because assigning value (poly expression) 51
obj) { return switch (obj) { case Integer i -> i; case Double d -> d.intValue(); case String s -> Integer.parseInt(s); default -> throw new IllegalArgumentException("unknown type"); }; } Reminder: Syntax can change 52
obj) { switch (obj) { case Integer i when i % 2 == 1 -> System.out.println("odd"); case Integer i when i % 2 == 0 -> System.out.println(“even"); default -> System.out.println("not an int"); }; } Reminder: Feature can still change 53
//TODO convert to switch expression on Java 17 String result = ""; switch (store) { case "Hallmark": result = "KC"; break; case "Crayola": result = "PA"; break; default: result = "anywhere"; } return result; } 56
commaSeparated) {} var list = List.of("x", "y", "z"); Separations result = list.stream() .collect(Collectors.teeing( Collectors.joining(" "), Collectors.joining(","), (s, c) -> new Separations(s, c))); System.out.println(result);
as String %d Decimal integer (no dot) %c Char %f Float (decimal) %n New line Many more out of scope. Examples: • %e - scientific notation • %t - time • %S - converts to all uppercase 62
ex = Executors.newVirtualThreadPerTaskExecutor() ex.submit(runnOrCall) // or managed Thread.Builder b = Thread.ofPlatform().name("xxx"); vs Thread.Builder b = Thread.ofVirtual().name("xxx"); b.start(runnable) 21 This could be a whole presentation…. 68