Java Enum — Free Java Tutorial
Learn Java Enum in Java with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
TL;DR: Learn Java Enum in Java with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
Written & reviewed by the Syllab.in Academic Team (CBSE/NCERT subject experts) · Updated
Java Enum in Java
An enum (enumeration) defines a fixed set of named constants. Use it when a variable can only hold one of a limited set of values: days of the week, directions, seasons, status codes.
Enums are type-safe — the compiler prevents assigning invalid values, unlike using int constants (0, 1, 2...).
Java enums are full classes — they can have fields, constructors, and methods. This makes them far more powerful than enums in other languages.
Useful enum methods: values() returns all constants as an array, ordinal() returns the position (0-based), name() returns the name as a String, valueOf(String) converts a string to an enum constant.
Java Enum — Syntax
// Basic enum
enum Direction { NORTH, SOUTH, EAST, WEST }
// Enum with fields
enum Priority {
LOW(1), MEDIUM(5), HIGH(10);
private final int value;
Priority(int value) { this.value = value; }
public int getValue() { return value; }
}
Direction dir = Direction.NORTH;
for (Direction
Learn Java Enum step by step with Syllab's free interactive Java tutorial — runnable code examples, practice exercises and instant AI feedback, all free with no signup. Explore the full Java course →