Hidden Beauties of Java Enums: The Not-So-Secret Weapon That Can Do A Lot More

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ก.ย. 2024
  • Discover the hidden beauties of Java enums in this insightful video that delves deep into this powerful feature of the Java programming language. Java enums are often seen as simple constructs, but they are a not-so-secret weapon that can significantly enhance your coding efficiency and best practices.
    Join us as we explore advanced Java techniques, providing practical enum examples, patterns, and tips that every developer should know. Whether you want to improve your software development skills or want to understand the full potential of enums, this video offers valuable insights into their usage in real-world scenarios.
    Unlock the advanced capabilities of Java enums and learn how they can streamline your development process. From programming hacks to best practices, this video is a must-watch for developers looking to elevate their Java knowledge. Don't miss out on these essential concepts that can transform your approach to Java programming!
    Watch now to uncover the secrets of Java enums and take your development skills to the next level!
    NOTE: there is actually an error in one of the code examples, just to check if someone notices ;-)
    Around 12'-13' the code "class Customer() {" should not have the "()".
    The blog post is available here:
    webtechie.be/p...
    And the sources here:
    github.com/foo...
    Other links mentioned:
    * api.pi4j.com/web/
    + library github.com/Pi4...
    * lottie4j.com/
    + library github.com/lot...
    * 4drums.media/
    * www.jbang.dev/
    * foojay.io/toda...

ความคิดเห็น • 29

  • @Manuel-oe4gv
    @Manuel-oe4gv ปีที่แล้ว +9

    I came from reddit ! Nice content I want to be good programmer like you one day !! I have 5 years of exp and it feels like I know nothing

    • @FrankDelporte
      @FrankDelporte  ปีที่แล้ว +11

      I have 30 years of experience and still each day there are things I don't understand. That's how things work. Embrace it! It's an opportunity to evolve and learn continuously 😃

  • @TheKundan11
    @TheKundan11 ปีที่แล้ว +9

    Wonderful video Frank. Learned a new thing in Java. Please also make videos on JavaFX tutorials. There are very few JavaFX tutorials online. Please keep posting videos regularly.

    • @FrankDelporte
      @FrankDelporte  ปีที่แล้ว +1

      Thanks for your kind words!!

  • @VerhoevenSimon
    @VerhoevenSimon ปีที่แล้ว +5

    Indeed some nice things to do with enums, and that customer state is indeed quite an apt example. And the code error was indeed spotted at the 12:04 mark. Thank you for the interesting video and blog post.

    • @FrankDelporte
      @FrankDelporte  ปีที่แล้ว +1

      Thanks! And you watched attentively to spot the error... ;-)

  • @enes1565
    @enes1565 5 หลายเดือนก่อน +2

    thanks for good explanation❤

    • @FrankDelporte
      @FrankDelporte  5 หลายเดือนก่อน

      You're welcome 😊

  • @Misa7531
    @Misa7531 3 หลายเดือนก่อน +1

    Hey great overview of enum functionality, you could also show that an enum is basically a immutable class and can also implement interfaces, this could potentiality lead to interesting use cases like an light version of strategy pattern, also quick question, why you are doing Arrays.stream().sequential() is'n it sequential by default ? Other then this great video you got one more subscriber :D

    • @FrankDelporte
      @FrankDelporte  3 หลายเดือนก่อน

      Thanks for your feedback! There is actually a lot more that could also fit in this video; maybe I need to create a follow-up... ;-)

  • @avalagum7957
    @avalagum7957 4 หลายเดือนก่อน +1

    A few notes:
    - your project directory has an .idea directory but you open it with vscode. You don't want to show people your IntelliJ? :)
    - you're using java 17, aren't you? If yes, your switch (...) { case ...: return 1; ... } doesn't look very nice as there are a lot of return's in there.
    - you use jband EnumExtended.java instead of java EnumExtendec.java. What's the advantage of using jbang over java?

    • @FrankDelporte
      @FrankDelporte  4 หลายเดือนก่อน

      Hi, thanks for your feedback!
      1/ I use both Visual Studio Code and IntelliJIDEA, normally I add the .idea directory to gitignore, but probably forgot it here... Check out my other videos, you'll see I definitely do show it :-)
      2/ Yes switch/case can be further improved with newer Java versions, good remark!
      3/ When you don't use dependencies, java can handle it. But I do prefer JBang as it has a way to define dependencies inside the file and you don't need a full Maven or Gradle project. See pi4j.com/examples/jbang/ for more info.

  • @donwinston
    @donwinston 7 หลายเดือนก่อน +1

    I fail to see any benefit of enums over: final String[] values = { "X1", "X2", ..., "Xn" };

    • @luquillasnano
      @luquillasnano 7 หลายเดือนก่อน

      I'm with you. It's even more verbose for me than working with old plain arrays. I'd really like to understand all the enthusiasm with them, but I just can't 🫤

    • @mrshahcloud
      @mrshahcloud 7 หลายเดือนก่อน

      Because you can share it on multiple class, easy to document on openapi etc

    • @donwinston
      @donwinston 7 หลายเดือนก่อน

      @@mrshahcloud You can "put public static final MyEnum = { "X1", "X2", "X3" };" in a static class and make it part of a library.

    • @mrshahcloud
      @mrshahcloud 7 หลายเดือนก่อน

      @@donwinston of course you can, there are many ways to skin a cat. We could also create a complete large program using only the main class and opt out of using oop in java. Whichever suits the use case.

    • @donwinston
      @donwinston 7 หลายเดือนก่อน

      @@mrshahcloud No. the point is the enum feature has little to nothing to offer.

  • @yaroslavpanych2067
    @yaroslavpanych2067 4 หลายเดือนก่อน +1

    1. "Enum members are instances of the enum type" ehm, yeah. Surprise. It is the case since forever. It is not hidden, always been there. "Enum type much like any class can have fields and methods, including constructors". Yeah, nothing new really, nothing hidden either!
    2. Also, cringe using java instead of normal javac->java sequence. You are targeting pupils, students, newbies! Don't teach them bad!