-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
60 lines (42 loc) · 1.9 KB
/
Main.java
File metadata and controls
60 lines (42 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package java21;
import java21.records.RecordPatternsWithInstanceof;
import java21.virtualthreads.ExecutorImpl;
import java21.virtualthreads.ThreadOfVirtualImpl;
import java.util.Locale;
//import static java.util.FormatProcessor.FMT;
public class Main {
public static void main(String[] args) {
var product = new Product(1L, "Laptop", 1000.0);
// Concatenation using + operator
var string1 = "Product with id " + product.productId() + " is " +
product.name() + " and has price $" + product.price();
System.out.println(string1);
// Concatenation using StringBuilder
var string2 = new StringBuilder()
.append("Product with id ")
.append(product.productId())
.append(" is ")
.append(product.name())
.append(" and has price $")
.append(product.price())
.toString();
System.out.println(string2);
// Concatenation using String.format
var string3 = String.format(Locale.US,
"Product with id %s is %s" +
" and has price $%.2f",
product.productId(), product.name(), product.price());
System.out.println(string3);
//var string4 = FMT."Product is \{product.productId()}: \{product.name()}, priced at $%.2f\{product.price()}";
//System.out.println(string4);
// testing "sequenced collections" feature
CollectionSequences.testCollectionSequences();
// testing "record" with pattern matching in if-construct
RecordPatternsWithInstanceof.test();
// testing Executors.newVirtualThreadPerTaskExecutor
ExecutorImpl.withVirtualThreadsInJava21(); // high performance
//ExecutorImpl.withoutVirtualThreads(); // quite slower
// testing Thread.ofVirtual()
ThreadOfVirtualImpl.main(null);
}
}