Blackbody Radiation
Sometimes in physics and chemistry it's better to make predictions by starting with an ideal hypothetical object because its behavior is easier to model, and the behavior of the ideal hypothetical object is a good approximation for how real objects behave. A blackbody emitter is an ideal hypothetical object that can absorb or emit electromagnetic radiation at any wavelength. It does not favor certain specific wavelengths over others. As you increase its temperature, however, it will start to emit more and more radiation at shorter and shorter wavelengths, while the amount of radiation it emits at longer wavelengths will increase more slowly.
Wien's Law
Blackbody objects obey Wien's Law, which says that the wavelength of maximum intensity -- the wavelength at which the blackbody emits more energy -- is equal to a constant divided by the temperature of the blackbody object. This is a fair approximation for many real objects, and astronomers can use it to estimate the surface temperature of an object or star. The hotter the object, the shorter the wavelength of maximum intensity, and the bluer the star will appear, so measuring the ratio of blue light to red light is one quick and dirty way to estimate the approximate temperature of a distant object. This technique isn't very accurate, however, so although astronomers sometimes use it, they prefer a more precise method.
Spectra
Spectra offer astronomers another way to measure the temperature of distant objects. The core of a star emits radiation across a wide range of wavelengths. The atoms in the atmosphere of the star absorb some of that radiation. All elements can only emit or absorb radiation at certain specific wavelengths. The list of wavelengths at which an element can emit or absorb radiation is called the atomic spectrum of that element. As the temperature increases, the element will emit or absorb more energy at wavelengths that are not accessible when it's at low temperatures. If the element is heated to very high temperatures, however, it will become ionized and lose all its electrons, in which case it will no longer absorb radiation at all.
Composition and Temperature
By running the light from a distant star through a prism or a spectroscope, they can split it up into its different wavelengths. Wavelengths where an atom in the star's atmosphere strongly absorbs light will appear as dark bands called spectral lines. Astronomers check these spectral lines against the spectra for known elements to figure out which elements are present in the star's atmosphere. Next, they can determine the likely temperature of the star's atmosphere based on whether certain wavelengths are present or missing from the spectrum. If the star's atmosphere is so hot that all or most of the hydrogen is ionized, for example, the hydrogen atoms will not absorb much light, and the spectral lines for hydrogen will be weak or missing altogether.