Skip to content

Commit 67b38ef

Browse files
committed
jep138
1 parent 6db936f commit 67b38ef

File tree

5 files changed

+108
-32
lines changed

5 files changed

+108
-32
lines changed
Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,7 @@
11
package com.mkyong.java11;
22

3-
import java.nio.charset.StandardCharsets;
4-
import java.security.*;
5-
import java.security.spec.InvalidKeySpecException;
6-
import java.security.spec.NamedParameterSpec;
7-
import java.security.spec.PKCS8EncodedKeySpec;
8-
import java.security.spec.X509EncodedKeySpec;
9-
import java.util.Base64;
10-
113
public class Main {
12-
13-
public static void main(String[] args) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeySpecException {
14-
15-
KeyPairGenerator kpg = KeyPairGenerator.getInstance("XDH");
16-
NamedParameterSpec paramSpec = new NamedParameterSpec("X25519");
17-
kpg.initialize(paramSpec); // equivalent to kpg.initialize(255)
18-
// alternatively: kpg = KeyPairGenerator.getInstance("X25519")
19-
KeyPair kp = kpg.generateKeyPair();
20-
21-
/*KeyPairGenerator kpg = KeyPairGenerator.getInstance("X25519");
22-
KeyPair kp = kpg.generateKeyPair();
23-
24-
PublicKey publicKey = kp.getPublic();
25-
26-
System.out.println(publicKey.getAlgorithm());
27-
System.out.println(publicKey.getFormat());
28-
System.out.println(new String(publicKey.getEncoded(), StandardCharsets.UTF_8));
29-
30-
PrivateKey privateKey = kp.getPrivate();
31-
32-
System.out.println(privateKey.getAlgorithm());
33-
System.out.println(privateKey.getFormat());*/
34-
4+
public static void main(String[] args) {
5+
System.out.println("Hello Java 11");
356
}
36-
377
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.mkyong.java11.jep327;
2+
3+
public class PrintUnicode {
4+
5+
public static void main(String[] args) {
6+
String codepoint = "U+1F92A";
7+
System.out.println(convertCodePoints(codepoint));
8+
}
9+
10+
// Java, UTF-16
11+
// Convert code point to unicode
12+
static char[] convertCodePoints(String codePoint) {
13+
Integer i = Integer.valueOf(codePoint.substring(2), 16);
14+
char[] chars = Character.toChars(i);
15+
return chars;
16+
17+
}
18+
19+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.mkyong.java11.jep327;
2+
3+
// https://stackoverflow.com/questions/18380901/how-do-i-convert-unicode-codepoints-to-their-character-representation
4+
public class PrintUnicode2 {
5+
6+
public static void main(String[] args) {
7+
8+
printCodePoints("U+0041"); // Latin capital A
9+
printCodePoints("U+20BF"); // Bitcoin icon = ₿
10+
printCodePoints("U+32C0"); // January in Chinese = ㋀
11+
printCodePoints("U+1F929"); // emoji 🤩
12+
13+
printCodePoints("U+4F60");
14+
15+
// convert Unicode code points
16+
//String codePoints = "U+20BF"; // Bitcoin icon = ₿
17+
18+
String codePoints = "U+1F929"; // Bitcoin icon = ₿
19+
Integer i = Integer.valueOf(codePoints.substring(2), 16);
20+
System.out.println(i); // 8383
21+
22+
// Unicode in UTF-16 encoding
23+
char[] unicode16 = Character.toChars(i);
24+
System.out.println(unicode16);
25+
26+
String s = Character.toString(i);
27+
28+
// convert Unicode in UTF-16 to Unicode code points
29+
if(Character.isBmpCodePoint(i)){
30+
String hex = Integer.toHexString(i);
31+
System.out.println(String.format("U+%S", hex));
32+
}else{
33+
// Supplementary code point
34+
int supCodePoints = Character.toCodePoint(unicode16[0], unicode16[1]);
35+
String hex = Integer.toHexString(supCodePoints);
36+
System.out.println(String.format("U+%S", hex));
37+
}
38+
}
39+
40+
static void printCodePoints(String codePoint) {
41+
Integer i = Integer.valueOf(codePoint.substring(2), 16);
42+
char[] chars = Character.toChars(i);
43+
System.out.println(chars);
44+
}
45+
46+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.mkyong.java11.jep328;
2+
3+
import java.util.concurrent.*;
4+
5+
public class MemoryLeak {
6+
7+
private static BlockingQueue<byte[]> queue = new LinkedBlockingQueue<>(10);
8+
9+
public static void main(String[] args) {
10+
11+
Runnable producer = () -> {
12+
while (true) {
13+
// generates 1mb of object every 10ms
14+
queue.offer(new byte[1 * 1024 * 1024]);
15+
try {
16+
TimeUnit.MILLISECONDS.sleep(10);
17+
} catch (InterruptedException e) {
18+
e.printStackTrace();
19+
}
20+
}
21+
};
22+
23+
Runnable consumer = () -> {
24+
while (true) {
25+
try {
26+
// process every 100ms
27+
queue.take();
28+
TimeUnit.MILLISECONDS.sleep(100);
29+
} catch (InterruptedException e) {
30+
e.printStackTrace();
31+
}
32+
}
33+
};
34+
35+
// give a name, good for profiling
36+
new Thread(producer, "Producer Thread").start();
37+
new Thread(consumer, "Consumer Thread").start();
38+
39+
}
40+
41+
}
3.2 MB
Binary file not shown.

0 commit comments

Comments
 (0)