Skip to content

Commit 1ea362f

Browse files
committed
Add two new modules: <module>core-java-11-2</module> to project
1 parent 1bcd3a1 commit 1ea362f

39 files changed

Lines changed: 2205 additions & 0 deletions
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Core Java 11
2+
3+
This module contains articles about Java 11 core features
4+
5+
### Relevant articles
6+
- [Guide to Java 8 Optional](https://www.baeldung.com/java-optional)
7+
- [Guide to Java Reflection](http://www.baeldung.com/java-reflection)
8+
- [Guide to Java 8’s Collectors](https://www.baeldung.com/java-8-collectors)
9+
- [New Features in Java 11](https://www.baeldung.com/java-11-new-features)
10+
- [Getting the Java Version at Runtime](https://www.baeldung.com/get-java-version-runtime)
11+
- [Invoking a SOAP Web Service in Java](https://www.baeldung.com/java-soap-web-service)
12+
- [Java HTTPS Client Certificate Authentication](https://www.baeldung.com/java-https-client-certificate-authentication)
13+
- [Call Methods at Runtime Using Java Reflection](https://www.baeldung.com/java-method-reflection)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<artifactId>core-java-11-2</artifactId>
7+
<version>0.1.0-SNAPSHOT</version>
8+
<name>core-java-11-2</name>
9+
<packaging>jar</packaging>
10+
11+
<parent>
12+
<groupId>com.ossez.core-java-modules</groupId>
13+
<artifactId>core-java-modules</artifactId>
14+
<version>0.0.2-SNAPSHOT</version>
15+
</parent>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>com.google.guava</groupId>
20+
<artifactId>guava</artifactId>
21+
<version>${guava.version}</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.mock-server</groupId>
25+
<artifactId>mockserver-junit-jupiter</artifactId>
26+
<version>${mockserver.version}</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.apache.commons</groupId>
30+
<artifactId>commons-lang3</artifactId>
31+
<version>${commons-lang3.version}</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>jakarta.xml.ws</groupId>
35+
<artifactId>jakarta.xml.ws-api</artifactId>
36+
<version>${jakarta.ws-api.version}</version>
37+
</dependency>
38+
</dependencies>
39+
40+
<build>
41+
<plugins>
42+
<plugin>
43+
<groupId>org.apache.maven.plugins</groupId>
44+
<artifactId>maven-compiler-plugin</artifactId>
45+
<version>${maven-compiler-plugin.version}</version>
46+
<configuration>
47+
<source>${maven.compiler.source.version}</source>
48+
<target>${maven.compiler.target.version}</target>
49+
</configuration>
50+
</plugin>
51+
<!-- jax-ws maven plugin -->
52+
<plugin>
53+
<groupId>com.sun.xml.ws</groupId>
54+
<artifactId>jaxws-maven-plugin</artifactId>
55+
<version>${jaxws-maven-plugin.version}</version>
56+
<configuration>
57+
<wsdlUrls>
58+
<wsdlUrl>http://localhost:8888/ws/country?wsdl</wsdlUrl>
59+
</wsdlUrls>
60+
<keep>true</keep>
61+
<packageName>com.baeldung.soap.ws.client.generated</packageName>
62+
<sourceDestDir>src/main/java</sourceDestDir>
63+
</configuration>
64+
</plugin>
65+
</plugins>
66+
</build>
67+
68+
<properties>
69+
<maven.compiler.source.version>11</maven.compiler.source.version>
70+
<maven.compiler.target.version>11</maven.compiler.target.version>
71+
<mockserver.version>5.11.1</mockserver.version>
72+
<jakarta.ws-api.version>3.0.1</jakarta.ws-api.version>
73+
<jaxws-maven-plugin.version>3.0.2</jaxws-maven-plugin.version>
74+
</properties>
75+
76+
</project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.baeldung.features;
2+
3+
public class MainClass {
4+
5+
private static boolean mainPrivateMethod() {
6+
return true;
7+
}
8+
9+
public static class NestedClass {
10+
11+
boolean nestedPublicMethod() {
12+
return mainPrivateMethod();
13+
}
14+
15+
}
16+
17+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.baeldung.httpsclientauthentication;
2+
3+
import java.io.BufferedInputStream;
4+
import java.io.BufferedOutputStream;
5+
import java.io.IOException;
6+
import java.io.InputStream;
7+
import java.io.OutputStream;
8+
9+
import javax.net.SocketFactory;
10+
import javax.net.ssl.SSLSocket;
11+
import javax.net.ssl.SSLSocketFactory;
12+
13+
public class SSLScocketClient {
14+
15+
static void startClient(String host, int port) throws IOException {
16+
17+
SocketFactory factory = SSLSocketFactory.getDefault();
18+
19+
try (SSLSocket socket = (SSLSocket) factory.createSocket(host, port)) {
20+
socket.setEnabledCipherSuites(new String[] { "TLS_AES_128_GCM_SHA256" });
21+
socket.setEnabledProtocols(new String[] { "TLSv1.3" });
22+
InputStream is = new BufferedInputStream(socket.getInputStream());
23+
String message = "Hello World Message";
24+
System.out.println("sending message: " + message);
25+
OutputStream os = new BufferedOutputStream(socket.getOutputStream());
26+
os.write(message.getBytes());
27+
os.flush();
28+
byte[] data = new byte[2048];
29+
int len = is.read(data);
30+
if (len <= 0) {
31+
throw new IOException("no data received");
32+
}
33+
System.out.printf("client received %d bytes: %s%n", len, new String(data, 0, len));
34+
}
35+
}
36+
37+
public static void main(String[] args) throws IOException {
38+
39+
startClient("localhost", 8443);
40+
}
41+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.baeldung.httpsclientauthentication;
2+
3+
import java.io.BufferedInputStream;
4+
import java.io.BufferedOutputStream;
5+
import java.io.IOException;
6+
import java.io.InputStream;
7+
import java.io.OutputStream;
8+
import java.net.Socket;
9+
10+
import javax.net.ServerSocketFactory;
11+
import javax.net.ssl.SSLServerSocket;
12+
import javax.net.ssl.SSLServerSocketFactory;
13+
14+
public class SSLSocketEchoServer {
15+
16+
static void startServer(int port) throws IOException {
17+
18+
ServerSocketFactory factory = SSLServerSocketFactory.getDefault();
19+
20+
try (SSLServerSocket listener = (SSLServerSocket) factory.createServerSocket(port)) {
21+
listener.setNeedClientAuth(true);
22+
listener.setEnabledCipherSuites(new String[] { "TLS_AES_128_GCM_SHA256" });
23+
listener.setEnabledProtocols(new String[] { "TLSv1.3" });
24+
System.out.println("listening for messages...");
25+
try (Socket socket = listener.accept()) {
26+
InputStream is = new BufferedInputStream(socket.getInputStream());
27+
OutputStream os = new BufferedOutputStream(socket.getOutputStream());
28+
byte[] data = new byte[2048];
29+
int len = is.read(data);
30+
if (len <= 0) {
31+
throw new IOException("no data received");
32+
}
33+
String message = new String(data, 0, len);
34+
System.out.printf("server received %d bytes: %s%n", len, message);
35+
String response = message + " processed by server";
36+
os.write(response.getBytes(), 0, response.getBytes().length);
37+
os.flush();
38+
}
39+
System.out.println("message processed, exiting");
40+
}
41+
}
42+
43+
public static void main(String[] args) throws IOException {
44+
startServer(8443);
45+
}
46+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung.optional;
2+
3+
public class Modem {
4+
private Double price;
5+
6+
public Modem(Double price) {
7+
this.price = price;
8+
}
9+
10+
public Double getPrice() {
11+
return price;
12+
}
13+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.baeldung.optional;
2+
3+
import java.util.List;
4+
import java.util.Optional;
5+
import java.util.stream.Collectors;
6+
7+
public class Person {
8+
private String name;
9+
private int age;
10+
private String password;
11+
12+
public Person(String name, int age) {
13+
this.name = name;
14+
this.age = age;
15+
}
16+
17+
public Optional<String> getName() {
18+
return Optional.ofNullable(name);
19+
}
20+
21+
public void setName(String name) {
22+
this.name = name;
23+
}
24+
25+
public Optional<Integer> getAge() {
26+
return Optional.of(age);
27+
}
28+
29+
public void setAge(int age) {
30+
this.age = age;
31+
}
32+
33+
public void setPassword(String password) {
34+
this.password = password;
35+
}
36+
37+
public Optional<String> getPassword() {
38+
return Optional.ofNullable(password);
39+
}
40+
41+
public static List<Person> search(List<Person> people, String name, Optional<Integer> age) {
42+
// Null checks for people and name
43+
return people.stream()
44+
.filter(p -> p.getName().equals(name))
45+
.filter(p -> p.getAge().get() >= age.orElse(0))
46+
.collect(Collectors.toList());
47+
}
48+
49+
public static List<Person> search(List<Person> people, String name, Integer age) {
50+
// Null checks for people and name
51+
final Integer ageFilter = age != null ? age : 0;
52+
53+
return people.stream()
54+
.filter(p -> p.getName().equals(name))
55+
.filter(p -> p.getAge().get() >= ageFilter)
56+
.collect(Collectors.toList());
57+
}
58+
59+
public static List<Person> search(List<Person> people, String name) {
60+
return doSearch(people, name, 0);
61+
}
62+
63+
public static List<Person> search(List<Person> people, String name, int age) {
64+
return doSearch(people, name, age);
65+
}
66+
67+
private static List<Person> doSearch(List<Person> people, String name, int age) {
68+
// Null checks for people and name
69+
return people.stream()
70+
.filter(p -> p.getName().equals(name))
71+
.filter(p -> p.getAge().get().intValue() >= age)
72+
.collect(Collectors.toList());
73+
}
74+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.reflection;
2+
3+
public abstract class Animal implements Eating {
4+
5+
public static final String CATEGORY = "domestic";
6+
7+
private String name;
8+
9+
public Animal(String name) {
10+
this.name = name;
11+
}
12+
13+
public String getName() {
14+
return name;
15+
}
16+
17+
public void setName(String name) {
18+
this.name = name;
19+
}
20+
21+
protected abstract String getSound();
22+
23+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.baeldung.reflection;
2+
3+
public class Bird extends Animal {
4+
private boolean walks;
5+
6+
public Bird() {
7+
super("bird");
8+
}
9+
10+
public Bird(String name, boolean walks) {
11+
super(name);
12+
setWalks(walks);
13+
}
14+
15+
public Bird(String name) {
16+
super(name);
17+
}
18+
19+
@Override
20+
public String eats() {
21+
return "grains";
22+
}
23+
24+
@Override
25+
protected String getSound() {
26+
return "chaps";
27+
}
28+
29+
public boolean walks() {
30+
return walks;
31+
}
32+
33+
public void setWalks(boolean walks) {
34+
this.walks = walks;
35+
}
36+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.reflection;
2+
3+
import java.lang.annotation.Annotation;
4+
5+
public class DynamicGreeter implements Greeter {
6+
7+
private String greet;
8+
9+
public DynamicGreeter(String greet) {
10+
this.greet = greet;
11+
}
12+
13+
@Override
14+
public Class<? extends Annotation> annotationType() {
15+
return DynamicGreeter.class;
16+
}
17+
18+
@Override
19+
public String greet() {
20+
return greet;
21+
}
22+
23+
}

0 commit comments

Comments
 (0)