Skip to content

Commit 6c72e25

Browse files
committed
reorganization
1 parent d2d4062 commit 6c72e25

26 files changed

+192
-224
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
.idea/
77
target/
88
output/
9+
bin/
910
*.jar
1011
*.war
1112
*.ear

Diff for: README.md

+15-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ A project to explore more about the new features of Java 8, 9, ...
3737
* Null I/O
3838

3939
* [Java 12](java-12/)
40-
* Switch expression (preview 1)
40+
* Switch expression (preview)
4141
* Compact Number Format
4242
* Collectors improvements
4343
* CompletableFuture improvements
@@ -46,7 +46,7 @@ A project to explore more about the new features of Java 8, 9, ...
4646

4747
* [Java 13](java-13/)
4848
* Switch expression (preview 2)
49-
* Text blocks
49+
* Text blocks (preview)
5050
* String API updates
5151
* NIO updates
5252
* Socket and ServerSocket reimplementation (Project Loom)
@@ -56,10 +56,21 @@ A project to explore more about the new features of Java 8, 9, ...
5656
* [Java 14](java-14/) (May 17th, 2020)
5757
* Switch expression (standard)
5858
* Pattern matching for `instanceof` (preview)
59-
* Text blocks improvements
59+
* Text blocks improvements (preview 2)
6060
* Records (preview)
6161
* Helpful NullPointerExceptions
6262
* Packaging tool
6363
* JFR even streaming
6464

