From the course: Java 8+ Essential Training: Objects and APIs
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Declare and use enum types - Java Tutorial
From the course: Java 8+ Essential Training: Objects and APIs
Declare and use enum types
- [Instructor] Java supports a special type called an enum, short for an enumeration. An enum lets you define a set of mutually exclusive values that can be referenced throughout an application. Just like variables that are static and final, constants, an enum value can only be defined once. Enum values are stored internally as integer values. But like the constants that I've previously shown, those values don't matter. What matters is that each enumerated value is unique. In this application, I'll go to my utilities package, and select new, java class. I'll call the class operation, but instead of it being a class, I'll choose enum as the type. I'll click okay. And that creates the enum file. Just like a class, the identifier, that is the enum has to match the name of the file. So, the enum operation is stored in operation dot java. Now, to define the available values, I'll type in add, comma subtract, and then a semicolon, and that's all you need to do. The actual values will be…
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)
About encapsulation3m 46s
-
Use the Java runtime classes4m 45s
-
(Locked)
Wrap code in static methods5m 56s
-
(Locked)
Declare and use custom classes4m 9s
-
(Locked)
Organize code with packages3m 46s
-
(Locked)
Create and use instance methods2m 27s
-
(Locked)
Manage state with instance variables7m 31s
-
(Locked)
Declare multiple constructor methods5m 2s
-
(Locked)
Use static fields as constants5m 51s
-
(Locked)
Declare and use enum types3m 44s
-
(Locked)
Organize code with nested types4m 15s
-
(Locked)
-
-
-
-
-