Consider a random variable $X\sim\text{Uniform}[e, e^2]$ and define the new random variable $Y = \ln(X)$.
A) How do we compute $E(Y)$, using the theorem that states that $$E(g(X)) = \int_{-\infty}^{\infty} g(x)f_{X}(x) dx$$
B) How do you compute $E(Y)$ by computing the probability density function of $Y$ first?
(A) Take $g(x)=\ln(x)$ to get \begin{multline*} \mathbb{E}\left[Y\right]=\mathbb{E}\left[\ln(X)\right]=\int_{-\infty}^{\infty}\ln(x)f_{X}(x)dx=\int_{-\infty}^{\infty}\ln(x)\frac{\boldsymbol{1}_{(e,e^{2})}(x)}{e^{2}-e}dx\\ =\frac{1}{e^{2}-e}\int_{e}^{e^{2}}\ln(x)dx=\frac{e^{2}}{e^{2}-e}. \end{multline*}
(B) If $1<y<2$, then \begin{multline*} F_{Y}(y)=\mathbb{P}(Y\leq y)=\mathbb{P}(\ln(X)\leq y)=\mathbb{P}(X\leq e^{y})=\int_{-\infty}^{e^{y}}f_{X}(x)dx\\ =\int_{-\infty}^{e^{y}}\frac{\boldsymbol{1}_{(e,e^{2})}(x)}{e^{2}-e}dx=\frac{1}{e^{2}-e}\int_{e}^{e^{y}}dx=\frac{e^{y}-e}{e^{2}-e}. \end{multline*} Taking derivatives, it follows that $$ f_{Y}(y)=\frac{e^{y}\boldsymbol{1}_{(1,2)}(y)}{e^{2}-e}. $$ Therefore, $$ \mathbb{E}\left[Y\right]=\int_{-\infty}^{\infty}yf_{Y}(y)dy=\int_{-\infty}^{\infty}y\frac{e^{y}\boldsymbol{1}_{(1,2)}(y)}{e^{2}-e}dy=\frac{1}{e^{2}-e}\int_{1}^{2}ye^{y}dy=\frac{e^{2}}{e^{2}-e}. $$ This is the same answer as was obtained in part (A).