65-
* [Java 15](java-15/)
65+
* [Java 15](java-15/) (GA - Sep, 2020)
66+
* Sealed classes (preview)
67+
* Hidden classes
68+
* DatagramSocket reimplementation
69+
* Pattern matching for `instanceof` (preview 2)
70+
* Records (preview 2)
71+
* Foreign-Memory Access API (incubator)
72+
73+
## Helpful Links
74+
75+
* [Considerations Bumping Java EE](https://vorozco.com/blog/2020/2020-08-21-considerations-bumping-javaee.html)
76+
* [The Role of Preview Features in Java and Beyond](https://blogs.oracle.com/javamagazine/the-role-of-previews-in-java-14-java-15-java-16-and-beyond)

Diff for: java-10/CollectionsCopyOf.java

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import java.util.Arrays;
2+
import java.util.List;
3+
import java.util.Map;
4+
import java.util.Set;
5+
6+
public class CollectionsCopyOf {
7+
public static void main(String[] args) {
8+
List<String> muttableList = Arrays.asList("New", "Method", "To", "Copy");
9+
10+
// Copy methods
11+
List<String> immutableList = List.copyOf(muttableList);
12+
immutableList.forEach(System.out::println);
13+
14+
Set<String> immutableSet = Set.copyOf(muttableList);
15+
immutableSet.forEach(System.out::println);
16+
17+
Map<String, String> immutableMap = Map.copyOf(Map.of("k1", "v1", "k2", "v2"));
18+
immutableMap.forEach((key, value) -> System.out.println(key + " = " + value));
19+
20+
}
21+
}

Diff for: java-10/ProcessTest.java

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import java.lang.management.ManagementFactory;
2+
import java.lang.management.RuntimeMXBean;
3+
4+
public class ProcessTest {
5+
public static void main(String[] args) {
6+
final RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
7+
final long pid = runtime.getPid();
8+
System.out.println("Process ID is: " + pid);
9+
}
10+
}

Diff for: java-10/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Java 10
22

3+
```sh
4+
sh build.sh
5+
java -cp bin <ClassName>
6+
```
7+
38
## Features
49

510
### Language

Diff for: java-10/StreamToUnmodifiableCollections.java

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import java.util.List;
2+
import java.util.Map;
3+
import java.util.function.Function;
4+
import java.util.stream.Collectors;
5+
6+
public class StreamToUnmodifiableCollections {
7+
public static void main(String[] args) {
8+
List<String> list = List.of("Testing", "Immutable", "List", "From", "Stream");
9+
10+
List<String> immutableList = list.stream()
11+
.collect(Collectors.toUnmodifiableList());
12+
immutableList.forEach(System.out::println);
13+
14+
Map<String, Integer> wordsLengths = list.stream()
15+
.collect(Collectors.toUnmodifiableMap(Function.identity(), word -> word.length()));
16+
wordsLengths.forEach((word, length) -> System.out.println(word + " -> " + length + " letters"));
17+
}
18+
}

Diff for: java-10/build.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[[ -f bin ]] && mkdir bin
2+
javac *.java -d ./bin

Diff for: java-10/pom.xml

-21
This file was deleted.

Diff for: java-10/src/main/java/com/github/wesleyegberto/collections/CollectionsCopyOf.java

-23
This file was deleted.

Diff for: java-10/src/main/java/com/github/wesleyegberto/collections/StreamToUnmodifiableCollections.java

-20
This file was deleted.

Diff for: java-10/src/main/java/com/github/wesleyegberto/process/ProcessTest.java

-12
This file was deleted.

Diff for: java-11/GetRequestAsyncTest.java

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import java.net.http.HttpClient;
2+
import java.net.http.HttpRequest;
3+
import java.net.http.HttpResponse;
4+
5+
public class GetRequestAsyncTest {
6+
public static void main(String[] args) throws InterruptedException {
7+
HttpRequest request = HttpBinRequestBuilder.createGetRequest();
8+
9+
HttpClient httpClient = HttpClientBuilderTest.createHttpClient();
10+
// HttpClient#sendAsync is non-blocking and returns a CompletableFuture
11+
httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString())
12+
.thenApply(HttpResponse::body)
13+
.thenAccept(body -> System.out.println("Async Response: " + body))
14+
.exceptionally(ex -> {
15+
System.out.println("Exception: " + ex.getLocalizedMessage());
16+
return null;
17+
})
18+
.join(); // let's wait
19+
}
20+
}

Diff for: java-11/GetRequestReactiveTest.java

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import java.net.http.HttpRequest;
2+
import java.net.http.HttpResponse.BodyHandlers;
3+
import java.util.concurrent.Flow.Subscriber;
4+
import java.util.concurrent.Flow.Subscription;
5+
6+
public class GetRequestReactiveTest {
7+
public static void main(String[] args) {
8+
HttpRequest request = HttpBinRequestBuilder.createGetRequest();
9+
10+
HttpClientBuilderTest.createHttpClient()
11+
.sendAsync(request, BodyHandlers.fromLineSubscriber(new LinePrinter()))
12+
.join();
13+
}
14+
15+
public static class LinePrinter implements Subscriber<String> {
16+
private Subscription subscription;
17+
18+
@Override
19+
public void onSubscribe(Subscription subscription) {
20+
this.subscription = subscription;
21+
this.subscription.request(1);
22+
}
23+
24+
@Override
25+
public void onNext(String item) {
26+
System.out.println("== [LinePrinter] Line received: " + item);
27+
this.subscription.request(1);
28+
}
29+
30+
@Override
31+
public void onError(Throwable throwable) {
32+
System.out.println("== [LinePrinter] Line received: " + throwable);
33+
}
34+
35+
@Override
36+
public void onComplete() {
37+
System.out.println("== [LinePrinter] Completed");
38+
}
39+
}
40+
}

Diff for: java-11/GetRequestTest.java

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import java.io.IOException;
2+
import java.net.http.HttpClient;
3+
import java.net.http.HttpRequest;
4+
import java.net.http.HttpResponse;
5+
import java.net.http.HttpResponse.BodyHandlers;
6+
7+
public class GetRequestTest {
8+
public static void main(String[] args) throws IOException, InterruptedException {
9+
HttpRequest request = HttpBinRequestBuilder.createGetRequest();
10+
11+
HttpClient httpClient = HttpClientBuilderTest.createHttpClient();
12+
// HttpClient#send is blocking; the body is kept in memory to be processed
13+
HttpResponse<String> httpResponse = httpClient.send(request, BodyHandlers.ofString());
14+
System.out.println("Response: " + httpResponse.body());
15+
}
16+
}

Diff for: java-11/HttpBinRequestBuilder.java

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import java.net.URI;
2+
import java.net.http.HttpRequest;
3+
4+
public class HttpBinRequestBuilder {
5+
public static HttpRequest createGetRequest() {
6+
// HttpRequest is immutable
7+
return HttpRequest.newBuilder()
8+
.GET()
9+
.uri(URI.create("http://httpbin.org/get"))
10+
.header("Accept-Language", "en-US,en;q=0.5")
11+
.build();
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
package com.github.wesleyegberto.java11.http;
2-
31
import java.net.http.HttpClient;
42
import java.time.Duration;
53

Diff for: java-11/PostRequestTest.java

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import java.io.IOException;
2+
import java.net.URI;
3+
import java.net.http.HttpClient;
4+
import java.net.http.HttpRequest;
5+
import java.net.http.HttpResponse;
6+
7+
import static java.net.http.HttpRequest.*;
8+
9+
public class PostRequestTest {
10+
public static void main(String[] args) throws IOException, InterruptedException {
11+
BodyPublisher body = BodyPublishers.ofString("{'id':1}");
12+
HttpRequest request = newBuilder()
13+
.POST(body)
14+
.uri(URI.create("http://httpbin.org/post"))
15+
.build();
16+
17+
HttpClient httpClient = HttpClientBuilderTest.createHttpClient();
18+
HttpResponse<String> httpResponse = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
19+
System.out.println("Response: " + httpResponse.body());
20+
}
21+
}

Diff for: java-11/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Java 11
22

3+
To run each example use:
4+
5+
```sh
6+
sh build.sh
7+
java -cp bin <ClassName>
8+
```
9+
310
## Features
411

512
### Language

Diff for: java-11/build.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[[ -f bin ]] && mkdir bin
2+
javac *.java -d ./bin

Diff for: java-11/pom.xml

-21
This file was deleted.

Diff for: java-11/src/main/java/com/github/wesleyegberto/java11/http/GetRequestAsyncTest.java

-22
This file was deleted.

0 commit comments

Comments
 (0)