Java Enums Explained in 6 Minutes

Поделиться
HTML-код
  • Опубликовано: 27 сен 2024
  • All about Enums in Java - Full tutorial with concrete examples.
    Enums (short for Enumerations) are used in Java to hold types that have a certain finite set of values. But if you're new to enums, they can be a little confusing. In this Java beginners' tutorial video, we'll talk all about enums - how you can create your own enums, how to use them, and in what situation using an enum makes sense in your code. All in less than 6 minutes!
    Learn or improve your Java by watching it being coded live!
    Hi, I'm John! I'm a Lead Java Software Engineer and I've been in the programming industry for more than a decade. I love sharing what I've learned over the years in a way that's understandable for all levels of Java learners.
    Let me know what else you'd like to see!
    Links to any stuff in this description are affiliate links, so if you buy a product through those links I may earn a small commission.
    📕 THE best book to learn Java, Effective Java by Joshua Bloch
    amzn.to/36AfdUu
    📕 One of my favorite programming books, Clean Code by Robert Martin
    amzn.to/3GTPVhf
    🎧 Or get the audio version of Clean Code for FREE here with an Audible free trial
    www.audibletria...
    🖥️Standing desk brand I use for recording (get a code for $30 off through this link!)
    bit.ly/3QPNGko
    📹Phone I use for recording:
    amzn.to/3HepYJu
    🎙️Microphone I use (classy, I know):
    amzn.to/3AYGdbz
    Donate with PayPal (Thank you so much!)
    www.paypal.com...
    ☕Complete Java course:
    codingwithjohn...
    codingwithjohn...

