If you take a light source and split it into it's component parts with a spectrometer (which is a glorified prism although gratings can be used) you'll see the spectrum of colours.
If you examine it carefully you'll see dark bands in the spectrum. These dark bands correspond to materials in the light source absorping light at certain frequencies.
The bands can also be bright rather than dark depending on the set up.
Different materials have different 'fingerprints' of lines and you can work out what materials are in the sources.
The element Helium was actually first discoverred in the Sun using this technique (hence it's name) before it was discoverred on the earth.
So if you compare the spectra of your sources you can tell what is present.
If the source is heading away from you rapidly the bands will appear further down the spectra than they would if you were looking at a stationary source they would be 'red shifted' (blue shifted if they were heading towards you)
The bands will broaden more the hotter the source is.
So by comparing the spectra of two sources you cand determine a) what is present in them b) if they are moving relative to you or not. c) how hot the source is.
See here for more:
http://en.wikipedia.org/wiki/Spectral_line