Periodic orbits of differential systems via the averaging theory with special emphasis on Hamiltonian systems