Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
We have a parallel plate capicitor with capacitance C ($ C= \epsilon°A/d $) when no dielectric is inside it.
The charge on it is Q(+Q on left and -Q on right).
Now a dielectric slab of dielecteic constant K is placed between plates. (Battery is not connected)
The energy stored in the capacitor is given by 2 mehods:
Judging by your first method, I assume that you have taken the capacitor to be isolated and the potential difference is not held constant by an external source (like a battery). The reason that the second method is not leading to the same answer is because you have applied the wrong equation for energy density. The expression $$u_E = \frac{1}{2} \epsilon_0 E^2$$ is applicable only if the material present in between the plates is vaccum (or even air, if you are willing to consider it's dielectric constant to be $\kappa = 1$). In any other medium, the equation for energy density is $$u_E = \frac{1}{2} \kappa \epsilon_o E^2$$ This equation should follow from the way the equation for energy density is derived (from the case of a parallel - plate capacitor), because $\epsilon_0$ is replaced by $\epsilon = \kappa \epsilon_0$. The rest of the derivation follows suit as usual, and the $\kappa^2$ term becomes $\kappa$ in the denominator, identical to the result from the first method $$ U_E = \frac{Q^2}{2\kappa C_o}$$ provided the capacitors are isolated and the potential difference (voltage) is not maintained by an external source like a battery (Note that the result will be different if that were the case)
The final expression will depend on weather the capacitor is connected to a battery or not. If it is connected , then voltage will remain same , before and after the insertion of dielectric. If the battery is not same then charge conservation will be followed.