The Artima Developer Community
Sponsored Link

Java Buzz Forum
What is the difference between BLACK and black?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Goldy Lukka

Posts: 1008
Nickname: xyling
Registered: Jan, 2004

Goldy Lukka is a Java Developer and an Entrepreneur. He is Founder of xyling.com.
What is the difference between BLACK and black? Posted: Aug 17, 2005 1:12 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Goldy Lukka.
Original Post: What is the difference between BLACK and black?
Feed Title: Xyling Java Blogs
Feed URL: http://www.javablogs.xyling.com/thisWeek.rss
Feed Description: Your one stop source for Java Related Resources.
Latest Java Buzz Posts
Latest Java Buzz Posts by Goldy Lukka
Latest Posts From Xyling Java Blogs

Advertisement
Sounds weird? Well, there is BIG difference in case you are playing with java.awt.Color class.

Recently, in one of my swing applications, I used the following to code to set black as a background color for my textaread:
mytextarea.setBackgroud(java.awt.Color.BLACK);

It compiled well but when I gave this application to one of my friend he cried pasting the following stack trace:

Exception in thread "main" java.lang.NoSuchFieldError: BLACK
at MyClass.initComponents(MyClass.java:74)


He exclaimed saying he has installed the latest JDK (1.5) in his machine.

After a bit of investigation, I came up with the following abstract:

BLACK is a static final field in the class java.awt.Color that represents a "black" color RGB values.
The whole issue here is that, till 1.3.x versions, they had a variable called "black" (read case sensitive). May be later in 1.4.x they realized that it is not a standard practice to do so and they define additional variable named "BLACK" to represent the same thing.

Now, when my friend would have tried executing this, his default JRE could not have recognized BLACK because it would be 1.3.x or earlier.

Another question that arises is, if someone installs JDK 1.4.x, why would 1.3.x or older would be his default JRE? The reason is, it could be because of installing any of these:
1. Web browser bundling JRE or earlier versions.
2. Oracle database.
3. Softwares requiring Java and bundling JRE alongwith.

How to see what version of java is default?
Simplest. Just open a command prompt and type java -version


Workaround for this? (In windows)
1. Change the registry value. Well, better not play with it.
2. Go to my computer icon and right click. go to advanced tab -> environment variables settings, for all users, set the FIRST entry of path environment variable to your jdk bin directory.

It worked!!! :-)

[Resource-Type: Tip; Category: Java/Swing/JFC; XRating: 3]

Read: What is the difference between BLACK and black?

Topic: Trivial Text Messaging Protocol (working name) Previous Topic   Next Topic Topic: Pickle Hat [Flickr]

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use