Java 21 API New Features

  Рет қаралды 40,302

Java

Java

Күн бұрын

Learn about the many enhancements that Java 21 is giving you in the classes you are using every day.
Java 21 is introducing several major new features: virtual threads and pattern matching. But it also brings new many small additions to classes that you are using every day, and that you can leverage from day one. This video covers the most important ones: the String class, regular expressions, the Collections framework, some additions in Java I/O, the Math class, and, as a bonus some important deprecations you need to be aware of.
⎯⎯⎯⎯⎯⎯ Chapters ⎯⎯⎯⎯⎯⎯
0:00 Intro
1:18 New methods on String, Character, StringBuilder and StringBuffer
2:34 Naming your capturing groups in regular expressions
4:01 Additions to the Collections framework
6:22 Localization in the Date and Time API
6:53 Additions to the Java I/O API
7:49 Using AutoCloseable with HttpClient, ExecutorService, and ForkJoinPool
9:29 Additions to the Math class
11:25 Multiplying BigIntegers in parallel
12:00 Additions to the Thread class
13:25 Additions to the Future interface
14:45 Deprecation of finalize()
15:42 Deprecation of the constructors of the wrapper classes
16:20 Outro
⎯⎯⎯⎯⎯⎯ Resources ⎯⎯⎯⎯⎯⎯
◦ Full #RoadTo21 Playlist ➱ • Road to 21
◦ Java 21 New Feature: Virtual Threads ➱ • Java 21 new feature: V...
◦ Java 21 New Feature: Sequenced Collections - JEP Cafe #19 ➱ • Java 21 New Feature: S...
◦ The JEP 444: Virtual Threads ➱ openjdk.org/je...
◦ The JEP 431: Sequenced Collections ➱ openjdk.org/je...
Tags: #Java #Java21 #Tools #OpenJDK

