Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Color.red and Color.RED

Tags:

java

colors

What's the real difference between definitions for setXxx(Color.red) and setXxx(Color.RED)?

I've found the following explanation on the web. Is it all about naming conventions?

Java originally defined a few color constant names in lowercase, which violated the naming rule of using uppercase for constants. 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

like image 436
mKorbel Avatar asked Sep 02 '11 08:09

mKorbel


People also ask

Do we say Colour red or red Colour?

Red is a color. You don't usually say "red (as an adjective) color"; the use of the red (as a noun) on its own (without color after it) means that you are talking about the color that's red. The same rule applies to all colors, such as green, yellow, blue.

What is difference between Colour and color?

Difference Between Color and ColourColor is the spelling used in the United States. Colour is used in other English-speaking countries. The word color has its roots (unsurprisingly) in the Latin word color. It entered Middle English through the Anglo-Norman colur, which was a version of the Old French colour.

Why do we call the color red red?

Red was the first basic colour term added to languages after black and white. The word red derives from Sanskrit rudhira and Proto-Germanic rauthaz. One of the first written records of the term is from an Old English translation (897 ce) of Pope St.


2 Answers

There's the code itself:

public final static Color red = new Color(255, 0, 0);  public final static Color RED = red; 

The upper case letters were introduced in JDK 1.4 (to conform to its naming convention, stating that constants must be in upper-case).

In essence, there are no difference at all (except letter casing).


If I want to really be brave, Oracle might go wild and remove constants that is lower-cased, but then that would break all other code that's written pre-JDK 1.4. You never know, I would suggest sticking to uppercase letters for constants. It first has to be deprecated though (as mentioned by Andrew Thompson).

like image 158
Buhake Sindi Avatar answered Oct 12 '22 07:10

Buhake Sindi


There is really no difference. See the Color class:

/**  * The color red.  In the default sRGB space.  */ public final static Color red       = new Color(255, 0, 0);  /**  * The color red.  In the default sRGB space.  * @since 1.4  */ public final static Color RED = red; 
like image 38
Jan Zyka Avatar answered Oct 12 '22 05:10

Jan Zyka