Skip to content

Commit 69d9f4d

Browse files
committed
refactoring folders; added Java 9 examples
1 parent 419ffab commit 69d9f4d

File tree

14 files changed

+168
-1
lines changed

14 files changed

+168
-1
lines changed

java-8/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.github.wesleyegberto</groupId>
5-
<artifactId>java-new-features</artifactId>
5+
<artifactId>java-8-new-features</artifactId>
66
<version>1.0-SNAPSHOT</version>
77
<packaging>jar</packaging>
88

File renamed without changes.

java-9/modules/simple_deps/build_bundle.sh

100755100644
File mode changed.

java-9/modules/simple_deps/build_modules.sh

100755100644
File mode changed.

java-9/modules/simple_deps/run_bundle.sh

100755100644
File mode changed.

java-9/modules/simple_deps/run_module_calculator.sh

100755100644
File mode changed.

java-9/modules/simple_deps/show_deps.sh

100755100644
File mode changed.

java-9/others-features/build_run.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
rm -rf target
2+
3+
CLASSES_DIR="target/classes"
4+
JAR_DIR="target/jars"
5+
6+
mkdir -p $CLASSES_DIR
7+
mkdir -p $JAR_DIR
8+
9+
$JAVA9_HOME/bin/javac -p jdk.incubator.httpclient -d $CLASSES_DIR --module-version 1.0 `find src/main/java -name *.java`
10+
11+
# --main-class com.github.wesleyegberto.httpclient.HttpClientTest \
12+
$JAVA9_HOME/bin/jar -c -f $JAR_DIR/http-client-test.jar \
13+
--main-class com.github.wesleyegberto.collections.CollectionsTest \
14+
-C $CLASSES_DIR .
15+
16+
17+
$JAVA9_HOME/bin/java -p $JAR_DIR -m J9NewFeatures

java-9/others-features/pom.xml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.github.wesleyegberto</groupId>
5+
<artifactId>java-9-new-features</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<packaging>jar</packaging>
8+
9+
<dependencies>
10+
</dependencies>
11+
12+
<build>
13+
<finalName>java-9-new-features</finalName>
14+
</build>
15+
16+
<properties>
17+
<maven.compiler.source>9</maven.compiler.source>
18+
<maven.compiler.target>9</maven.compiler.target>
19+
<failOnMissingWebXml>false</failOnMissingWebXml>
20+
</properties>
21+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.github.wesleyegberto.collections;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
import java.util.Set;
6+
7+
public class CollectionsTest {
8+
public static void main(String[] args) {
9+
List.of("First", "Second", "Third")
10+
.forEach(System.out::println);
11+
12+
Set.of(1, 2, 3, 4, 5)
13+
.forEach(System.out::println);
14+
15+
Map.of("K1", "V1", "K2", "V2", "K3", "V3", "K4", "V4", "K5", "V5")
16+
.forEach((key, value) -> System.out.println(key + " -> " + value));
17+
18+
Map.ofEntries(
19+
Map.entry("K1", "V1"),
20+
Map.entry("K2", "V2"),
21+
Map.entry("K3", "V3"),
22+
Map.entry("K4", "V4"),
23+
Map.entry("K5", "V5")
24+
)
25+
.forEach((key, value) -> System.out.println(key + " -> " + value));
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.github.wesleyegberto.httpclient;
2+
3+
import java.io.IOException;
4+
import java.net.URI;
5+
import jdk.incubator.http.*;
6+
7+
public class HttpClientTest {
8+
public static void main(String[] args) throws IOException, InterruptedException {
9+
HttpRequest request = HttpRequest.newBuilder()
10+
.uri(URI.create("http://httpbin.org/uuid"))
11+
.GET()
12+
.build();
13+
14+
String syncResponse = HttpClient.newHttpClient()
15+
.send(request, HttpResponse.BodyHandler.asString())
16+
.body();
17+
18+
System.out.println("Sync response: " + syncResponse);
19+
20+
HttpClient.newHttpClient()
21+
.sendAsync(request, HttpResponse.BodyHandler.asString())
22+
.thenApply(HttpResponse::body)
23+
.thenAccept(response -> System.out.println("Async response: " + response));
24+
25+
26+
/*
27+
.responseAsync() // CompletableFuture
28+
.thenAccept(httpResponse ->
29+
System.out.println(httpResponse.body(HttpResponse.asString()))
30+
);*/
31+
Thread.sleep(5000);
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.github.wesleyegberto.processapi;
2+
3+
import java.io.IOException;
4+
5+
public class ProcessTest {
6+
public static void main(String[] args) throws IOException, InterruptedException {
7+
ProcessHandle process = ProcessHandle.current();
8+
System.out.println("Main pid: " + process.pid());
9+
System.out.println("Main user: " + process.info().user().orElse("Unknown"));
10+
11+
Process sleepy = Runtime.getRuntime().exec("sleep 60s");
12+
System.out.println("Sleepy pid: " + sleepy.pid());
13+
14+
System.out.println("Destroying sleepy");
15+
sleepy.onExit()
16+
.thenRun(() -> {
17+
System.out.println("Alive: " + sleepy.isAlive());
18+
System.out.println("Exit code: " + sleepy.exitValue());
19+
});
20+
sleepy.destroy();
21+
22+
Thread.sleep(5000);
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.github.wesleyegberto.reactive;
2+
3+
import java.util.concurrent.Flow.Subscriber;
4+
import java.util.concurrent.Flow.Subscription;
5+
import java.util.concurrent.SubmissionPublisher;
6+
import java.util.stream.IntStream;
7+
8+
public class FlowTest {
9+
public static void main(String[] args) {
10+
try (SubmissionPublisher<String> publisher = new SubmissionPublisher<>()) {
11+
publisher.subscribe(new MySubscriber());
12+
13+
IntStream.range(0, 15)
14+
.mapToObj(String::valueOf)
15+
.forEach(publisher::submit);
16+
}
17+
}
18+
}
19+
20+
class MySubscriber implements Subscriber<String> {
21+
@Override
22+
public void onComplete() {
23+
System.out.println("Completed");
24+
}
25+
26+
@Override
27+
public void onError(Throwable err) {
28+
System.out.println("Error: " + err.getMessage());
29+
}
30+
31+
@Override
32+
public void onNext(String item) {
33+
System.out.println("Next: " + item);
34+
}
35+
36+
@Override
37+
public void onSubscribe(Subscription subscription) {
38+
System.out.println("Subscribed, requesting 10 items...");
39+
subscription.request(10);
40+
}
41+
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module J9NewFeatures {
2+
requires jdk.incubator.httpclient;
3+
}

0 commit comments

Comments
 (0)