Пікірлер: 82
@java
@java 11 ай бұрын
We got 2:34 wrong. Named groups in regular expressions are supported since Java 7. What's new (in 20) is that the methods related to named groups moved up the dependency tree from `Matcher` to the interface `MatchResult`.
@zoladkow
@zoladkow 9 ай бұрын
no worries, everyone here knows the vids are just about coffee sipping with some words inbetween 😁
@brandpcalderon5343
@brandpcalderon5343 6 ай бұрын
i was going to complain the same, named groups are allowed since I learnt regex like 3 years ago and more I suppose
@OzoneGrif
@OzoneGrif 5 ай бұрын
Yeah I was really confused about this. Was going to comment the same thing. Brain fart !
@onebeartoe
@onebeartoe 11 ай бұрын
Thanks! I cant wait for the named String groupings to help parse flat files.
@YvesDautremay
@YvesDautremay 11 ай бұрын
Thanks for the overview ! A few nice things that may be shadowed by virtual threads
@JosePaumard
@JosePaumard 11 ай бұрын
Thank you!
@Talaria.School
@Talaria.School 11 ай бұрын
Great topics I had to comment and thumbs up. Thanks a lot José.
@JosePaumard
@JosePaumard 11 ай бұрын
Thank you Khaled!
@boyneverstop
@boyneverstop 11 ай бұрын
Thank you for making this video! Very useful
@JosePaumard
@JosePaumard 11 ай бұрын
Thank you!
@1gmar
@1gmar 11 ай бұрын
Apologies, isn't the feature mentioned at 2:34 already available since Java 7?
@mikolajpodbielski
@mikolajpodbielski 11 ай бұрын
Yes, it is.
@christofferhammarstrom
@christofferhammarstrom 11 ай бұрын
What is new in Java 20 though, is that MatchResult now supports named groups. Perhaps there was a mixup here.
@JosePaumard
@JosePaumard 11 ай бұрын
You're absolutely right. What has been done in 20 is that the methods are now available on MatchResult (interface implemented by the Matcher class), along with some others. I should have mentionned namedGroup() also.
@OriginGaming101
@OriginGaming101 Ай бұрын
Came here for Java, stayed for their use of my favourite local cafe in the background! 😂
@codeZarathustra
@codeZarathustra 11 ай бұрын
Good explanation Sr! Thank very much!
@JosePaumard
@JosePaumard 11 ай бұрын
Thank you!
@nO_d3N1AL
@nO_d3N1AL 10 ай бұрын
Really appreciate this format of doing updates. Also a cool idea: the amount of coffee left in the cup should match the progress of the video ;) Also thankful that new APIs and methods aren't using checked exceptions! 🎉
@JosePaumard
@JosePaumard 10 ай бұрын
Well it does ;) This is real coffee that I drink during the recording.
@nO_d3N1AL
@nO_d3N1AL 10 ай бұрын
@@JosePaumard Cool! I bet it's actual Java coffee too ;)
@JosePaumard
@JosePaumard 10 ай бұрын
@@nO_d3N1AL Oh yes it is! 😊
@mortensen117
@mortensen117 11 ай бұрын
So, named groups, which arrived in Java SE 7, is now suddenly something new? If you could write the name of the group in some meaningfull way without of a lot a string gymnastics, then there would be some thing new.
@JosePaumard
@JosePaumard 11 ай бұрын
What is new is that the methods are now also on the interface.
@svalyavasvalyava9867
@svalyavasvalyava9867 11 ай бұрын
Awesome video, thank you ☺️
@ajaythombare6235
@ajaythombare6235 10 ай бұрын
thank you for valuable information sir... btw I like ur coffee cup
@Speiger
@Speiger 11 ай бұрын
IMO the state enum is missing something. "CREATED" or "UNSTARTED", because there is no way to track if a task was already started or not. Which is useful if you have a queue of tasks that are expensive and you want to cut basically anything that isn't started yet, and you didn't expose the Queue itself. Unless state returns null if it isn't started yet, then i take that back.
@pravinjain2834
@pravinjain2834 11 ай бұрын
I fully agree, currently it seems they put the state as RUNNING as soon as the task is submitted. probably it is being thought that since we can have virtual threads, the number of threads in the pool will be more and no task will be waiting to get started. but for tasks which are computative (no blocking activity), one may not like to use virtual threads. In any case you are right, that state has been missed.
@jeromemainaud
@jeromemainaud 4 ай бұрын
3:59 With large patterns in a multiline string, instead of using backslashes you can also use the COMMENT flag. This will be more readable.
@hephestos300
@hephestos300 5 ай бұрын
after what JDK will be the whole lambda as was introduced in JDK8 deprecated and ousted ? Can't wait the moment
@si2001si
@si2001si 7 ай бұрын
Hi Jose, Big Fan!! Your Coffee looks yum
@oifbert
@oifbert 2 ай бұрын
What's new about pattern matching? Named groups have existed for years.
@TheNeoxpert
@TheNeoxpert 11 ай бұрын
08:44 close() method will be called no matter what? what if there is System.exit(0); in the try block?
@JosePaumard
@JosePaumard 11 ай бұрын
Nope, not in that case. If what you need is to kill your JVM as fast as possible, taking the time to execute all your close(), finalize(), etc... would probably be a mistake,
@danthe1st
@danthe1st 11 ай бұрын
Shouldn't it be "Charset" instead of "CharSet" in 7:09?
@muzzletov
@muzzletov 11 ай бұрын
CharSet is just short for Character Set. So, no, it shouldnt.But yes, the class is called Charset, which feels wrong :D
@danthe1st
@danthe1st 11 ай бұрын
@@muzzletov If the JDK calls it Charset, it is Charset and not CharSet. And honestly, I would consider charset to be its own (atomic) word and (at least in the context of Java,) it isn't really a set of characters.
@JosePaumard
@JosePaumard 11 ай бұрын
It should. Thank you for pointing it out!
@RishiRajxtrim
@RishiRajxtrim 29 күн бұрын
🎉
@ClydeXT
@ClydeXT 10 ай бұрын
In your example at 7:15, your types should be "byte[]" instead if "int[]"
@zoladkow
@zoladkow 9 ай бұрын
ahh... certainly too much coffee 🙃
@rishiraj2548
@rishiraj2548 2 ай бұрын
Thanks
@ahmadfx8962
@ahmadfx8962 11 ай бұрын
رائع
@edmaphis9805
@edmaphis9805 11 ай бұрын
Emoji methods !! Holy smokes !!
@radoandrey2268
@radoandrey2268 11 ай бұрын
Thank you
@computer_science10
@computer_science10 8 ай бұрын
thank you
@edmaphis9805
@edmaphis9805 11 ай бұрын
So Autoclosable is a functional interface?
@JosePaumard
@JosePaumard 11 ай бұрын
It is. I'm not sure that it will be very useful to implement it with a lambda though...
@edmaphis9805
@edmaphis9805 11 ай бұрын
Ok. class Closer { static void closing(Closeable closeable) throws Exception { System.out.println("Now closing: " + closeable.toString()); closeable.close(); } } class AClosable implements AutoCloseable { @Override public void close() throws Exception { System.out.println("I am closing"); } } public class CloseableDemo { public static void main(String[] args) throws Exception { var aclosable = new AClosable(); Closer.closing(() -> { try { aclosable.close(); } catch (Exception ex) { } }); } }
@edmaphis9805
@edmaphis9805 11 ай бұрын
@@JosePaumard Thanks, I tried anyhow. 😉
@JosePaumard
@JosePaumard 11 ай бұрын
@@edmaphis9805I'm not sure I would use this pattern in a real application 😉
@akaalkripal5724
@akaalkripal5724 10 ай бұрын
How's the coffee?
@JorgetePanete
@JorgetePanete 11 ай бұрын
I think close() should be called automatically when the object is no longer needed
@SourabhBhat
@SourabhBhat 11 ай бұрын
Wouldn't that cause the same problems as finalize?
@JorgetePanete
@JorgetePanete 11 ай бұрын
@@SourabhBhat At least if it's called at the end of the scope of the object I think there wouldn't be problems
@alessandroautiero5414
@alessandroautiero5414 11 ай бұрын
​​@@JorgetePanetein a method's scope that's probably easy enough (GoLang has the defer keyword for this use case pretty much), but how would you do it in the case of a field? It would have the same problems as the finalize method I'm pretty sure.
@JorgetePanete
@JorgetePanete 11 ай бұрын
@@alessandroautiero5414 I don't know, I just wish it was like Rust does
@mattidragon835
@mattidragon835 11 ай бұрын
@@JorgetePanete the reason rust can automatically close is it's strict borrowing and moving rules. In java you can move objects freely and rely on the GC to clean them up
@zenmony-dot-com7457
@zenmony-dot-com7457 11 ай бұрын
Pleasant coffee lounge atmosphere, perfect for learning.
@JoshuaMuzaaya
@JoshuaMuzaaya 8 ай бұрын
wow, all these have been in Erlang/OTP, Python, Elixir right at those languages' first version.
@kitkarson4226
@kitkarson4226 11 ай бұрын
Why do they pollute Character class with emoji methods 🤮? They could have made it as a separate util class .
@pravinjain2834
@pravinjain2834 11 ай бұрын
Yes, there could be a separate class for all the Unicode properties. There are still a lot of unicode properties not available in Java API (Character class).
@sneibarg
@sneibarg 11 ай бұрын
Naming capture groups is a super old feature of Python.
@Parkhill57
@Parkhill57 10 ай бұрын
piano in background still drives me crazy.
@mortensen117
@mortensen117 11 ай бұрын
AutoCloseable? Why are you presenting these OLD features as if they were new? Are you crazy?
@kitkarson4226
@kitkarson4226 11 ай бұрын
Watch it one more time. AutoCloseable is OLD. But now ExecutorService, HttpClient..etc also implement the interface. Thats what he says!
@JosePaumard
@JosePaumard 11 ай бұрын
It's not because it's old that it's not useful. With the deprecation of finalize(), AutoCloseable becomes more important. Thus the new classes that implement it. Keeping repeating old stuff is not a problem for me.
@nicholas1460
@nicholas1460 11 ай бұрын
You used var. Shame on you.
@JosePaumard
@JosePaumard 11 ай бұрын
Oh no, I love var.
@nicholas1460
@nicholas1460 11 ай бұрын
@@JosePaumard var var var var. Just for you. Quess what objects I'm using.
@JosePaumard
@JosePaumard 11 ай бұрын
@@nicholas1460 You don't need to use it everywhere. But there are still many places where it will make your code more readable.
@kitkarson4226
@kitkarson4226 11 ай бұрын
var is a great addition to java. I have been using for couple years now,
@khmarbaise
@khmarbaise 11 ай бұрын
var often shows that the variables names used are not good enough to transport the information. That lets me reconsider my names and make it better (hopefully ;-))
@Kjhd9987hy
@Kjhd9987hy 11 ай бұрын
What an old ugly mess language. I feel bad for android devs when they gota look at swift and swiftui
Project Leyden - Capturing Lightning in a Bottle #JVMLS
47:57
Java 21 new feature: Virtual Threads #RoadTo21
33:35
Java
Рет қаралды 60 М.
My Cheetos🍕PIZZA #cooking #shorts
00:43
BANKII
Рет қаралды 22 МЛН
Jumping off balcony pulls her tooth! 🫣🦷
01:00
Justin Flom
Рет қаралды 33 МЛН
Harley Quinn lost the Joker forever!!!#Harley Quinn #joker
00:19
Harley Quinn with the Joker
Рет қаралды 22 МЛН
Can A Seed Grow In Your Nose? 🤔
00:33
Zack D. Films
Рет қаралды 32 МЛН
Что нового в JDK 21
52:37
Уголок сельского джависта
Рет қаралды 8 М.
(Dirty?) Tricks in Java 22 - Inside Java Newscast #64
13:05
Java 21 Security Updates #RoadTo21
27:04
Java
Рет қаралды 7 М.
Java 21 Pattern Matching Tutorial #RoadTo21
23:28
Java
Рет қаралды 26 М.
Java 21 Is Good?! | Prime Reacts
27:08
ThePrimeTime
Рет қаралды 228 М.
New Java Version 22 - The 3 Best New Features You'll ACTUALLY Use
13:15
Coding with John
Рет қаралды 103 М.
Andrew Kelley   Practical Data Oriented Design (DoD)
46:40
ChimiChanga
Рет қаралды 74 М.
Какой ноутбук взять для учёбы? #msi #rtx4090 #laptop #юмор #игровой #apple #shorts
0:18