Java supports the use of various types of literals, such as integers (5, 2), floating-point numbers (2.5, 6.022e+23), characters ('a'
, '\n'
), Booleans (true
, false
), and strings ("Hello\n"
). Extensive use of literals in a program can lead to two problems: first, the meaning of the literal is often obscured or unclear from the context (magic numbers); second, changing a frequently used literal requires searching the entire program source for that literal and distinguishing those the uses that must be modified from those that should remain unmodified.
...