From the course: Java 8 Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Declaring and using enum types - Java Tutorial
From the course: Java 8 Essential Training
Declaring and using enum types
- I've previously described how to standardize values using the static and final keywords. These are java's versions of constants. But, you can also set up enumerations, lists of possible values that you can use for any particular variable. An enumeration in java is called an enum class. You can create an enum class, either in its own separate code file, or as a nested enum if its only going to be used in one java class. I'm going to create an enum class in the enums project, and I'll place it the model folder, the same folder that contains my Olive class. I'll right click on that folder and choose New, Java Class. I'll set the name of the class to OliveName, and I'll set the kind of class to Enum, and click OK. And notice that the big difference is in the keyword that identifies the file. Instead of class, this is an enum. Now, I'll set up the possible values as a simple list, separating the values with commas. Just as with constants, the naming convention is to use all upper case…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
-
(Locked)
Understanding encapsulation7m 19s
-
Creating and instantiating custom classes4m 51s
-
(Locked)
Creating nested and anonymous classes4m 17s
-
(Locked)
Visualizing class relationships3m 43s
-
(Locked)
Storing data in instance variables6m 2s
-
(Locked)
Declaring instance and static methods3m 59s
-
(Locked)
Using constructor methods4m 56s
-
(Locked)
Using static variables as constants3m 3s
-
(Locked)
Declaring and using enum types5m 17s
-
(Locked)
-
-
-
-