Java 10 Features

1. πŸ”ΉΒ Local Variable Type Inference (var)

Description: Allows you to declare local variables using var, letting the compiler infer the type.

Example:

var name = "Java";          // inferred as String
var count = 10;             // inferred as int
var list = List.of("A", "B", "C"); // inferred as List<String>

πŸ”Έ Only for local variables (not class members, parameters, or return types).


2. πŸ”Ή Unmodifiable Collectors

Improvement in Collectors.toUnmodifiableList(), Set, and Map.

Example:

var list = List.of("A", "B", "C");
var unmodifiableList = list.stream()
                           .collect(Collectors.toUnmodifiableList());

Trying to modify the list will throw UnsupportedOperationException.


3. πŸ”Ή Optional.orElseThrow() Without Arguments

Description: Simplified way to throw NoSuchElementException if value is not present.

Example:

Optional<String> name = Optional.of("Java");
System.out.println(name.orElseThrow()); // no args needed

4. πŸ”Ή Application Class-Data Sharing (AppCDS)

Benefit: Reduces JVM startup time and memory footprint by sharing common class metadata across JVMs.

Use Case: Large-scale Java applications and microservices.

πŸ›  Requires specific setup with -Xshare:on.


5. πŸ”Ή G1 Garbage Collector Improvements

Description: G1 GC now supports full parallel compaction β€” improving pause times.


6. πŸ”Ή Root Certificates Included

Java 10 comes with a default set of root SSL certificates, improving out-of-the-box security for HTTPS connections.


7. πŸ”Ή Thread-Local Handshakes

A new JVM mechanism to allow fine-grained pausing of threads for diagnostics and memory management.

πŸ” More efficient than global safepoints.


8. πŸ”Ή Heap Allocation on Alternative Memory Devices

Supports systems with multi-tiered memory (e.g., DRAM + NVDIMM), allowing Java to allocate heap memory selectively.

Useful for large-scale enterprise deployments.


9. πŸ”Ή Experimental Java-Based JIT Compiler (Graal)

You can use Graal as an experimental JIT compiler with the JVM:

java -XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler ...

πŸ”š Summary Table

Feature Benefit
var for local variables Cleaner syntax, type inference
Unmodifiable collectors Immutable collections
Optional.orElseThrow() Simplified null-checks
AppCDS Faster startup, reduced memory
G1 GC enhancements Shorter pause times
Root certificates Secure HTTPS out-of-the-box
Thread-local handshakes Better diagnostics, perf
Heap on alternative memory Efficient memory usage
Graal JIT compiler Performance tuning


Back to blog

Leave a comment

Please note, comments need to be approved before they are published.