Category : Java | Sub Category : Java 10 features | By Prasad Bonam Last updated: 2023-08-09 07:43:47 Viewed : 303
here are some Java 10 features with examples to help illustrate their usage:
Local-Variable Type Inference (var):
javavar name = "John"; // Inferred as String
var numbers = List.of(1, 2, 3); // Inferred as List<Integer>
Application Class-Data Sharing:
bash# Create an archive of class data
$ java -Xshare:dump
# Use the archived class data at startup
$ java -Xshare:on -jar MyApp.jar
Time-Based Release Versioning:
bash$ java -version
openjdk version "10" 2018-03-20
Parallel Full GC for G1:
bash$ java -XX:+UseG1GC -XX:+UseParallelGC -jar MyApp.jar
Thread-Local Handshakes:
javaThread.currentThread().registerOnThreadLocalHandshake(() -> {
// Code to execute during the handshake
System.out.println("Thread-local handshake executed.");
});
Additional Unicode Language-Tag Extensions:
javaLocale locale = Locale.forLanguageTag("en-u-ca-chinese");
System.out.println(locale.getUnicodeLocaleAttributes()); // Output: [chinese]
Heap Allocation on Alternative Memory Devices:
bash$ java -XX:AllocateHeapAt=non-volatile-memory -jar MyApp.jar
Thread-Local Random Number Generator:
javaint randomInt = ThreadLocalRandom.current().nextInt(1, 100);
Please note that while these examples provide a basic understanding of the Java 10 features, some features may require specific runtime options or additional configuration. For comprehensive details and advanced usage, refer to the official Java documentation and resources for Java 10.