|MadSci Network: Astronomy|
This is a very good question! Color turns out to depend on the wavelength of the light emitted by an object. Light, as you may have heard, is in many ways nothing more than a wave (similar to a water wave you make by dropping a pebble into a still pond). The wavelength is then just the distance between two successive wave crests. Light can actually have any wavelength, and the wavelength of the light determines which part of the electromagnetic spectrum it is in. For example, radio waves have relatively long wavelengths, in the meter range, while gamma rays have very short wavelengths (even smaller than the size of an atom!). The energy of each "photon" (or individual packet of light) in the light ray is inversely proportional to the wavelength of the light. In other words, gamma ray photons have more energy than radio photons.
Visible light is somewhere in the middle, with wavelengths between about 400 and 700 billionths of a meter. Blue light has a smaller wavelength than red light; they are at opposite ends of the visible spectrum, as I'm sure you know. This means that blue photons have more energy than red photons. This indicates that hotter objects, which have high energies, probably emit more energy in blue photons than cool objects do.
For some objects, known by the slightly confusing name "blackbodies," this is indeed true. These are dense objects that perfectly absorb light. Basically, any solid or dense gas that is hot enough will be a blackbody (like hot iron, or the sun). The spectrum of the light emitted by these objects can be described mathematically, and it turns out that the wavelength where most of the light is emitted is inversely proportional to the temperature of the object. Therefore, the hotter an object is, the bluer it will be. An object at about 7000 degrees Celsius will be blue, while an object at about 4000 degrees will be red. This is why we say that hot stars are blue and cool stars are red. Anything cooler than 4000 degrees will have most of its emission in non-visible light - but it will emit more in the red range than in the blue range, because the former is closer to the peak. This is why almost all the heated objects we see are red - we rarely get things hot enough to be blue!
There are, however, other reasons why objects can have colors. Obviously, blue and red shirts are the same temperature, so that can't be the only explanation! The most important is the chemical properties of the object. It turns out that each kind of atom (hydrogen, sodium, helium, etc.) only emits and absorbs very specific wavelengths of light. Molecules, which make up most objects, absorb light over ranges of wavelengths, transmit some wavelengths, and reflect the rest. We see this reflected light, and that's what gives it the color we see on shirts, cars, leaves, etc. (Clear glass, for example, transmits all visible wavelengths, which is why it is transparent.)
This also explains why most fireplace-fires are orange/yellow: the burning process breaks bonds in molecules made up of carbon and hydrogen that emit yellow light. (If there's lots of soot in the fire, the soot particles will act as blackbody particles, so you will get more red light that way.) If we put magnesium in our fireplaces, we'd see bluer light because of its atomic properties (and get some explosions; I wouldn't recommend this!). (Incidentally, this is why astronomical nebulae are often red: the hydrogen in the nebula has a strong emission line in the red range. See http://apod.gsfc.nasa.gov/apod/ap001122.html for an example.)
As to your question of why people consider red to be a warm color and blue to be cold, your guess is probably as good as mine! But I would say that it has to do with our everyday experience. Nearly all of the fires that we see are red, both because we rarely see anything heated to very high temperatures and because of the properties of carbon and its molecules. Meanwhile, the molecular properties of water make it bluish-green. Since these are the hot/cold things we most often see, our minds probably associate hot and cold with them. This is an example of how we have to be pretty careful when applying our everyday intuition to objects as strange as stars!
[I would add that our bodies might also bias us toward thinking red is hot and blue is cold. When we get warm, more blood flows to our skin in an effort to cool us. The result is that our skin looks red. If we are cold, the body tries to conserve heat by shunting blood away from our skin, giving out skin a bluish tinge. Moderator.]
Try the links in the MadSci Library for more information on Astronomy.