# Special Types

An **enum** is a special data type that defines a fixed set of constant values👉 {VALUE1, VALUE2, VALUE3}

To define an enum:

```java
public enum Day {
  MONDAY, 
  TUESDAY, 
  WEDNESDAY  
}
```

To use an enum:

```java
Day day = Day.MONDAY;

if(day == Day.MONDAY) {
  😀 // Do something
}
```

**Benefits:**

* 📏 Defines a fixed set of values that is clear and understandable
* 🔒 Limits variables to only those values, increasing program integrity
* 🖥️ Concise and readable code using human-friendly labels vs integers
* 🤖 Useful for representing defined, unchanging categories like statuses, states, options

## Example

```java
public class Main {

  // Define Weekday enum with constant values 
  public enum Weekday {
    MONDAY, 
    TUESDAY, 
    WEDNESDAY, 
    THURSDAY, 
    FRIDAY, 
    SATURDAY, 
    SUNDAY
  }

  public static void main(String[] args) {
  
    // Create Weekday variables using enum values
    Weekday today = Weekday.WEDNESDAY;
    Weekday tomorrow = Weekday.THURSDAY;

    // Use enum in conditionals
    if(today == Weekday.WEDNESDAY) {
      System.out.println("It's the middle of the week!");
    } else if(today == Weekday.SATURDAY) {
      System.out.println("It's the weekend!");
    }

    // Invalid assignment causes compile error
    Weekday invalidDay = "Tuesday"; 

  }

}
```

In this example, the Weekday enum defines the valid constant values. The main method shows variable declaration, conditionals, and attempted invalid assignment with enums.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://qatesting.gitbook.io/qa/java/variables-and-types/special-types.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
