- JAVA OVERVIEW
- History of Java
- Tools you will need for java
- Java Environment Setup
- Popular Java Editors
- Java Basic Syntax/First-Program
- Java Identifiers
- Java Modifiers
- Java Arrays
- Java Enums
- Java Keywords
- Comments in Java
- Java - Objects and Classes
- Objects in Java
- Classes in Java
- Constructors
- Creating an Object
- Accessing Instance Variables and Methods
- Source file declaration rules
- Java Package
- Simple Case Study
- Basic Data Types
- Primitive Data Types
- Reference Data Types
- Java Literals
- Variable Types
- Local variables
- Instance variables
- Class or static variables
- Java Access Modifiers
- What is OOPS
- Inheritance concept
- Encapsulation
- What is Polymorphism
- Method Overloading
- Method Overriding
- Abstraction in Java
- Abstract class
- Interface in Java
- Method overloading in Java:
- What is Annonymous object?
- Java 8
What are Java Enums?
This is also called as java enumerated types.
Enums were introduced in java 5.0.
Enums restrict a variable to have one of only a few predefined values.
The values in this enumerated list are called enums.
With the use of enums, it is possible to reduce the number of bugs in your code.
For example,
If we consider an application for a fresh juice shop. It would be possible to restrict the glass size to small, medium and Large. This would make sure that it would not allow anyone to order any size other than the small, medium or large.
Example of Enums Types in Java:-
class FreshJuice
{
enum FreshJuiceSize
{
SMALL, MEDUIM, LARGE
}
FreshJuiceSize size;
}
public class FreshJuiceTest
{
public static void main(String args[])
{
FreshJuice juice = new FreshJuice();
juice.size = FreshJuice. FreshJuiceSize.MEDUIM ;
}
}
Note: enums can be declared as their own or inside a class.
Methods, variables, constructors can be defined inside enums as well.