Refactoring Java 8 code with Java 17 new features - JEP Café #9

Ғылым және технология

How to use the new features from Java 17, especially Records, to improve your Java 8 code. Do you need to make your code easier to understand without losing performance? This JEP Café shows you how to do it.
Submit your katas for more live coding like this one!
Tags: #Java #OpenJDK #Java17 #JDK #JDK17 #Record #Programming #JEPCafe #InsideJava
⎯⎯⎯⎯⎯⎯ Chapters ⎯⎯⎯⎯⎯⎯
0:00 Intro
1:02 Introducing the Haiku Katas
1:58 1st kata: finding all the letters used in a String
3:37 Comparing the performances
3:53 2nd kata: getting the top 3 most used letters
8:26 Solving the tie problem by inverting a map
12:28 Improving the code with Java 17 features: Records
20:30 Comparing the performances
21:16 3rd kata: partionning the words
22:54 Partionning the words in one pass
23:57 Comparing the performances
24:32 Outro
⎯⎯⎯⎯⎯⎯ Resources ⎯⎯⎯⎯⎯⎯
◦ Donald Raab Haiku Katas ➱ / haiku-for-java-using-t...
◦ JEP 395: Records ➱ openjdk.java.net/jeps/395
◦ The Eclipse Collections framework ➱ www.eclipse.org/collections/
◦ How to use JMH ➱ openjdk.java.net/projects/cod...
◦ JDK 17 ➱ openjdk.java.net/projects/jdk17
◦ Dev.java, The Destination for Java Developers ➱ dev.java/
◦ OpenJDK ➱ openjdk.java.net/
◦ Oracle Java ➱ www.oracle.com/java/

