Add java11-features module: runnable demos and captured output for the ankurm.com java11-features article

This commit is contained in:
2026-10-20 17:13:58 +00:00
parent 77c782abbf
commit 8b9447a393
19 changed files with 223 additions and 0 deletions
@@ -0,0 +1,7 @@
$ javac src/StringMethods.java && java StringMethods (11.0.32.1)
trim() length : 9
strip() length : 5
isBlank(" ") : true isEmpty: false
lines() : [a, b, c]
repeat(3) : ababab
stripLeading : [x ] stripTrailing: [ x]
+3
View File
@@ -0,0 +1,3 @@
$ javac src/FilesDemo.java && java FilesDemo (11.0.32.1)
read back : one|two|three
Path.of : a/b/c.txt
@@ -0,0 +1,4 @@
$ javac src/HttpClientDemo.java && java HttpClientDemo (11.0.32.1)
sync : 200 hello from server version=HTTP_1_1
header : X-Demo=yes
async : hello from server
+3
View File
@@ -0,0 +1,3 @@
$ javac src/VarLambda.java && java VarLambda (11.0.32.1)
(var a, var b) : 5
with annotation : x-y
@@ -0,0 +1,2 @@
$ java src/SingleFile.java (11.0.32.1)
launched from source, java.version=11.0.32.1
+4
View File
@@ -0,0 +1,4 @@
$ javac src/NestMates.java && java NestMates (11.0.32.1)
nest host : NestMates
inner can read : 42
access$ methods on outer: 0
@@ -0,0 +1,20 @@
$ javac broken/JaxbRemoved.java (1.8.0_504)
(compiled cleanly)
$ javac broken/JaxbRemoved.java (11.0.32.1)
broken/JaxbRemoved.java:1: error: package javax.xml.bind does not exist
import javax.xml.bind.JAXBContext;
^
broken/JaxbRemoved.java:6: error: cannot find symbol
System.out.println(JAXBContext.class.getName());
^
symbol: class JAXBContext
location: class JaxbRemoved
2 errors
$ javac broken/VarWithoutLambda.java (11.0.32.1)
broken/VarWithoutLambda.java:6: error: invalid lambda parameter declaration
BiFunction<Integer, Integer, Integer> f = (var a, Integer b) -> a + b;
^
(cannot mix 'var' and explicitly-typed parameters)
1 error
@@ -0,0 +1,33 @@
# trim vs strip on the same string, Java 8 has no strip(); the Java 8 compile of src/StringMethods.java:
$ javac src/StringMethods.java (1.8.0_504)
src/StringMethods.java:9: error: cannot find symbol
System.out.println("strip() length : " + padded.strip().length());
^
symbol: method strip()
location: variable padded of type String
src/StringMethods.java:10: error: cannot find symbol
System.out.println("isBlank(\" \") : " + " ".isBlank() + " isEmpty: " + " ".isEmpty());
^
symbol: method isBlank()
location: class String
src/StringMethods.java:11: error: cannot find symbol
System.out.println("lines() : " + "a\nb\r\nc".lines().collect(Collectors.toList()));
^
symbol: method lines()
location: class String
src/StringMethods.java:12: error: cannot find symbol
System.out.println("repeat(3) : " + "ab".repeat(3));
^
symbol: method repeat(int)
location: class String
src/StringMethods.java:13: error: cannot find symbol
System.out.println("stripLeading : [" + " x ".stripLeading() + "] stripTrailing: [" + " x ".stripTrailing() + "]");
^
symbol: method stripLeading()
location: class String
src/StringMethods.java:13: error: cannot find symbol
System.out.println("stripLeading : [" + " x ".stripLeading() + "] stripTrailing: [" + " x ".stripTrailing() + "]");
^
symbol: method stripTrailing()
location: class String
6 errors