Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This might seem like an odd question, but I'm worried that I'm putting too many things as constants/finals at the top of my java class. I've started to put every value that is in my program into a constant (At least the ones that influence it's overall effect). The reason I'm doing it is because then it's easy to find the values and change them latter, even if they are only used once, it's easier to find them at the top. Is this a bad or good practice, I really have no idea.

Here's an example:

private static final Color COLOR_SELECTED = Color.BLUE;
private static final Color COLOR_ALTERNATE_ONE = Color.WHITE;
private static final Color COLOR_ALTERNATE_TWO = new Color(240, 240 , 240);
private static final Color TEXT_COLOR =;
share|improve this question
COLOR_SELECTED doesn't read like a constant at first glance (sounds like a variable I.E. what is the currently selected color or something)... maybe you should rename it to SELECTED_TEXT_COLOR or whatever it really means. – Esailija May 25 '13 at 12:20
@Esailija Thanks, I will. – sinθ May 25 '13 at 20:42
up vote 4 down vote accepted

No, this is not a bad thing. Your code will be able to refer to TEXT_COLOR and consistently get Even if you only use it once now, you might use it more than once as your code continues to develop.

An even better thing would be to read these values from a properties file, so you could change them without recompiling. But that's only something to worry about if you think the colours used might actually change in the future.

share|improve this answer

This is a good practice! This is equivalent to the idea of removing magic numbers.

In the future, if you want to change the color of something that is selected, you can do it in one place. Trying to look for every instance of Color.BLUE might not be incorrect if a different item also uses the color blue.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.