Java Tutorial # 26 | Enumerations in Java | Enums in Java | Java Beginners Tutorials by Java9s

preview_player
Показать описание
Enums in Java help to define constants which are more powerful than we do with Interfaces. The main objective of Enums is to ensure the type safety when using the Constants in Java programs. In this Video tutorial i have explained how enums work and how objects can be created. I have also explained about some the important methods of enum like values() valueOf(String), Ordinal(), name() etc. All the object produced by enum are singleton. And enum provided a great flexibility to add more values to constant and define methods like a normal class.
Рекомендации по теме
Комментарии
Автор

I found the first example easier to absorb immediately than the second was, possibly because the second were about ranges, or just slightly less time was spent on it. Anyway, subscribed and I am going to be keeping you in mind when seeking Java information. One thing none of the tutorials I've watched showed was when we needed to have specific integral values for enums that corresponded to some external hardware or software system, something like
enum Commands { SEND = 10, RECEIVE = 20, CLEAR = 32, SIGNAL_BUFFER_FULL = 60 }
At least in the old days, that was a very common use of enums, to let our program deal with externally-imposed magic numbers. None of the tutorials I've seen really showed how to do that, including this one. I guess we could use a constructor and a private value to do that, something like
enum Commands { SEND(10), RECEIVE(20), CLEAR(32), SIGNAL_BUFFER_FULL(60);
private int chipCommand;
private Commands( int cCMD )
{
chipCommand = cCMD;
}
public int getCmdValue()
{
return chipCommand;
}
Then when we need the values we do something like Commands.SEND.getCmdValue();
Obviously, the people who made the enums in Java 5 had been using enums in C/C++ and other languages for years, and had been thinking about what they liked and disliked about them and how they could make them better. C# enums are beautifully simple and clean, but now I see how there is also a lot to like about Java's implementation.

jvsnyc
Автор

I use enums but never observed these many details before...good one

rakeshkonda
Автор

One of the best explanation on enums.Thank you!!

arjunsuresh
Автор

A complete tutorial on enums. Thanks !!

thundrking
Автор

Very good tutorial. Srini can you please share link for the code for these videos

saikiran
Автор

thnx a ton, it was completely unknown to me!

subhajitmitra
Автор

Very good Video... Love it. Just one small suggestion: Please include how Enum can be used for implementing Singleton Design Pattern. The best uses of Enum...

SudiptaDeb
Автор

Presentation is lovely .. I appreciate the pain taken by you for us

how to change the value in the enums  like

CHICKEN_SOUP(20)   to  CHICKEN(30)  by programmatically this is missing in the presentation ..

sumanreddy
Автор

Thanks a lot, could you provide link to java9s and the source code for enum

krishnasampath
Автор

why enum is not allowing values which are started with Integers?

Nareshgvlogs
Автор

nice u have exposed enum that is not done at class room !!!

kishansatasiya
Автор

i still don't get a clear idea of enums, and how do their methods work.

muddassirahmed
Автор

i executed my program without declaring my constructor private...'

enum boy
{ jatin("mast", 20),
amit("haggu", 20),
sagar("charkhat", 20);

private final String desc;
private final int age;

boy(String desc, int age)
{
this.desc=desc;
this.age=age;}

String getdesc()
{ return desc;}

int getage()
{ return age;
}

}

class asd
{ public static void main(String args[])
{
for(boy a: boy.values())
System.out.println("Name is "+a+". He is "+a.getdesc()+". He is "+a.getage()+" years old.");
}}

jatinlalwani
visit shbcf.ru