  In this paper we consider the relation between symmetries and first integrals
for both continuous canonical Hamiltonian equations and discrete Hamiltonian
equations. We observe that canonical Hamiltonian equations can be obtained by
variational principle from an action functional and consider invariance
properties of this functional as it is done in Lagrangian formalism. We rewrite
the well--known Noether's identity in terms of the Hamiltonian function and
symmetry operators. This approach, based on symmetries of the Hamiltonian
action, provides a simple and clear way to construct first integrals of
Hamiltonian equations without integration. A discrete analog of this identity
is developed. It leads to a relation between symmetries and first integrals for
discrete Hamiltonian equations that can be used to conserve structural
properties of Hamiltonian equations in numerical implementation. The results
are illustrated by a number of examples for both continuous and discrete
Hamiltonian equations.
