Java Enum Tutorial #96

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024

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

  • @alexlorenlee
    @alexlorenlee  11 หลายเดือนก่อน +2

    If you’re new to programming but want a career in tech, I HIGHLY RECOMMEND applying to one of Springboard’s online coding bootcamps (use code ALEXLEE for $1,000 off): bit.ly/3HX970h

  • @jamescalvert7862
    @jamescalvert7862 3 ปีที่แล้ว +36

    You continue to save me everytime we start something new in college

  • @wk1215
    @wk1215 4 ปีที่แล้ว +51

    Hey I am 12 years old and my fav language is c++ and java. love your vids. You explain good and clearly. Keep it up :)

    • @rittenbrake1613
      @rittenbrake1613 4 ปีที่แล้ว +17

      wow dude u got a bright future

    • @richardss402
      @richardss402 3 ปีที่แล้ว

      @@rittenbrake1613 IDK whether helping a company earn more and more money is a bright future.

    • @rittenbrake1613
      @rittenbrake1613 3 ปีที่แล้ว +4

      @@richardss402 start your own company then :)

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

      @@rittenbrake1613 Nice advice :)

    • @coolfred9083
      @coolfred9083 3 ปีที่แล้ว +2

      @@richardss402 Well for a lot of people it is, they call it _"having a job"_

  • @wjr5552
    @wjr5552 2 หลายเดือนก่อน

    Enums are useful for limiting / constricting the values supplied by the client code. Helps reduce GIGO (garbage in / garbage out).

  • @latedeveloper7836
    @latedeveloper7836 3 ปีที่แล้ว +40

    Thanks yet again! My notes below in case they are of help to others in a hurry:
    0:40 Making and naming a new class
    1:05 Enum explained in brief
    1:15 Starting by creating an array
    1:45 Nice tip on static keyword
    2:00 Converting array into an enum
    2:10 Enum example outside of a class
    2:45 Resolving errors when working with 'labels - don't use strings
    3:25 Convention for enums - all upper-case
    3:45 How to access a label in a enum
    4:15 Test run - prints name of the label
    4:40 Changing name of enum to title case for convention best practice
    5:00 Why to use an enum (like an array but for constant values, cleaner)
    5:35 Example use case with a computer game level
    5:48 What a switch case is (in brief)
    6:40 Enum example inside a class, with a list that doesn't change (constants)
    7:10 Formatting not an issue for labels. Using upper case for names.
    7:45 Distinction between object and enum - use enumName.LABEL for enum
    8:05 If statement to test
    8:48 Test run
    8:55 Recap of enums and use cases

  • @keeprunning5457
    @keeprunning5457 ปีที่แล้ว

    just asked me about this in entry level coding interview thanks alex you are the real mvp

  • @razorlea1
    @razorlea1 2 ปีที่แล้ว

    Alex Lee basically be teaching me Java.

  • @AjaySharma-xt1hp
    @AjaySharma-xt1hp 3 ปีที่แล้ว

    thanks for help me learn java

  • @rolfchristensen9026
    @rolfchristensen9026 2 ปีที่แล้ว

    Awesome as always

  • @Louyark
    @Louyark 3 ปีที่แล้ว

    At 03:10 you just broke the mystery for me. thanks a lot for this video.

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

    love your videos.. good teaching skills

  • @ericamuhammad5082
    @ericamuhammad5082 2 ปีที่แล้ว

    Thank you!

  • @robwpalace2677
    @robwpalace2677 4 ปีที่แล้ว

    Thanks a lot. Please continue with your videos

  • @hollykm
    @hollykm 4 ปีที่แล้ว

    I needed this like 2 weeks ago😪😪

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

    Love your content can you please do a vending machine application

  • @glazeddonut503
    @glazeddonut503 3 ปีที่แล้ว

    very helpful , thank you !

  • @vitz8572
    @vitz8572 2 ปีที่แล้ว

    How to get a user input as enum ?

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

    instead of enums we can use final type of variable also

  • @yanyanchen930
    @yanyanchen930 3 ปีที่แล้ว

    please explain "Generics" if you are available! Big thanks!

  • @misstress1928
    @misstress1928 3 ปีที่แล้ว

    So, enum in Java is like tuple in Python, right?

  • @elifaleynaa
    @elifaleynaa 4 ปีที่แล้ว

    Hİ Alex ! your videos very helpful thank so much.I have a one question about how to use tree and linked list together ?

  • @WSBWallstreetBets
    @WSBWallstreetBets 4 ปีที่แล้ว

    Could you please give a more in depth guide to enums. I see some people use enums where each variable (i.e. chocolate and vanilla) are followed by having specific values. Like chocolate (tubSize, thickness, price) etc. How could we use that info in our code for tests or states etc.

  • @goolkinsnose3936
    @goolkinsnose3936 3 ปีที่แล้ว

    Enum is actually like enema 0:05

  • @khuramali2980
    @khuramali2980 4 ปีที่แล้ว

    Hey. I love ur video's but sometimes it doesnt match my lessons where i have to give the enum an value and then recall it and make an tostring in it...

  • @hajer2467
    @hajer2467 2 ปีที่แล้ว

    You are great 👍😌😌😌.

  • @johnfrog9210
    @johnfrog9210 4 ปีที่แล้ว

    Thankyou for your videos (y)

  • @lutz
    @lutz 4 ปีที่แล้ว

    legend

  • @justinherrera4514
    @justinherrera4514 4 ปีที่แล้ว

    thank you soooo much

  • @rahmounihajar7995
    @rahmounihajar7995 3 ปีที่แล้ว

    hey alex, can you start mentioning names of songs you do in the opening haha thanks

  • @samarthvs3338
    @samarthvs3338 2 ปีที่แล้ว

    3:32 it's not compulsory to be in upper case

  • @chowowgaming266
    @chowowgaming266 4 ปีที่แล้ว

    Am I seeing league on your mac?? ;p

  • @moondemudimba7920
    @moondemudimba7920 4 ปีที่แล้ว

    Power tutorials

  • @ActualVital
    @ActualVital 4 ปีที่แล้ว

    Can you be my professor?

  • @Dixus10
    @Dixus10 4 ปีที่แล้ว +29

    7:43 "Name it something like Flavor flav"
    Instant like.

  • @abhinavkrothapalli3224
    @abhinavkrothapalli3224 4 ปีที่แล้ว +35

    Hey! If possible, can you do a tutorial on creating a simple game like tic-tac-toe? Love your vids, I would really appreciate if you can do this! Thanks!

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

      this would be great

    • @alexlorenlee
      @alexlorenlee  4 ปีที่แล้ว +24

      Thank you! I think that’s a great idea :) I’ll see if I can post a tic tac toe program video up in the next few weeks ;)

    • @abhinavkrothapalli3224
      @abhinavkrothapalli3224 4 ปีที่แล้ว +2

      Alex Lee Thanks a lot man, I’m looking forward to it!

  • @kishanmistry4385
    @kishanmistry4385 4 ปีที่แล้ว +77

    Coincidentally I had a lecture today about enums in java lol

  • @Kurokage130
    @Kurokage130 4 ปีที่แล้ว +21

    Hey Alex, your videos are always amazing! You break things down into their simplest form and you're of tremendous value to the community. Keep up the good work; We thank you!!!

  • @thanigaivelan8394
    @thanigaivelan8394 4 ปีที่แล้ว +33

    I love all of your videos....
    They are really enjoyable..i want this way of explanation.....

    • @__-cd1nd
      @__-cd1nd 4 ปีที่แล้ว

      True !

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

    I love this intro!!✨

  • @Evgen_87433
    @Evgen_87433 2 ปีที่แล้ว

    All compliments and thanks for your educational video aside, listening to this video in Razer headphones makes the sound of your keyboard is soooooo satisfying! xD

  • @jakemulvany1
    @jakemulvany1 8 หลายเดือนก่อน

    Is there any advantage/disadvantage of putting the enum inside/outside the class? How would the JVM understand this?

  • @wjr5552
    @wjr5552 2 หลายเดือนก่อน

    Typing "Enum" doesn't screw with the computer. Enum is a "reserve" word in Java.

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

    Usually instead of enums I use static int uppercase variables inside an interface class, this way I can store the integers values on a database and compare data as if(db.getIcecreamByRowId(0).getFlavor() == Flavors.VANILLA), it becomes more readable than if(db.getIcecreamByRowId(0).getFlavor() == 0), "Flavors" being the interface class and VANILLA an uppercase static int. Please correct me if im wrong and can store enums on db or if theres a better way of doing it.

    • @frankiewilde6915
      @frankiewilde6915 4 ปีที่แล้ว

      Each enum value has the ordinal() method. You can use that.

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

    Whenever I'm stuck, I search for you video. Great job man!! Way better than my teacher.

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

    Just know that you truly saved an Australian university student's ass tonight. Got a sub from me!

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

    thanks a lot bro

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

    Thank you so much Alex for effort, pls keep going!...

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

    Your videos are so informative while also being very entertaining.. I love your vids man

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

    bro,any tutorial on python by you?
    please share link

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

    really like ya face

  • @NadChel1
    @NadChel1 ปีที่แล้ว

    I still don't understand what advantages enums offer

  • @miracallychurn3328
    @miracallychurn3328 4 ปีที่แล้ว +2

    Nice videos

  • @ryanmcintyre4202
    @ryanmcintyre4202 3 ปีที่แล้ว

    Do you know a way to bubble sort the enums? or something like that I have no clue what this stuff is I fell way behind

    • @ryanmcintyre4202
      @ryanmcintyre4202 3 ปีที่แล้ว

      oh and it had to be a method in the main class

  • @sdj7fajo
    @sdj7fajo 3 ปีที่แล้ว

    Alex, how do you read user input to get a value from the enumerated list? Say I want the user to type ORANGES in, the user would receive fruit back. I can put userItem = GroceryList.ORANGES; to receive 'fruit', but that's not what I want. I want the user to type something in.
    I am doing an assignment for a GroceryList..
    public enum GroceryList {ORANGE, TOMATO, JUICE, WATER}
    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    GroceryItem userItem;
    if (userItem == GroceryList.ORANGES || userItem == GroceryList.TOMATO)
    System.out.print("fruit");
    else if (userItem == GroceryList.JUICE || userItem == GroceryList.WATER)
    System.out.print("drink");
    else
    System.out.print("unknown");
    return;
    }
    }

  • @lucasc1765
    @lucasc1765 2 ปีที่แล้ว

    I'm just falling in love for you :)

  • @mohomedrimnaz1234
    @mohomedrimnaz1234 2 ปีที่แล้ว

    Thank you. This was very helpful.

  • @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

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

    Great video! I really enjoy the content!

  • @erawanthewise8227
    @erawanthewise8227 3 ปีที่แล้ว

    Please stop being the best youtuber, please...

  • @aakash9579
    @aakash9579 2 ปีที่แล้ว

    please ans me why Static is used in strings ?

  • @baldursgatethree
    @baldursgatethree 2 ปีที่แล้ว

    alex thank you for saving my life

  • @mrchedda
    @mrchedda 3 ปีที่แล้ว

    Ummmm it's short for Enumeration. -_-

  • @wjr5552
    @wjr5552 2 หลายเดือนก่อน

    Enum is short for "Enumeration"

  • @milankbudha
    @milankbudha 4 ปีที่แล้ว

    plzzz use intellij IDE sometimes

  • @edwardperez1244
    @edwardperez1244 4 ปีที่แล้ว

    I HAVE NEVER UNDERSTOOD WHAT THE HELL ENUMS ARE

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

    Can someone explain to me what Level l = level.LOW; does? I have been struggling with objects a little bit

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

      Level l = Level.LOW will call on LOW from the enum. Level is what the enum is called, l is arbitrary the statement just needed a name, and the set of variables would be low, medium, and high.The dot operator after level (level.LOW) calls on LOW from that enum so now l is basically set to LOW (l = LOW). Hope this isn't too confusing.

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

      Mia Savelli ohhh ok thank you. U may not be able to see me but u helped me out a lot. Thanks

  • @Pilpiscas
    @Pilpiscas 2 ปีที่แล้ว

    You always seem to know what I need

  • @mirjanapanic355
    @mirjanapanic355 3 ปีที่แล้ว

    thanks! it is very helpful

  • @moiyetresorkonan6326
    @moiyetresorkonan6326 2 ปีที่แล้ว

    Thank you for everything guy

  • @danielhidefjall5060
    @danielhidefjall5060 3 ปีที่แล้ว

    This video helped me, thanks

  • @alistair_xxii
    @alistair_xxii 3 ปีที่แล้ว

    thnk you :) appreciate it

  • @bishanhewagama8706
    @bishanhewagama8706 ปีที่แล้ว

    YOU ARE A GOD FOR THIS 🙌

  • @davidevans4452
    @davidevans4452 3 ปีที่แล้ว

    Amazing. You saved me so much head scratching and googling.
    Thank you!

  • @БайсалАлтынбекуулу-г4ы
    @БайсалАлтынбекуулу-г4ы 2 ปีที่แล้ว

    the best tutorial maker

  • @TheTeller2012
    @TheTeller2012 4 ปีที่แล้ว

    Alex,
    Can you help to see why my codes does not run on my java eclipse?

  • @ultralegendarybeast101
    @ultralegendarybeast101 3 ปีที่แล้ว

    enumeration!

  • @weslleyfelix5072
    @weslleyfelix5072 4 ปีที่แล้ว +4

    i'm actually amazed how easely you can spread knowledge with such quality.... I couldn't understand my professor in college, but I could easily underrstandd your video... thanks Alex 😍 😍 😍

  • @virCottoQ37
    @virCottoQ37 4 ปีที่แล้ว

    Please, if you do tutorial, no background music please

  • @ikhbayar1000
    @ikhbayar1000 ปีที่แล้ว

    WOT

  • @nourissa5457
    @nourissa5457 2 ปีที่แล้ว

    thank you so much

  • @MrAnloco
    @MrAnloco 4 ปีที่แล้ว

    "enum" ... as in something that is for "enumerating" things... that's how I made sense out of it and that's what helped me to understand it as a concept

  • @bubbletea8793
    @bubbletea8793 3 ปีที่แล้ว

    thank you

  • @unagi4254
    @unagi4254 3 ปีที่แล้ว

    I love you

  • @justinherrera4514
    @justinherrera4514 4 ปีที่แล้ว

    idk why i even go to lecture it never makes sense but this does'

  • @TalePop117
    @TalePop117 4 ปีที่แล้ว

    thanks for the videos, just work little better on the jokes lol

  • @giladkay3761
    @giladkay3761 3 ปีที่แล้ว

    Wait, so is boolean a type of enum?

  • @sindhusudhakaran1731
    @sindhusudhakaran1731 3 ปีที่แล้ว

    Thank you Alex.. this is very helpful

  • @PP-hn9vq
    @PP-hn9vq 3 ปีที่แล้ว

    Thank you Alex! I enjoy your explanations!!!

  • @maxmuller8580
    @maxmuller8580 3 ปีที่แล้ว

    Alex out there making java look easy xD

  • @samradhisharma1998
    @samradhisharma1998 2 ปีที่แล้ว

    Excellent tutorial 👍👏👏👏👏

  • @Official_ISmokeyTheBear
    @Official_ISmokeyTheBear 4 ปีที่แล้ว

    Love youre vids Alex.
    You think you can do one where you talk about singly linked nodes?

  • @rafa_337
    @rafa_337 2 ปีที่แล้ว

    Your explanations are extremly good!!!

  • @caia6438
    @caia6438 4 ปีที่แล้ว

    Thanks for making this easier, I’m taking Computer Science as well!!! I really appreciate this tutorial!💕

  • @mahadgady3675
    @mahadgady3675 4 ปีที่แล้ว

    thaaaanks 😍, I was just thinking how could I use enum in my project ,, you saved me ! 😂

  • @eatliftpolskarepeat9168
    @eatliftpolskarepeat9168 4 ปีที่แล้ว

    Thank you for this video! Very *clean* and helpful.
    I’ve watched two others before yours and they didn’t make the concept any easier. Yours did! Cheers!

  • @mtaylor2232
    @mtaylor2232 4 ปีที่แล้ว

    I was going to do a flutter tutorial but got side tracked and started doing this instead. you're a good teacher - hopefully we get some back-end tutorials!

  • @JustinTheVlogger
    @JustinTheVlogger 4 ปีที่แล้ว

    Thank you for this video, you helped me a lot.

  • @yuiwayui
    @yuiwayui 4 ปีที่แล้ว

    Thank you. This helped me in the enum chapter. I was struggled to understand it before.

  • @aminezaidi4089
    @aminezaidi4089 4 ปีที่แล้ว

    ALEX!
    YOU'RE A LIFE SAVIOR.
    THATS IT.

  • @pbeeby
    @pbeeby 4 ปีที่แล้ว

    Thanks this was helpful and well put together