Stars get their heat from two sources - gravity, and nuclear fusion.
When stars initially form from large balls of gas, they contract under the influence of gravity, and heat up because that gravitational energy goes into the motion of the gas. Once they get hot enough, the hydrogen nuclei in the plasma in the center of the star start to occasionally merge to form helium, releasing a lot of energy from that nuclear fusion process. All this heating, from both sources, creates a pressure that causes the star to quit contracting at some point. If the star is big enough to start with, the central temperature will be high enough to really keep that fusion going, and the heat gradually will seep out to the outside parts of the star, so the outer surface regions will also rise to quite high temperatures. It is the temperature of the outer surface that determines the way the stars shine - our sun has an outer temperature of around 5000 degrees, but other stars can be as hot as 50,000 degrees, producing much bluer light, while red dwarf stars are considerably cooler and produce mostly red and infrared light.