Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Why does the Color class have two variables for each color?

  1. #1
    Member
    Join Date
    Mar 2010
    Posts
    271
    Thanks
    21
    Thanked 7 Times in 7 Posts

    Default Why does the Color class have two variables for each color?

    Hey guys,

    I'm curious, why does the Color class have two variable for each color. For example, for color white, WHITE and white. Why does it have both if the do they same job?


    -Mel


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Why does the Color class have two variables for each color?

    I suspect it has something to do with the Java naming conventions. Prior to Java 1.4, the there were only camel case static color fields (white, black, etc.). However, beginning in 1.4 they added the all-caps versions, probably to indicate that these are to be treated as constants.

    This is just speculation, though. I didn't find any hard evidence why the upper case versions were added.

  3. #3
    Member
    Join Date
    Mar 2010
    Posts
    271
    Thanks
    21
    Thanked 7 Times in 7 Posts

    Default Re: Why does the Color class have two variables for each color?

    I see. Sounds like it very well is the reason. Though if it is, why do the lower case variables still exist?

  4. #4
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: Why does the Color class have two variables for each color?

    why do the lower case variables still exist?
    My guess would be that Sun/Oracle would be rather careful before breaking existing code that uses the lowercase variables.

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Why does the Color class have two variables for each color?

    Quote Originally Posted by Melawe View Post
    I see. Sounds like it very well is the reason. Though if it is, why do the lower case variables still exist?
    I'd agree with helloworld's hypothesis. And if this is the case they probably still exist for backwards compatibility - all legacy code that relies on the lower case would break if they were removed, and in many cases updating legacy code is a nightmare and not worth the effort.

  6. #6
    Member
    Join Date
    Mar 2010
    Posts
    271
    Thanks
    21
    Thanked 7 Times in 7 Posts

    Default Re: Why does the Color class have two variables for each color?

    Quote Originally Posted by copeg View Post
    I'd agree with helloworld's hypothesis. And if this is the case they probably still exist for backwards compatibility - all legacy code that relies on the lower case would break if they were removed, and in many cases updating legacy code is a nightmare and not worth the effort.
    I was going to say that if pbrock was right, that problem ought to be solved by now. Esp since 7 is out(almost) now. Though, now that you bring up legacy code, I can see why.

    I wonder if they plan on removing them.

Similar Threads

  1. Help me Color in this section
    By Bagzli in forum AWT / Java Swing
    Replies: 1
    Last Post: March 30th, 2012, 04:13 PM
  2. JTable Row Color
    By ellias2007 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 23rd, 2012, 01:29 PM
  3. text color changer based on words/ word classification by color
    By knoxy5467 in forum Java Theory & Questions
    Replies: 25
    Last Post: June 15th, 2011, 07:52 AM
  4. Trying to output color....HELP PLEASE!
    By toppcon in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 15th, 2011, 10:52 PM
  5. Color Problem
    By aussiemcgr in forum Java Theory & Questions
    Replies: 5
    Last Post: July 12th, 2010, 03:53 PM