List of new features since Java 8
Java 9
- HTML5 Javadoc
https://blog.idrsolutions.com/2017/05/how-html5-javadocs-in-java-9-will-make-your-life-easier/ - New HTTP Client
https://www.baeldung.com/java-9-http-client - Collection factory methods
List.of(1, 2, 3)
https://www.tutorialspoint.com/java9/java9_collection_factory_methods.htm - Process API impovements
https://www.tutorialspoint.com/java9/java9_process_api_improvements.htm
ProcessBuilder pb = new ProcessBuilder("notepad.exe"); - Private interface methods
With Java 9 interfaces can have following type of variables/methods.
- Constant variables
- Abstract methods
- Default methods
- Static methods
- Private methods
- Private Static methods
- Stream API improvements
takeWhile, dropWhile, iterate, ofNullable
https://www.tutorialspoint.com/java9/java9_stream_api_improvements.htm - Try w/ resources improvement
BufferedReader br = new BufferedReader(inputString);
https://www.tutorialspoint.com/java9/java9_try_with_resources_improvement.htm
try (br)
{
  return br.readLine();
} - /@Deprecated improvements
forRemoval, since
https://www.tutorialspoint.com/java9/java9_enhanced_deprecated_annotation.htm - Inner class diamond operator
https://www.tutorialspoint.com/java9/java9_inner_class_diamond_operator.htm - Optional improvements
stream, ifPresentOrElse, or
https://www.tutorialspoint.com/java9/java9_optional_class_improvements.htm
Java 10
- Local variable type inference
var str =
"Hello world"
;
https://howtodoinjava.com/java10/var-local-variable-type-inference/ - Collection factory methods
List.copyOf, etc.. - Optional.orElseThrow()
Java 11
- New String Methods
" ".isBlank, str.lines(), strip(). stripLeading(), stripTailing(), repeat(int) - Reading/Writing strings to files
Files.writeString
Files.readString - Local variable syntax for lamda parameters
(var s1, var s2) -> s1 + s2
- Reflection access control stuff
Class.getNestHost, getNestMembers, isNestmateOf - HTTP client improvements supporting HTTP 1.1 and Websocket
- Optional.isEmpty
Java 12
- Switch expressions
String result = switch (day) { case "M", "W", "F" -> "MWF"; case "T", "TH", "S" -> "TTS"; default -> { if(day.isEmpty()) break "Please insert a valid day."; else break "Looks like a Sunday."; }
File.mismatch
- Compact number formatting
NumberFormat.getCompactNumberInstance - Collectors.teeing
- String.indent, transform, describeConstable, resolveContantDesc
- Pattern matching for instanceof
if (obj instanceof String s)
Java 13
- Text blocks
String textBlock = """ Hi Hello Yes""";
- Text block methods
formatted, stripIndent, translateEscapes - Switch statement
return -> yield - New implementation of Socket API