Although the enumeration is a common programming feature that is found in many other computer languages, it was not part of the original specification for Java. One reason for this is that the enumeration is technically a convenience, rather than a necessity. However, over the years, many programmers had wanted Java to support enumerations because they offer an elegant, structured solution to a variety of programming tasks. This request was granted by the release of JDK 5, which added enumerations to Java.

In its simplest form, an enumeration is a list of named constants that define a new data type. An object of an enumeration type can hold only the values that are defined by the list. Thus, an enumeration gives you a way to precisely ...

Get Java, A Beginner's Guide, 5th Edition, 5th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.