Пікірлер: 69

  • @svalyavasvalyava9867
    @svalyavasvalyava98672 жыл бұрын

    I like these videos sooo much. They are infinitely nice to watch. Thank you!

  • @java

    @java

    2 жыл бұрын

    Glad you like them!

  • @adrianperez8695
    @adrianperez86952 жыл бұрын

    Thank you for these recent series of videos on Java 17 features. I've shared them with my team to help us get up to speed on newer features.

  • @JosePaumard

    @JosePaumard

    2 жыл бұрын

    Thank you! Glad you like it!

  • @stevenpereira8537
    @stevenpereira85372 жыл бұрын

    Thanks for posting. Great explanation and breakdown!

  • @java

    @java

    2 жыл бұрын

    Glad you enjoyed it!

  • @pravinjain2834
    @pravinjain28342 жыл бұрын

    At 3:15, both the Kata and the JDK 17 solution have a common bug. the filtering will eliminate supplementary characters which may be alphabetic. The use of chars() method is the culprit, using codePoints() would be more correct. The surrogate range 0xd800 0xdfff, will always result in isAlphabetic returning false and will eliminate all the supplementary characters even if they are alphabetic.

  • @n_lisper

    @n_lisper

    10 ай бұрын

    Thanks for the info, didn’t know about this!

  • @thoaikieu5707

    @thoaikieu5707

    7 ай бұрын

    hello ! can you give me example supplementary characters which may be alphabetic.

  • @GercioP
    @GercioP2 жыл бұрын

    You are Magician of Java Streams 😄

  • @VisruthCV
    @VisruthCV2 жыл бұрын

    Very useful video, thanks for publishing!

  • @JosePaumard

    @JosePaumard

    2 жыл бұрын

    Thank you!

  • @VisruthCV

    @VisruthCV

    2 жыл бұрын

    @@JosePaumard Welcome

  • @youshasajjad5402
    @youshasajjad5402 Жыл бұрын

    Thanks for the videos. It will surely help me.

  • @bikramdhall1266
    @bikramdhall12662 жыл бұрын

    Sir, I am a big fan (as student) of you since couple of years . Thanks a lot.

  • @java

    @java

    2 жыл бұрын

    So nice of you!

  • @victorpinasarnault9135
    @victorpinasarnault91352 жыл бұрын

    Finally, java tutorials ❤

  • @hessenbenslima
    @hessenbenslima2 жыл бұрын

    Thank you so mush Mr. Paumard great presentation

  • @java

    @java

    2 жыл бұрын

    You are very welcome

  • @badpotato
    @badpotato2 жыл бұрын

    really good videos.. thanks.

  • @aswarthanarayanareddyb176
    @aswarthanarayanareddyb1762 жыл бұрын

    Awesome sir.

  • @artemmishin800
    @artemmishin8002 жыл бұрын

    Great 👍 thanks Jose))) best lessons!!

  • @java

    @java

    2 жыл бұрын

    Glad you liked it!

  • @fabricioaraujo7642
    @fabricioaraujo76422 жыл бұрын

    Thanks !

  • @MakeItStik
    @MakeItStik2 жыл бұрын

    Jose, We need such videos more frequently !

  • @java

    @java

    2 жыл бұрын

    We agree! Please stay tuned and hit the 🔔 to get notified. 😉

  • @nithinnambiar
    @nithinnambiar2 жыл бұрын

    Nice, Records can improve the readability a lot. It was little too fast for me as it takes some time to read the code and understand.

  • @olayemimichael3426
    @olayemimichael34262 жыл бұрын

    Thanks, Java is cool

  • @marcelmfa
    @marcelmfa Жыл бұрын

    Do you have any video showing how you did to get data benchmark data?

  • @HerbertLandei
    @HerbertLandei2 жыл бұрын

    I would avoid sorting entry streams, instead I would rather try to use a TreeMap with an appropriate comparator instead. If you need a sorted map, why not use one? Yes, it is more finicky to construct one using collectors etc., but you eliminate a whole step.

  • @yohanal33
    @yohanal332 жыл бұрын

    Good Job again

  • @canbariscan
    @canbariscan7 ай бұрын

    music gets real good at 19mins :)

  • @MT________
    @MT________ Жыл бұрын

    This would look so much nice in Java Xtend. Sadly though that language never really had a breakthrough.

  • @ericandresen680
    @ericandresen6802 жыл бұрын

    Holy cow that is a lot of code... Starting to use Go, and now i remember why :D

  • @MakeItStik

    @MakeItStik

    2 жыл бұрын

    Can you paste some Go code here for the 2nd problem - top occurrences (including case of tie as described) ? Will help in comparing. - you can mention a github link.

  • @ramdaneoualitsen1323
    @ramdaneoualitsen13232 жыл бұрын

    There is an issue with the ide. it is not in dark mode.

  • @alexhamilton4332
    @alexhamilton43322 жыл бұрын

    What does the us in us/op stand for?

  • @JosePaumard

    @JosePaumard

    2 жыл бұрын

    It's the symbol for micro seconds / operation. Usually ou write it "μs", but in many case the "mu" (greek letter) will not display correctly.

  • @rokkralj9786
    @rokkralj9786 Жыл бұрын

    There is a much simpler solution. 1. Group by letter to get counts Map, sort it by count 2. Get count of the third element in the list, store it into "int boundaryCount" 3. filter(), or even better takeWhile(), with a count >= boundaryCount. It should be no more than 5 lines of code.

  • @csvxmlfan3853
    @csvxmlfan38532 жыл бұрын

    Where can I get such a beautiful mug?

  • @EskilP
    @EskilP6 ай бұрын

    mmmhmm cold coffee 😛

  • @SLTRM
    @SLTRM2 жыл бұрын

    Snake case in class method names? Mmmm maybe too much pressure from rust lang? Je je je

  • @ClevertonHeusner
    @ClevertonHeusner2 жыл бұрын

    Nice. Now pour me a drink, please.

  • @java

    @java

    2 жыл бұрын

    Deal

  • @weho_brian
    @weho_brian2 жыл бұрын

    Java is still around? JavKidding

  • @aharonha
    @aharonha2 жыл бұрын

    Seems like someone in eclipse collections project is working hard to solve a non-existing problem.

  • @houssamel1657
    @houssamel16572 жыл бұрын

    Is this person from France 🇫🇷?

  • @JosePaumard

    @JosePaumard

    2 жыл бұрын

    I am.

  • @houssamel1657

    @houssamel1657

    2 жыл бұрын

    @@JosePaumard Yeah, I inferred that from how you pronounce letters, thanks for this wonderful video.

  • @JosePaumard

    @JosePaumard

    2 жыл бұрын

    @@houssamel1657 Thank you, glad you like it!

  • @Anshulkatta

    @Anshulkatta

    Жыл бұрын

    Netherlands or Denmark most probably

  • @francoisloriot2674

    @francoisloriot2674

    3 ай бұрын

    ​@@Anshulkattanot at all. this is a french accent for sure 😊

  • @themrambusher
    @themrambusher Жыл бұрын

    jdk17 code is more complex than jdk8 code in my opinion

  • @cccc2740
    @cccc2740 Жыл бұрын

    Record would kill lombok

  • @cod3r1337
    @cod3r13372 жыл бұрын

    Still mind-boggingly verbose and clunky for something that should be simple. And that's for code written by a very experienced, very smart expert, doing everything that can reasonably be done with the latest tools available to distill it down to near-optimum readability. Good thing we have Kotlin and Clojure now, otherwise I would probably have given up on the JVM...

  • @brucedsm

    @brucedsm

    2 жыл бұрын

    Can you show a example in kotlin? To compare...

  • @Inuyasha463

    @Inuyasha463

    2 жыл бұрын

    @@brucedsm I can step in here and provide an example. I'm not expert though, so perhaps there are better ways to do it in Kotlin. I haven't watch the whole video yet, so I'm copying the logic he used for the second kata before he started talking about inverting the map. I still need to finish watching that part. The logic should be basically the same as his, so this comparison is mostly so you can compare the readability of Kotlin code with Java code. I personally find it less cluttered and confusing than the Java Streams Apis, but perhaps I'm just more used to Kotlin these days. val result = "This is a test String." .lowercase() .filter { it.isLetter() } .groupingBy { it }.eachCount() .entries.sortedByDescending { it.value } .take(3) The output is: [t=4, s=4, i=3] On a separate note, I love these videos and all the great changes coming to Java. Thanks guys, and keep up the great work!

  • @ErikBrakkee

    @ErikBrakkee

    Жыл бұрын

    Perhaps the video should also have shown a basic method using for loops and collections. My guess is that that code would have been a lot shorter and more easy to understand. There are places for streams IMO but the authors of the streams framework probably did not intend to replace all for loops by streams.

  • @vanivari359

    @vanivari359

    Жыл бұрын

    @@ErikBrakkee yeah, once you start to use it, you tend to use it everywhere, but many java developers really struggle to adopt to them because you have to learn so much stuff - all the collectors and comparators and streams and predicates and static method references and the processing order in the background, i mean: Comparator.reverseOrder() .. who is looking there for that. It forces people into stackoverflow-programming (which is fine if you know what you are doing., but..)

  • @miasmator

    @miasmator

    Жыл бұрын

    @@vanivari359 You fail to see that Java has already eliminated 90% of the verbosity. Before Java 8, especially before anonymous classes implementing any of this was particularly verbose. Also the fact that you needed to use procedural patterns, any algorithm would have required 100+ lines of code if you didn't want code smells in the form of overly long functions. Having a separate sort method for reverse order might be handy, but these kind of helper methods increase the size of classes and pollute their namespaces.

  • @progdynamic3114
    @progdynamic31142 жыл бұрын

    he seems to be starving for a long time.

  • @sandeepthakur7795
    @sandeepthakur7795 Жыл бұрын

    Will you please improve your voice quality?

  • @MrJgremmen

    @MrJgremmen

    6 ай бұрын

    you're not used to writing specifications, are you?

  • @user-zq8bt6hv9k
    @user-zq8bt6hv9k2 жыл бұрын

    i switched to rust 🙄

  • @jackofnotrades15

    @jackofnotrades15

    2 жыл бұрын

    lol

  • @user-zq8bt6hv9k

    @user-zq8bt6hv9k

    2 жыл бұрын

    @@Ihavetoreturnsomevideotapes then switch to javascript

  • @Asdasxel

    @Asdasxel

    2 жыл бұрын

    @@user-zq8bt6hv9k Why would you want to end up with a worse language that is used in totally different types of applications?

  • @user-zq8bt6hv9k

    @user-zq8bt6hv9k

    2 жыл бұрын

    @@Asdasxel same reason why people switched from c++ to java in the 90's

  • @cya3mdirl158
    @cya3mdirl1582 жыл бұрын

    Or start using Kotlin

Келесі