Initially each star was a huge cloud of gas and dust spread out in an area of space. At some point this gas was made to be unstable, perhaps by a supernova shock-wave in the interstellar medium, and began to collapse under the influence of gravity. As gas collapses or is compressed it heats up. An object that is above absolute zero emits a spectrum of radiation that depends mostly on it's temperature and a little bit on its composition. As the gas collapsed further the temperature rose higher and higher. Finally, once the gas had collapsed into a large spherical shape, the temperature finally reached the point where hydrogen could begin fusing in it's core, and thus the star is born.
One key thing here to understand is that the star gets its energy initially from gravitational collapse. Just like a falling object has energy, a collapsing gas cloud does too. Fusion effectively replaces the gravitational energy lost by radiation.
We use spectrographs on a telescope to separate the light into a spectrum, like a prism does to white light, and a camera to record the light itself.
See here: http://en.wikipedia.org/wiki/Stellar_classification
Stars do not show a continuous spectrum, although they may appear to if your instrument isn't sensitive enough to separate or record the lines.