Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of java.awt.Color.blue and java.awt.Color.BLUE

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 ?

like image 472
ring bearer Avatar asked Apr 03 '12 16:04

ring bearer


1 Answers

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

like image 168
mre Avatar answered Sep 24 '22 23:09

mre