It's not always easy to calculate these things, and astronomers have developed clever techniques to measure them.
Distances: distance is a very tough thing to calculate in astronomy, but there are various ways of doing it. If a star is very close to Earth (a couple hundred light-years with modern technology), the most accurate technique is something called the "parallax"- as the Earth orbits the sun, this causes the stars to move very slightly in the sky, and by measuring that effect we can determine how far away they are.
For objects further away, the parallax doesn't work, so basically what you need to do is find a way to figure out how bright the star is, and compare this to how bright it appears. There are once again various tricks to figure this out (e.g. for distant galaxies, very special supernovae called type 1a supernovae always reach the same brightness so we can use that). There are lots of different methods, each with their own pros and cons.
Surface temperature: actually this one is pretty easy. What you do with this one is look at the wavelengths that star is emitting, and see where in the spectrum that it is brightest. This is known as the "black body" phenomenon and it lets you measure surface temperature quite accurately.
Mass: this one is again a bit harder. Basically what you need is for the star in question to be close enough to another star that they orbit each other- fortunately most stars do this. By measuring how long it takes each one to orbit around the center of mass, you can measure how much the star weighs.
So there are various ways to calculate these things. It's very difficult, though, and lots of things can go wrong. There's a bit of a joke among other fields of science that if a theory is on the same order of magnitude as the measurements (meaning that theory is sort of around the same numbers as the measurement), the astronomers will accept that as good enough.