Potential energy from a conservative force

A conservative force's work depends only on the endpoints, so it can be stored as potential energy with $\Delta U = -\int F\,dx$ and $F = -dU/dx$, giving $\frac{1}{2}kx^2$ for a spring and $-GMm/r$ for gravity.

From AP Physics C: Mechanics.