Why there are two Color
constants defined in java.awt.Color
class? For instance
public static final Color blue;
public static final Color BLUE;
This is obviously redundant. Is there some specific usage scenario - like a best practice where upper case Color is preferred over lower case Color or vice-versa ?
It's a naming convention thing.
Java originally defined a few color constant names in lowercase, which violated the naming rule of using uppercase for constants. These are best to use since they are available in all versions of Java:
Color.black
,Color.darkGray
,Color.gray
,Color.lightGray
,Color.white
,Color.magenta
,Color.red
,Color.pink
,Color.orange
,Color.yellow
,Color.green
,Color.cyan
,Color.blue
Java 1.4 added the proper uppercase names for constants:
Color.BLACK
,Color.DARK_GRAY
,Color.GRAY
,Color.LIGHT_GRAY
,Color.WHITE
,Color.MAGENTA
,Color.RED
,Color.PINK
,Color.ORANGE
,Color.YELLOW
,Color.GREEN
,Color.CYAN
,Color.BLUE
Source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With