Defining Java Constants

Yeah, I understand. What's the big deal in defining constants in Java. But hold on, and spare me a few minutes. Read on. As a standard practice constants must be defined for values which do not change in the application. The use of string literals and numbers scattered across the code is discouraged. It is always a good practice to define constants for all of those values which is used at multiple places. Let’s first check the rules. Final and Static What makes a literal or a numeric value “ constant ”? Java provides for a keyword “ final ”. Anything that is final cannot be changed once its value is set (in the context of a field). Thus any constant should be accompanied by the keyword “ final ”. The keyword “ static ” however is not mandatory to define a constant. A constant is something which is expected to be used outside the scope of the class, in most probability, would remain the same throughout the application. If that is the case, then the constant ...