Skip to content

Commit e7dd080

Browse files
committed
added more examples of Java 9 and 10
1 parent 69d9f4d commit e7dd080

File tree

11 files changed

+85
-9
lines changed

11 files changed

+85
-9
lines changed

java-10/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-10-new-features</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<packaging>jar</packaging>
8+
9+
<dependencies>
10+
</dependencies>
11+
12+
<build>
13+
<finalName>java-10-new-features</finalName>
14+
</build>
15+
16+
<properties>
17+
<maven.compiler.source>10</maven.compiler.source>
18+
<maven.compiler.target>10</maven.compiler.target>
19+
<failOnMissingWebXml>false</failOnMissingWebXml>
20+
</properties>
21+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.github.wesleyegberto.collections;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
import java.util.Map;
6+
import java.util.Set;
7+
8+
public class CollectionsCopyOf {
9+
public static void main(String[] args) {
10+
List<String> muttableList = Arrays.asList("New", "Method", "To", "Copy");
11+
12+
// Copy methods
13+
List<String> immutableList = List.copyOf(muttableList);
14+
immutableList.forEach(System.out::println);
15+
16+
Set<String> immutableSet = Set.copyOf(muttableList);
17+
immutableSet.forEach(System.out::println);
18+
19+
Map<String, String> immutableMap = Map.copyOf(Map.of("k1", "v1", "k2", "v2"));
20+
immutableMap.forEach((key, value) -> System.out.println(key + " = " + value));
21+
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.github.wesleyegberto.collections;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
import java.util.function.Function;
6+
import java.util.stream.Collectors;
7+
8+
public class CollectionsFromStream {
9+
public static void main(String[] args) {
10+
List<String> list = List.of("Testing", "Immutable", "List", "From", "Stream");
11+
12+
List<String> immutableList = list.stream()
13+
.collect(Collectors.toUnmodifiableList());
14+
immutableList.forEach(System.out::println);
15+
16+
Map<String, Integer> wordsLengths = list.stream()
17+
.collect(Collectors.toUnmodifiableMap(Function.identity(), word -> word.length()));
18+
wordsLengths.forEach((word, length) -> System.out.println(word + " -> " + length + " letters"));
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.github.wesleyegberto.process;
2+
3+
import java.lang.management.ManagementFactory;
4+
import java.lang.management.RuntimeMXBean;
5+
6+
public class ProcessTest {
7+
public static void main(String[] args) {
8+
final RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
9+
final long pid = runtime.getPid();
10+
System.out.println("Process ID is: " + pid);
11+
}
12+
}

java-8/src/main/java/com/github/wesleyegberto/map/StreamMapTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import java.util.*;
44
import java.util.stream.Stream;
55
import java.util.function.Function; // map operations -> transformations
6-
import com.github.wesleyegberto.model.*;
6+
7+
import com.github.wesleyegberto.model.Person;
8+
import com.github.wesleyegberto.model.Warrior;
79

810
public class StreamMapTest {
911

java-8/src/main/java/com/github/wesleyegberto/model/Warrior.java

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.github.wesleyegberto.model;
22

3-
import java.util.*;
4-
53
public class Warrior {
64
private Person person;
75
private String type;

java-9/others-features/build_run.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ mkdir -p $JAR_DIR
88

99
$JAVA9_HOME/bin/javac -p jdk.incubator.httpclient -d $CLASSES_DIR --module-version 1.0 `find src/main/java -name *.java`
1010

11-
# --main-class com.github.wesleyegberto.httpclient.HttpClientTest \
11+
# --main-class HttpClientTest \
1212
$JAVA9_HOME/bin/jar -c -f $JAR_DIR/http-client-test.jar \
13-
--main-class com.github.wesleyegberto.collections.CollectionsTest \
13+
--main-class CollectionsCopyOf.CollectionsTest \
1414
-C $CLASSES_DIR .
1515

1616

java-9/others-features/src/main/java/com/github/wesleyegberto/collections/CollectionsTest.java renamed to java-9/others-features/src/main/java/com/github/wesleyegberto/collections/collections/CollectionsTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.wesleyegberto.collections;
1+
package com.github.wesleyegberto.collections.collections;
22

33
import java.util.List;
44
import java.util.Map;

java-9/others-features/src/main/java/com/github/wesleyegberto/httpclient/HttpClientTest.java renamed to java-9/others-features/src/main/java/com/github/wesleyegberto/collections/httpclient/HttpClientTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.wesleyegberto.httpclient;
1+
package com.github.wesleyegberto.collections.httpclient;
22

33
import java.io.IOException;
44
import java.net.URI;

java-9/others-features/src/main/java/com/github/wesleyegberto/processapi/ProcessTest.java renamed to java-9/others-features/src/main/java/com/github/wesleyegberto/collections/processapi/ProcessTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.wesleyegberto.processapi;
1+
package com.github.wesleyegberto.collections.processapi;
22

33
import java.io.IOException;
44

java-9/others-features/src/main/java/com/github/wesleyegberto/reactive/FlowTest.java renamed to java-9/others-features/src/main/java/com/github/wesleyegberto/collections/reactive/FlowTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.wesleyegberto.reactive;
1+
package com.github.wesleyegberto.collections.reactive;
22

33
import java.util.concurrent.Flow.Subscriber;
44
import java.util.concurrent.Flow.Subscription;

0 commit comments

Comments
 (0)