Тёмный

Java Enums Explained in 6 Minutes 

Coding with John
Подписаться 358 тыс.
Просмотров 260 тыс.
50% 1

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...

Опубликовано:

 

28 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 236   
@ScottishKoala
@ScottishKoala Год назад
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 года назад
The mutability of Enum fields is a nugget of wisdom, which i didn't anticipated. Thanks!
@David-hl1wo
@David-hl1wo 2 года назад
Very controversial video.
@gabrielfono844
@gabrielfono844 2 года назад
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
@amitamlani6285
@amitamlani6285 2 месяца назад
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.
@juliock-y3w
@juliock-y3w 10 месяцев назад
Man your videos are so clear even to me, who can't speak english at all
@sss_az1063
@sss_az1063 2 года назад
You’re making my life much easier thank you so much man i really appreciate you
@flaviu-vanca
@flaviu-vanca 2 года назад
Hi John, another nice thing about enums is that you can use abstract methods to customize the constants :)
@codewithankush9753
@codewithankush9753 2 года назад
Please make Java development full course, they way you explain it's really easy to get understand concept. Thank you
@MrDarshD
@MrDarshD 3 года назад
Thank you for sharing! Love the names you give to them and also the shortcut tips!
@santuyou1
@santuyou1 2 года назад
Clear and crisp. Thanks for video. Subscribed.
@Drogo681
@Drogo681 2 года назад
Straight to the point, and very pedagogical. I have already subscribed, but I like is coming right up.
@chexblu
@chexblu 2 года назад
How come this has so few views and likes. Excellent video mate, keep it up please!
@yourman8808
@yourman8808 7 месяцев назад
This man makes a boring lesson to a lesson to be a fun and more enjoyable lesson.
@pranavnyavanandi9710
@pranavnyavanandi9710 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".
@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 👍
@hanseuberalles5063
@hanseuberalles5063 4 месяца назад
Loved that! Any tutorial for Strams please ?
@Coccoutube
@Coccoutube Год назад
Thanks as always John! My knowledge++
@HuwJones
@HuwJones 2 года назад
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.
@semilife
@semilife 2 года назад
Nice on John, short clear and detailed.
@Hughsie28
@Hughsie28 2 года назад
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!"
@OmarMendozaKS
@OmarMendozaKS 2 года назад
What a heck of explanation man, moreover super creative using cereal, thank you
@AtulRai
@AtulRai 2 года назад
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 года назад
It's a plugin called Darkest Dark
@pranavnyavanandi9710
@pranavnyavanandi9710 2 года назад
@@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.
@anitaliberatore2272
@anitaliberatore2272 2 года назад
can you do a video about dependency injection?
@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!
@seeulater8753
@seeulater8753 9 месяцев назад
Your videos help me a lot. Thank you so much!
@KoryGraphic
@KoryGraphic 2 года назад
This channel is pure trasure
@menaaziz27
@menaaziz27 3 года назад
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 года назад
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.
@jooncco
@jooncco 2 года назад
Helpful as always
@Rockyzach88
@Rockyzach88 Год назад
So an enum is like a conglomeration of maps or dictionaries for a specific list of things?
@jonathanalcantara7347
@jonathanalcantara7347 2 года назад
Great explanation, 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!!!
@mouadaittalebali3066
@mouadaittalebali3066 2 года назад
Can not thank you enough!🙏
@rajeshg3570
@rajeshg3570 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
@withgrowinginsanity198
@withgrowinginsanity198 2 года назад
wow! A gold nuget of information. thanks a lot.
@CRII1P1
@CRII1P1 2 года назад
Can you do a video on Stacks and Queues please
@komalprasad6309
@komalprasad6309 2 года назад
Could you add Java certification series as well.
@kalyankumar8629
@kalyankumar8629 Год назад
Good toturial Mr.john
@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?
@mikaznavodya7277
@mikaznavodya7277 9 месяцев назад
Thank you, your explanations are very clear ❤
@rishabhshah1218
@rishabhshah1218 2 года назад
Nice and quick tutorial. Thanks
@aligooya8514
@aligooya8514 Год назад
You are born a teacher! did you know that?
@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
@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
@ChenChennie
@ChenChennie Год назад
is this a refreshment after collider and subs?
@Devivl
@Devivl Год назад
Thank you very much, John! 🙂
@BunnyboyCarrot
@BunnyboyCarrot 2 года назад
Nice and concise, awesome video!
@lucashenaoserna2455
@lucashenaoserna2455 Год назад
you could also set the level of delicousness to private
@ousmanetall1286
@ousmanetall1286 9 месяцев назад
All this programming stuffs make me have a headache, but anyway it's fun!
@жава
@жава 2 месяца назад
is it simply a list of a final expressions?
@MrNoahsamen
@MrNoahsamen Год назад
If you declare a Constant Enum the semicolon is optional
@BAXEN
@BAXEN 2 года назад
Can you explain to me how Enum is used? I don't know why I would ever use an Enum.
@4inchezz199
@4inchezz199 2 года назад
Thanks man, this actually helped me a lot :D
@DarkenedPossession
@DarkenedPossession 2 года назад
many thanks dude !!
@pp3k07
@pp3k07 2 года назад
Why the semi colon?
@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.
@mub03
@mub03 Год назад
Awesome Video!
@ghettoslick2000
@ghettoslick2000 Год назад
Awesome Thanks!!!!
@aksharjoshi3384
@aksharjoshi3384 2 года назад
What can I say, you are the best!
@Russianspyonyou
@Russianspyonyou 2 года назад
I learned something!
@jacquelinea2110
@jacquelinea2110 5 месяцев назад
I tried that but my "Finish" is deactivated. any help?
@mahdinouira3261
@mahdinouira3261 Год назад
can you please give me or show me the ode written in 1 tab, im new and i wanna have it
@wasimpatel2618
@wasimpatel2618 Год назад
love you john.
@Mohamed-uf5jh
@Mohamed-uf5jh 2 года назад
Thanks, very very clear
@hulagabal
@hulagabal 2 года назад
Thanks
@ayoubmessaoudi5206
@ayoubmessaoudi5206 4 месяца назад
lovely video dude
@vladimirkraus1438
@vladimirkraus1438 6 месяцев назад
Just nitpicking: I would argue for using singular in the enum name. So DayOfTheWeek instead DaysOfTheWeek.
@antonignatenko7776
@antonignatenko7776 2 года назад
wonder whether i can fill an array with enum elements?
@philipepompeu
@philipepompeu 2 года назад
Great content
@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)…
@MohammedUmar-ow2pl
@MohammedUmar-ow2pl 8 месяцев назад
Great promotion...1:36
@hamidreza8354
@hamidreza8354 3 года назад
it was great. thanks
@jvsnyc
@jvsnyc 3 года назад
Do you normally make the name of your ENUM type singular or plural? Either can be valid, as long as you are consistent within your codebase. I feel like at one point I tended towards plurals, like DaysOfWeek or Colors, but then gravitated towards singular like DayOfWeek or Color because that seemed to be a predominate custom in Java-land. Again, not wrong as long as you don't mix them indiscriminately to the point that someone relies on the IDE to remember if it is Flavor or Flavors.
@CodingWithJohn
@CodingWithJohn 3 года назад
Come to think of it I do usually use singular, not sure why I went with plural in this video. Oh well. The convention does seem to be singular, so probably best to stay with that if the codebase you're working with doesn't do it the other way (DayOfTheWeek, Cereal, etc.).
@jakubsz4602
@jakubsz4602 2 года назад
fantastic!!!!
@jimb6554
@jimb6554 2 месяца назад
this.price = price; was supposed to be on the last line before you ended the video.
@user-jk8dl6vr1h
@user-jk8dl6vr1h 10 месяцев назад
you are great
@a7mdbest15
@a7mdbest15 6 месяцев назад
Wdym, froot loops are the best, thanks for the video though
@benjamingaidos4646
@benjamingaidos4646 2 года назад
very cool :)
@ca6koto0
@ca6koto0 Год назад
E-noom ? I always called them e-numb-s (as number) and nobody corrected me
@dasheiligedonerhuhn
@dasheiligedonerhuhn Год назад
isn't that just a hash map?
@amitkhulbe
@amitkhulbe 2 года назад
GReat java lessons, but when will we get a guitar lesson?
@thewolf-ps1qz
@thewolf-ps1qz 2 года назад
i subbed 😎❤️
@erikRairden
@erikRairden 2 года назад
Enum in java takes up so much memory. 24 bytes for each field. So a tiny enum with 4 distinct values would consume 96 bytes. And the example in this video (7 days) would take 168 bytes. Compared to an enum in say C++ or Go which could just use a tiny data type like a short or int, would take 2-4 bytes.
@augischadiegils.5109
@augischadiegils.5109 2 года назад
❤️❤️
@fernandapachla9700
@fernandapachla9700 2 года назад
eu te amo
@Noam.Michael
@Noam.Michael Год назад
yooooooooooooon
@markknight5178
@markknight5178 Год назад
Fruit Loop fan boys.... bwahahaha, had me rollin
@hectorgil3495
@hectorgil3495 2 года назад
+10
@halitozgur6166
@halitozgur6166 2 года назад
virgin fruit loop fanboys vs gigachad reeses puffs enjoyer
@imaginative-monkey
@imaginative-monkey Год назад
The biggest question: is it e-numb or e-noom?!
@CodingWithJohn
@CodingWithJohn Год назад
I say "noom", but I'm ok with either. I might get more clicks if I take a side and start a war though.
@imaginative-monkey
@imaginative-monkey Год назад
@@CodingWithJohn Haha... yup there are people who may take down civilizations on this, or gif/jif war... 👍
@inchworm9311
@inchworm9311 2 года назад
@Vikassharma-rq5bh
@Vikassharma-rq5bh Год назад
Johny sins ka bhai
@southern_smacker
@southern_smacker Год назад
A little bit too fast as if you are on the run while being pursued by police 👮‍♀️ 😂
@CodingWithJohn
@CodingWithJohn Год назад
I like to stay one step ahead of the Java cops
@delavago5379
@delavago5379 2 года назад
I've never heard anyone say enum like that before 💀. Man its driving me crazy. Lovely tutorial but the pronunciation is killing me.
@willtn
@willtn 2 года назад
æ-nööm
@delavago5379
@delavago5379 2 года назад
@@willtn right 💀
@OnatGG
@OnatGG 2 года назад
thats a cheap bass guitar
@CodingWithJohn
@CodingWithJohn 2 года назад
Yep, the bass actually belongs to a friend. The electric, acoustic, and drums are mine. But they're pretty cheap too
@MrSkinkarde
@MrSkinkarde 2 года назад
You make verbose code And Software for Little kids. Have you Ever made any real apps or just Cats And dogs with 100 char method names?
@AhmedMusrin
@AhmedMusrin 2 года назад
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!!!
@howtomath1245
@howtomath1245 3 года назад
Can you make a long tutorial about what a junior Java developer should know 100% to pass an interview or cover some core topics about it or a playlist of videos? Your videos are pretty understandable and informative, thank you.
@howtomath1245
@howtomath1245 3 года назад
Because when I look up some vacancies, it’s like you should know almost everything from core to spring and other stuff, it’s pretty hard to concentrate on one particular topic
@CallumAtwal
@CallumAtwal 2 года назад
@@howtomath1245 I'm in the same boat. My approach to it is to ensure I know the core fundamentals fully (beyond what is enough to get by). Hence why I've watched a video on such a simple topic in Java, enums. I've always just used enums in the way hes shown but it certainly helps to re-enforce what you know when you watch to back. Doing the same with other trivial and basic java concepts helps strengthen you. As for spring specific things, dummy projects are the way to go. Setting something up yourself. Creating a few difficult scenario's which require spring specific solutions. I work with spring day to day at work but hardly ever will run into edge cases that an interview might ask for. Good luck!
@TheDecodee
@TheDecodee 2 года назад
I adhere to the request, your videos have helped me a lot to understand java, but i would really like to see a video about contents that a jr java would need to know to get a job
@devilscarrybach8672
@devilscarrybach8672 2 года назад
I can help you. If you know basic core java then will take 1 week to get ready for job.
@TheDecodee
@TheDecodee 2 года назад
@@devilscarrybach8672 i would really appreciate your help! How should we do?
@jordhan
@jordhan 2 года назад
I was trying to understand Enums in practice to implement in my C# code, but a Java video nailed it for me. Now I understand when my teachers said "learn the idea, not the syntax".
@pranavnyavanandi9710
@pranavnyavanandi9710 2 года назад
Language-agnostic as they say.
@muhendis_
@muhendis_ 9 месяцев назад
ctrl shift x = this was an awesome knowledge 😄🙏🏻
Далее
КАК БОМЖУ ЗАРАБОТАТЬ НА ТАЧКУ
1:36:32
Java enum 🪐
10:50
Просмотров 65 тыс.
Multithreading in Java Explained in 10 Minutes
10:01
Просмотров 927 тыс.
Intro to Competitive Programming
11:41
Просмотров 777 тыс.
Java. Enum на примерах.
18:34
Просмотров 10 тыс.
100+ Computer Science Concepts Explained
13:08
Просмотров 2,5 млн
Map and HashMap in Java - Full Tutorial
10:10
Просмотров 576 тыс.
The Flaws of Inheritance
10:01
Просмотров 945 тыс.
Java Constructors - Full Tutorial
7:38
Просмотров 368 тыс.
КАК БОМЖУ ЗАРАБОТАТЬ НА ТАЧКУ
1:36:32