Java 21 Features
- Anand Nerurkar
- Oct 9, 2024
- 1 min read
Following are some of Java 21 LTS features
==
1.String Template
Earliar we use to do concatation with string , but with this feature now we can have String Template cotaining embeded expression (evaluated at runtime). IT ay contain variable,methods,exrpession computed at runtime.
For Ex:
STR is String Template Processor which evalaute string conatining a varaible a.
2.unnamed patterns and varibales
==
we can skip the variable if it will be used in future.
for ex: try {}catch(Exception e)
e is the variable which will be used only if the exception is thrown.
we can make use of above feature here. use _ , no need to use variable e for exception.
unnamed classes and instance method
==
wrtie a java file-demo.java without class that include only method
==
void main(String[]){
sysout("This method is without class name");
|
4.sequencecollection : we can create sequencecollection now
5.record pattern
Virtual Threads
==
Lightweight threads help to write hightly throughput concurrent applications..
below example to use virtual thread.
.png)









Comments