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 = Color.black;
  • 1
    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, 2013 at 12:20

2 Answers 2


No, this is not a bad thing. Your code will be able to refer to TEXT_COLOR and consistently get Color.black. 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.


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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