Any matter that has a temperature higher than its surroundings emits radiation at various frequencies. The total amount of radiation and the distribution of the emitted wavelengths depend almost entirely on the temperature of the body and are not characteristics of the material itself. For an idealised black body that absorbs all radiation that falls onto it, this relationship between temperature and wavelength of maximum emission is completely precise. Many astronomical bodies, such as stars, can be considered to be almost perfect black bodies, so we can apply all the characteristics of a black body to them. Let's have a look at the radiation of black bodies at different temperatures:
We can see examples of the spectrum of emitted radiation for seven bodies at different temperatures, ranging from 100 degrees Kelvin to 10000 degrees Kelvin. Please note that this diagram is logarithmic. That means that the difference from one scale point to the next along each axis is a factor of 10! The range of visible light is indicated with the colours of the rainbow between 0.4 and 0.8 µm.
There are two important things to notice:
A red dwarf with a surface temperature of 3000 K emits much more light towards the red end of the visible spectrum, hence it appears red. The hot stars appear blue since they emit a bigger part of their radiation in blue than they do in red. Well, technically they have their peak radiation in the ultraviolet wavelengths that we can't detect. And since in addition our human eyes are not very good at detecting a violet colour (the shortest wavelength we can see) these stars appear blue to us.
It is important to understand the exact radiation pattern of celestial bodies and then scan the sky at all wavelengths. This way we can much better detect bodies within a wide range of temperatures. A brown dwarf with a temperature of 1000 degrees Kelvin needs to be observed in the infrared at about 2 µm; at visible light wavelengths its radiation 100 000 times weaker.