In the book of Griffith intro to electrodynamics, on page 94, the energy of continuous charge distribution is derived in the following way:
W(total energy) = $\frac{1}{2} \int\rho V d\tau$, where $\rho$ is volume charge density, V is potential at that point and $d\tau$ is infinitesimal volume element.
Then, using $\rho = \epsilon_0 \nabla \cdot E$, one gets:
$\begin{align} W = \frac{\epsilon_0}{2} (-\int (\nabla\cdot E)V d\tau \qquad.......(1)\end{align}$
After which, he uses integration by parts to get:
$\begin{align} W = \frac{\epsilon_0}{2} (-\int (\nabla V)\cdot \,E\ d\tau\quad + \oint V\,E \cdot da ) \qquad.........(2)\end{align}$
I am unable to understand how one goes from equation 1 to 2. Please provide me detailed process rather than hints.