The "formula" for $E(X)$, the expectation of the random variable $X$, also called the first moment of $X$ about the origin, is $E(X)=\int_{-\infty}^{\infty} tf_X(t)\,dt,$ where $f_X(t)$ is the density function of the random variable $X$. Since $f_X(t)$ is $0$ on the interval $(-\infty,0)$, and also on the interval $(1,\infty)$, these parts make no contribution to the integral. If you want to be formal about this, we have for example $\int_{-\infty}^0 (t)(0)\,dt=0$. Because the density function is $0$ in this interval, there is no "weight" there, no contribution to the average value $E(X)$. The same is true for the interval $(1,\infty)$.
Since the density function is $1$ between $0$ and $1$, we want to find $\int_0^1 (t)(1)\,dt,$ which is just $\int_0^1 t\,dt.$ To calculate the integral, we find an "antiderivative" $G(t)$ of $t$. Then our definite integral is $G(1)-G(0)$. An antiderivative of $t$ is given by $G(t)=\dfrac{t^2}{2}$. You may remember this, and if you don't, you can check that it works by differentiating. Finally, $G(1)-G(0)=\dfrac{1^2}{2}-\dfrac{0^2}{2}=\dfrac{1}{2}.$
For $E(X^2)$, use the same reasoning. We end up needing $\int_0^1t^2\,dt.$ Finally, $H(t)=\dfrac{t^3}{3}$ is an antiderivative of $t^2$. Now calculate $H(1)-H(0)$.