I would like to calculate the variance of a uniformly distributed continuous random variable. The probability density function of a uniformly distributed continuous random variable is $$f_{X}(x) = \frac{1}{b-a}.$$
To obtain the variance, my book suggests to first calculate the second moment $$E[X^{2}]=\int_{-\infty}^{\infty}\frac{x^{2}}{b-a}dx.$$
However, I fail to see where the expression comes from. The expected value of a random variable is $$E[X] = \int_{-\infty}^{\infty} xf_{X}(x)dx.$$
So, when calculating $E[X^{2}]$ the density part remains the same and $X^{2}$ somehow translates to $x$ in the integral to be raised to the second power. Why does that happen?
[self-study]
please edit to add such tag. $\endgroup$