Let $(\Omega,\mathcal{F},P)$ be a probability space and $X:\Omega\to \mathbb{R}$ a random variable. Then the expected value of $X$ is defined by
$$EX := \int X\,dP$$
Now in undergraduate probability we're often given a distribution function (or the density function)
$$F(x) = \int_{-\infty}^x f(x)\,dx$$
to describe a distribution. In this case we say that $X$ has distribution function $F(x)$ and define
$$EX = \int_{-\infty}^\infty xf(x)\,dx.$$
Since the first definition is supposed to be the most general one, how do we derive the second definition from the first? The second definition doesn't even explicitly give out the random variable $X$ as a measurable function nor even clearly specify what the probability measure is, although I assume it must somehow be the Stieltjes measure defined by extending $P((a,b]) = F(b) - F(a)$.
Anyone care to elaborate on this?
This goes by the lovely name of "Law of the Unconscious Statistician".