For example 2, we are aiming to find an approximation for $I= \int_0^{1} \frac{1}{1+x}dx$. To this aim we will do the following:
Let $U$ be a uniform distribution defined as $U \sim [0,1]$. Then the we have the pdf of $U$, denoted $g$ , is defined as follows: $$ g(x)=\begin{cases} 1 \quad x \in [0,1] \\
0 \qquad elsewhere
\end{cases} $$
Thus given $f(x)= \frac{1}{1+x}$, then $$E[f(U)]=\int_0^{1} f(x) g(x)dx=\int_0^{1} \frac{1}{1+x} dx $$
Thus using this above equality we are able to estimate $I$ by estimating the expectation. Taking a sample $\{ x_i\}_{i=1,..,n}$ of $n$ points in $[0,1]$, then $I$ can be estimated by $$ I \approx \frac{1}{n} \sum_{i=1}^n \frac{1}{1+x_i} $$