An Interest In:
Web News this Week
- April 3, 2024
- April 2, 2024
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
JDK 8 -> 20
Java 8 2014 Java 8 Java JVM Lambda Optional Stearm LocalDateTime
2023321Java 20LTS)Java 17LTSJava 8Java 2011Java 17
Table Of Contents
- JDK 9
- JDK 10
- JDK 14
- Switch
- NPE
- JDK 15
- ZGC:
- JDK 16
- instanceof
- Record
- JDK 17
- Switch ()
- JDK 18
- UTF-8
JDK 9
JDK 9 Collection FactoriesList
, Set
Map
Immutable Collection
JDK 8 :
Set<String> mySet = new HashSet<String>();mySet.add("yun");mySet.add("yyx");mySet.add("andy");mySet = Collections.unmodifiableSet(mySet);
JDK 9
Set<String> mySet = Set.of("yun", "yyx", "andy");
JDK 10
Javascript var
syntax JDK 10 var
Javascript var
Java var
String str = "https://dev.to/";URL url = new URL(str);URLConnection con = url.openConnection();
JDK 10
var str = "https://dev.to/";var url = new URL(str);var con = url.openConnection();
var
Java var
var flag = 0; // intshortbytevar items = new ArrayList<>(); // ArrayList<Object>
OpenJDKLVTI
JDK 14
Switch
Switch JDK 12 JDK 14->
yeild
switch
String season;switch(month){ case MAR: case APR: case MAY: season = "spring"; break; case JUN: case JUL: case AUG: season = "summer"; break; case SEP: case OCT: case NOV: season = "autumn"; break; case DEC: case JAN: case FEB: season = "winter"; break; default: throw new IllegalArgumentException("Not a month: " + month);}return season;
Switch
return switch(month){ case MAR, APR, MAY -> "spring"; case JUN, JUL, AUG -> "summer"; case SEP, OCT, NOV -> "autumn"; case DEC, JAN, FEB -> "winter";}
NPE
JDK 14 NullPointerException
(NPE)null
JDK 14 exception message null
b
null
a.i = b.j;
JDK 14
Exception in thread "main" java.lang.NullPointerException at App.main(App.java:5)
JDK 14
Exception in thread "main" java.lang.NullPointerException: Cannot read field "j" because "b" is null at App.main(App.java:5)
JDK 15
Java JDK 15
String json = "{
" + "\"name\": \"" + user.name + "\",
" + "\"nickname\": \"" + user.nickName + "\"
" + "}";
JDK 15
var json = """ { "name": "%s", "nickname": "%s" } """.formatted(user.name, user.nickName);
ZGC:
JDK 15ZGC SPEC (Standard Performance Evaluation Corporation) ZGC
JDK
ZGC G1GC GC GC Java G1GC ZGC GC Java Java GC GC GC Java
JDK 16
instanceof
Pattern Matching instanceof
if( obj instanceof String){ // 1) obj // 2) declare String str3) cast obj String String str = (String) obj; // str }
3 1
if( obj instanceof String str ){ // str }
Record
JDK 16 record
Java Lombok
record
Lombok
@Data
hashcode
equals
toString
record
final class
final
record
getter
Record Immutable
JDK 16
final class Point { private final int x; private final int y; Point(int x, int y) { this.x = x; this.y = y; } int x() { return x; } int y() { return y; } public boolean equals(Object o) { if (!(o instanceof Point)) return false; Point other = (Point) o; return other.x == x && other.y == y; } public int hashCode() { return Objects.hash(x, y); } public String toString() { return String.format("Point[x=%d, y=%d]", x, y); }}
Lombok
@Getter@ToString@EqualsAndHashCode@AllArgsConstructorfinal class Point{ final int x; final int y;}
JDK 16 record
record Point(int x, int y) { }
JDK 17
Java 17 LTS
sealed
class
interface
final
sealed
sealed
final
sealed
non-sealed
public abstract sealed class Shape permits Circle, Rectangle, Square, WeirdShape { ... }public final class Circle extends Shape { ... }public sealed class Rectangle extends Shape permits TransparentRectangle, FilledRectangle { ... }public final class TransparentRectangle extends Rectangle { ... }public final class FilledRectangle extends Rectangle { ... }public final class Square extends Shape { ... }public non-sealed class WeirdShape extends Shape { ... }
Switch ()
JDK 16 instanceof
JDK 17 switch
switch
instanceof
static String formatter(Object o) { String formatted = "unknown"; if (o instanceof Integer i) { formatted = String.format("int %d", i); } else if (o instanceof Long l) { formatted = String.format("long %d", l); } else if (o instanceof Double d) { formatted = String.format("double %f", d); } else if (o instanceof String s) { formatted = String.format("String %s", s); } return formatted;}
switch
static String formatterPatternSwitch(Object o) { return switch (o) { case Integer i -> String.format("int %d", i); case Long l -> String.format("long %d", l); case Double d -> String.format("double %f", d); case String s -> String.format("String %s", s); default -> o.toString(); };}
JDK 18
UTF-8
JDK 18 UTF-8 APIs
JDK 17 readability
JDK 8 JDK 17 GC GC Serial GC G1GC
Original Link: https://dev.to/andylow/jdk-8-20-zui-zhong-yong-de-xin-zeng-te-xing-36jc
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To