Great approach, @ishrth_fathima But if your java constant values are logically related, an enum is even better. Enums not only group constants but can also hold extra functionality.
public enum TimeConstants {
MAX_SECONDS(25),
MIN_SECONDS(5);
private final int value;
TimeConstants(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
Then, use it like this:
java
CopyEdit
int timeout = TimeConstants.MAX_SECONDS.getValue();
Why use this?
Groups related constants
Ensures type safety
Allows additional behavior
When to use?
Best when constants belong to a category, like time limits or error codes."