Java-Specific Heuristics (J1–J3)
Three Java-focused heuristics: avoid wildcard imports, never inherit constants, and prefer enums over integer constants.
J1 & J2: Imports and Constant Inheritance
J1: Wildcard imports (import java.util.*) hide exactly which classes a file depends on. Explicit imports are a precise, searchable record of what the class actually needs. J2: Implementing an interface solely to inherit its constants is an anti-pattern called the Constant Interface Pattern — it pollutes the implementing class's public API. Use static import instead: you get the constant without the inheritance coupling.
J3: Enums vs Integer Constants
public static final int SUNDAY = 0 gives zero type safety — any int can be passed where a day is expected. An enum DayOfWeek.SUNDAY is named, typed, and exhaustive. Switch statements on enums generate compiler warnings when a case is missing. Enums can carry methods and data. The same principle applies in any language: TypeScript enum and Python enum.Enum provide the same guarantees.
Code Challenge
Replace integer constants with a typed enum to gain exhaustiveness and type safety (J3).
💡Key takeaway
J3 is the most universally applicable: replacing int constants with typed enums eliminates an entire class of silent bugs and makes switch/match statements exhaustively verifiable.
🔧 Some exercises may still have errors. If something seems wrong, use the Feedback button (bottom-right of the page) to report it — it helps us fix it fast.
Hint: J1: explicit imports over wildcards. J2: static import instead of constant interfaces. J3: enum instead of int constants — type safety, exhaustiveness, methods.
✗ Your version