Комментарии • 236

  • @ScottishKoala
    @ScottishKoala Год назад +54

    How does this man manage to break down these concepts so effectively, especially at such a quick pace?! These videos are a godsend. The way you add a small piece of code then fully explain why you added it and what it does makes the code extremely easy to understand. The humour along with the simple but creative programs is also a huge plus, very engaging. Thank you!!

  • @larryd9577
    @larryd9577 2 года назад +5

    The mutability of Enum fields is a nugget of wisdom, which i didn't anticipated. Thanks!

  • @micleh
    @micleh 2 года назад +43

    Hi. I've only recently become aware of your RUclips channel, and I wonder why the RUclips algorithm hasn't recommended your channel earlier.
    I like your succinct videos a lot, and they are superbly suited for my computer science school courses, since Java is the language students learn in higher education in Germany.
    Thanks a lot for the high-quality content.

    • @thalibmuhammad9519
      @thalibmuhammad9519 Год назад

      you can help by like and subscribe, that boost the youtube algorithm

    • @mahdinouira3261
      @mahdinouira3261 Год назад

      it could be because you are subscribed to many channels, try using two account (it can provide SOME of what you need )

  • @DaBestOhYeah
    @DaBestOhYeah Год назад +2

    I am so glad that whenever I don't understand something in java, your videos are top on the list!!

  • @juliock-y3w
    @juliock-y3w 10 месяцев назад +2

    Man your videos are so clear even to me, who can't speak english at all

  • @amitamlani6285
    @amitamlani6285 2 месяца назад +1

    I am trying to improve my proficiency in Java. I found your video very insightful and it allowed me to practice and adapt new coding immediately. I found the enum concept quite difficult to adapt into real usage, whilst looking at numerous other sources. Its application in code is making much better sense now with a strong example.

  • @gabrielfono844
    @gabrielfono844 2 года назад +3

    sir
    thanks so much
    I really appreciate
    I taught myself frontend development two years ago and I got hired recently as backend engineer.
    since I recently started learning java , I was struggling on something on my assignment and this video basically explain everything.
    your example is similar to the problem I have .
    I right away subscribe and will recommend this channel to my friend
    I want to say thank again

  • @sss_az1063
    @sss_az1063 2 года назад +6

    You’re making my life much easier thank you so much man i really appreciate you

  • @HatTrick4030
    @HatTrick4030 Год назад +3

    Amazing! now I don't have to watch a 30 minutes of enum video tutorial again on a purchased bootcamp on Udemy. just simple and and understandable. all that matters to us is to understand the syntax of a new lesson and master it and then we can build our projects with details ourselves. the problem with other instructors is that they involve too many peripherals to the main lesson and we understand all except the main topic :D

  • @valoriebroderick
    @valoriebroderick Год назад +2

    These tutorials are amazingly clear and understandable. I'm so grateful because that's not always the case with coding tutorials.

  • @codewithankush9753
    @codewithankush9753 2 года назад +1

    Please make Java development full course, they way you explain it's really easy to get understand concept. Thank you

  • @AhmedMusrin
    @AhmedMusrin 2 года назад +82

    We had to implement the 2nd part of your video(with grades instead of cereal) as part of my exam(on paper). Without you, I would not have gotten it correct. Thank you!!!

  • @janfeyen592
    @janfeyen592 Год назад +1

    Hey, you may not remember me, but I watched one of your I/O java videos a couple of weeks back and I just wanted to say thanks for the clear straight forward but most importantly amazing Java tutorials you've put out

  • @Habijob
    @Habijob 2 года назад +1

    Bless you and your video(s). I started studying for the OCA and your videos are a big help in understanding the dry text from the book in minutes (literally), haha.

  • @yourman8808
    @yourman8808 7 месяцев назад

    This man makes a boring lesson to a lesson to be a fun and more enjoyable lesson.

  • @eravil8882
    @eravil8882 2 года назад +9

    Hi sir, I've finished the core of java and I am now practicing it daily, and I started to explore more on advanced level and I'm going to start it in java enums. Thank u sir for sharing this. I'm really looking forward for your future videos about java. New Subscriber here!

    • @jetspray3
      @jetspray3 2 года назад +1

      Where do you go to practice java?

    • @pranavnyavanandi9710
      @pranavnyavanandi9710 2 года назад

      What do you mean practicing it daily? How are you doing that?

  • @flaviu-vanca
    @flaviu-vanca 2 года назад +5

    Hi John, another nice thing about enums is that you can use abstract methods to customize the constants :)

  • @limiakejelu
    @limiakejelu Год назад

    One thing about John is he picks the right examples that makes one watch and never forget the topic….In this case cereals 😂. Good job man 👍

  • @jarveyd8660
    @jarveyd8660 2 года назад +2

    You broke it down really well!!

  • @santuyou1
    @santuyou1 2 года назад +1

    Clear and crisp. Thanks for video. Subscribed.

  • @Coccoutube
    @Coccoutube Год назад +1

    Thanks as always John!
    My knowledge++

  • @Drogo681
    @Drogo681 2 года назад +1

    Straight to the point, and very pedagogical. I have already subscribed, but I like is coming right up.

  • @HimanshuGupta-jx4nk
    @HimanshuGupta-jx4nk Год назад

    I understood it is more like a class which contains its own instance fields as static. for example class test{ static test monday = new test(); static test tuesday = new test();} Thank you very much!!!!!!!

  • @OmarMendozaKS
    @OmarMendozaKS 2 года назад +1

    What a heck of explanation man, moreover super creative using cereal, thank you

  • @MrDarshD
    @MrDarshD 3 года назад +4

    Thank you for sharing! Love the names you give to them and also the shortcut tips!

  • @semilife
    @semilife 2 года назад +1

    Nice on John, short clear and detailed.

  • @chexblu
    @chexblu 2 года назад +1

    How come this has so few views and likes. Excellent video mate, keep it up please!

  • @hanseuberalles5063
    @hanseuberalles5063 4 месяца назад

    Loved that! Any tutorial for Strams please ?

  • @Cablur
    @Cablur Год назад

    Ohh, I really like your sense of humor and how you explain things, even though it was a bit fast. But maybe I'm just tired^^
    Anyways, thank you for this great video!

  • @seeulater8753
    @seeulater8753 9 месяцев назад

    Your videos help me a lot. Thank you so much!

  • @pranavnyavanandi9710
    @pranavnyavanandi9710 2 года назад +2

    final is what makes something constant, and also immutable. If all the fields of a class are made final, then the state of that class is unmodifiable. Which makes the type immutable. At least this is my understanding of it. A handy tip, the data members held by a class/object are what constitute it's "state" and methods make up it's "behavior".

  • @KoryGraphic
    @KoryGraphic 2 года назад

    This channel is pure trasure

  • @HuwJones
    @HuwJones 2 года назад +1

    Something missing here is the importance or ordinality. As in most other languages implementing enums or ordinals the items in the enumeration have an ordinal value...the order in which the enumeration's items are defined IS SIGNIFICANT. This can create problems in a project if developers try to re-order the items later on...something which should not be done. This idea of ordinality also has repercussions when mapping to a database. Most databases map enums to a column using the ordinal value by default. Just don't forget the ordinality.

  • @jooncco
    @jooncco 2 года назад +1

    Helpful as always

  • @menaaziz27
    @menaaziz27 3 года назад +1

    I watch all your videos even though I know about the video .. keep it up john!

    • @CodingWithJohn
      @CodingWithJohn  3 года назад

      Ha, well thank you!

    • @jvsnyc
      @jvsnyc 3 года назад +1

      Me too. I love seeing how he describes it in such a short time without saying anything flat-out wrong which would be so easy to do when trying to make really short videos.

  • @withgrowinginsanity198
    @withgrowinginsanity198 2 года назад

    wow! A gold nuget of information. thanks a lot.

  • @KH-hn3nu
    @KH-hn3nu Год назад

    Amazing break down John, thank you!... Now if only we can get you to reassess these gradings for deliciousness. Captain Crunch is 110/100 LOL!

  • @batsybats5591
    @batsybats5591 2 года назад

    Tysm for this video! I had watched another video on enums, but somehow errors were being thrown in my program and I didn't understand the purpose of enums, nor how to use them and now I think I have a clear basic understanding of them. Plus, I really want some cereals now lol

  • @Pacvalham
    @Pacvalham 2 года назад +2

    1:17 IntelliJ tells me that the semicolon is unnecessary, and the enum compiles with or without it; was it required in an earlier version of Java?

  • @yogeshvasudevan
    @yogeshvasudevan 2 года назад +1

    Great explanation 👏👏..Thank you for the refresher👍👍🙏

  • @jonathanalcantara7347
    @jonathanalcantara7347 2 года назад +1

    Great explanation, thanks!

  • @lolcrafter9524
    @lolcrafter9524 8 месяцев назад

    W video, probably saves me from a negative grade :)

  • @bhaweshpandey4306
    @bhaweshpandey4306 2 года назад +2

    This was helpful 👍, thanks !!

  • @Metorrite
    @Metorrite 7 месяцев назад

    4:32 - You thought we would not notice, but we did :)
    Real question, what design pattern do you use when you have enums that are constant values that need to contain a field that is an object whose internal values need to be changed across instances? For example, if you have different kinds of web input fields in an enum, and you know for certain the type of data type each field returns (String, int, boolean, array, etc) so you want to assign a corresponding validation strategy to each, however, in the strategy maybe you want to validate different values against the result across different input fields of the same type. This is my particular problem however i hope this represents the underlying design question i have!

  • @anitaliberatore2272
    @anitaliberatore2272 2 года назад +1

    can you do a video about dependency injection?

  • @kalyankumar8629
    @kalyankumar8629 Год назад

    Good toturial Mr.john

  • @mahodaadikari4116
    @mahodaadikari4116 2 года назад +1

    Another simple and amazing explanation as always. ❤💯

  • @mouadaittalebali3066
    @mouadaittalebali3066 2 года назад +1

    Can not thank you enough!🙏

  • @AtulRai
    @AtulRai 2 года назад +4

    Hey John, thank you for sharing your experience. I have watched couple of videos and became the fan of your explanation.
    If you don't mind, may I know which theme you are using in your Eclipse IDE?
    it's looking cool.

    • @CodingWithJohn
      @CodingWithJohn  2 года назад +3

      It's a plugin called Darkest Dark

    • @pranavnyavanandi9710
      @pranavnyavanandi9710 2 года назад +1

      @@CodingWithJohn Hello John. Could you make a video covering these things in eclipse like Maven, gradle, ant build, mylyn etc. ? Would be quite informative for beginners. Eclipse tends to overwhelm you with all these terms sometimes.

  • @ManhPhuGiang
    @ManhPhuGiang Год назад

    Thank you, great video.

  • @mikaznavodya7277
    @mikaznavodya7277 9 месяцев назад

    Thank you, your explanations are very clear ❤

  • @Devivl
    @Devivl Год назад

    Thank you very much, John! 🙂

  • @Imperfectwow
    @Imperfectwow 2 года назад +1

    Great content John thanks

  • @Hughsie28
    @Hughsie28 2 года назад +5

    Surprised you didn't include the abstract methods in the ENUM's as another way to give them more features, ie:
    public enum Test {
    MY_VALUE_NAME {
    public String myReadableValue() {
    return "My Value Name!";
    }
    };
    public abstract String myReadableValue();
    }
    usage:
    Test.MY_VALUE_NAME.myReadableValue();
    Output:
    "My Value Name!"

  • @rishabhshah1218
    @rishabhshah1218 2 года назад

    Nice and quick tutorial. Thanks

  • @gregdawe2786
    @gregdawe2786 10 месяцев назад

    Holy broken sewer pipe batman, thank you. I've been trying to figure out how to use enums for the past few hours. THANK YOU!!!

  • @aligooya8514
    @aligooya8514 Год назад

    You are born a teacher! did you know that?

  • @rajeshg3570
    @rajeshg3570 2 года назад +2

    This is simple and precise...may be some additional details like getting the ENUM by passing a value like deliciousness would be great

    • @rajeshg3570
      @rajeshg3570 2 года назад

      Hi John, Could you please add an example video to see how to use switch case with enums

  • @ousmanetall1286
    @ousmanetall1286 9 месяцев назад

    All this programming stuffs make me have a headache, but anyway it's fun!

  • @DarkenedPossession
    @DarkenedPossession 2 года назад

    many thanks dude !!

  • @BunnyboyCarrot
    @BunnyboyCarrot 2 года назад

    Nice and concise, awesome video!

  • @4inchezz199
    @4inchezz199 2 года назад

    Thanks man, this actually helped me a lot :D

  • @Russianspyonyou
    @Russianspyonyou 2 года назад

    I learned something!

  • @MarkWesley
    @MarkWesley Год назад

    50/50 mix of Reese's Puffs and Cocoa Puffs for the win!

    • @CodingWithJohn
      @CodingWithJohn  Год назад +1

      This is an interesting proposal. But doesn't that just dilute the peanut-butteriness of the cereal by adding additional chocolate to the already existing perfect mix of peanut butter and chocolate that is the Reese's Puff's recipe?

    • @MarkWesley
      @MarkWesley Год назад

      @@CodingWithJohn Excellent point. 😃

  • @DereC519
    @DereC519 3 месяца назад

    thank you

  • @CRII1P1
    @CRII1P1 2 года назад +1

    Can you do a video on Stacks and Queues please

  • @aksharjoshi3384
    @aksharjoshi3384 2 года назад

    What can I say, you are the best!

  • @mub03
    @mub03 Год назад

    Awesome Video!

  • @karyoplasma
    @karyoplasma 2 года назад +1

    OK, I'm just gonna confess my sin: I dev'd with Java for a very long time and I still sometimes use enums for stuff I should better be using a database. They are just so handy. Screw the inefficiency large enums create because of overhead, I wanna make life easy for me and I like switch statements lol

  • @komalprasad6309
    @komalprasad6309 2 года назад

    Could you add Java certification series as well.

  • @lucashenaoserna2455
    @lucashenaoserna2455 Год назад

    you could also set the level of delicousness to private

  • @Rockyzach88
    @Rockyzach88 Год назад

    So an enum is like a conglomeration of maps or dictionaries for a specific list of things?

  • @MrNoahsamen
    @MrNoahsamen Год назад

    If you declare a Constant Enum the semicolon is optional

  • @ayoubmessaoudi5206
    @ayoubmessaoudi5206 4 месяца назад

    lovely video dude

  • @ghettoslick2000
    @ghettoslick2000 Год назад

    Awesome Thanks!!!!

  • @wasimpatel2618
    @wasimpatel2618 Год назад

    love you john.

  • @Mohamed-uf5jh
    @Mohamed-uf5jh 2 года назад

    Thanks, very very clear

  • @javidrezvan9622
    @javidrezvan9622 2 года назад

    dear john good job .please speak slower . many people who interested in your videos they are not english speakers but whatever you are very good in teaching and thank you very much.

  • @wasimpatel2618
    @wasimpatel2618 Год назад

    John ,can you tell me what is the type of "enum values" like ,if MONDAY is not a String than what it is??
    and can we me numeric enums?

  • @philipepompeu
    @philipepompeu 2 года назад

    Great content

  • @saikumarff2693
    @saikumarff2693 6 месяцев назад

    What if we use the lowercase values for enum class

  • @malou5290
    @malou5290 5 месяцев назад

    excellent!

  • @hulagabal
    @hulagabal 2 года назад

    Thanks

  • @Brlitzkreig
    @Brlitzkreig 2 года назад

    Since this video was made on a Monday I think it was a while away from Friday lol.

  • @David-hl1wo
    @David-hl1wo 2 года назад +19

    Very controversial video.

  • @ChenChennie
    @ChenChennie Год назад

    is this a refreshment after collider and subs?

  • @chungfup1493
    @chungfup1493 Год назад

    I am going through Enums that were introduced in Java 1.5. In Effective Java 2'nd Edition it's mentioned that before Java 1.5 there were int and String enum patterns which were having some deficiencies.
    I understood the cons of int enum patterns but while going through String enum patterns I got the basic idea but didn't get the deep sense of below statements mentioned under Item30 in Effective Java:
    This variant, known as the String enum pattern, is even less desirable. While it does provide printable strings for its constants, it can lead to performance problems because it relies on string comparisons. Worse, it can lead naive users to hard-code string constants into client code instead of using field names. If such a hard-coded string constant contains a typographical error, it will escape detection at compile time and result in bugs at runtime.
    Can anyone help me in understanding what these lines explaining. I would appreciate if it can be explained with some code snippet.
    Thanks

  • @BAXEN
    @BAXEN 2 года назад +1

    Can you explain to me how Enum is used? I don't know why I would ever use an Enum.

  • @жава
    @жава 2 месяца назад

    is it simply a list of a final expressions?

  • @vladimirkraus1438
    @vladimirkraus1438 6 месяцев назад

    Just nitpicking: I would argue for using singular in the enum name. So DayOfTheWeek instead DaysOfTheWeek.

  • @I_DidntKnowThat
    @I_DidntKnowThat 7 месяцев назад

    Why would I prefer an enum (I didn't know that this is how you should pronounce it!), over a static variable and methods?

  • @Sisyphus.
    @Sisyphus. 2 года назад

    im not sure if i got it right but is every day of the week inside that enum like a constructor in it self, coz u are treating them like they are, just wanted to be sure that im getting it, if u can explain this

  • @pp3k07
    @pp3k07 2 года назад

    Why the semi colon?

  • @hamidreza8354
    @hamidreza8354 3 года назад

    it was great. thanks

  • @MohammedUmar-ow2pl
    @MohammedUmar-ow2pl 8 месяцев назад

    Great promotion...1:36

  • @tamharsingh7550
    @tamharsingh7550 Год назад

    How to implement this is ruby?

  • @jakubsz4602
    @jakubsz4602 2 года назад

    fantastic!!!!

  • @jacquelinea2110
    @jacquelinea2110 5 месяцев назад

    I tried that but my "Finish" is deactivated. any help?

  • @tylerbakeman
    @tylerbakeman 5 месяцев назад

    I never get to use enums in my programs, because I end up needing to convert them to classes or interfaces.
    I’m waiting for the day someone asks me to code the solar system or something. I have my enums ready
    * Come to think of it… I wonder if any of my static members can be replaced with enums (if they’re in groups)…

  • @antonignatenko7776
    @antonignatenko7776 2 года назад

    wonder whether i can fill an array with enum elements?