Heterogeneity plays an important role in modeling demographic, epidemic, biological and economical processes. The mathematical formulation of such systems can vary widely: age-structured systems, trait-structured systems, or systems with endogenously changing domains are some of the most common. This thesis investigates necessary optimality conditions of Pontryagin's type involving a Hamiltonian functional. At first, infinite horizon age-structured systems are analyzed. They are governed by partial differential equations with boundary conditions, coupled by non-local integral states. The objective function of problems on the infinite horizon, the objective value may become infinite. Therefore, the necessary optimality conditions are derived for controls that are weakly overtaking optimal. Despite the numerous applications in population dynamics and economics naturally formulated on an infinite horizon, a complete set of optimality conditions is missing, because of the difficult task of defining appropriate transversality conditions. A new approach (recently developed for ordinary differential equations by S. Aseev and V. Veliov) has been used for a system affine in the states, but non-linear in the controls and with a non-linear objective function. Furthermore, a demographic problem: Due to a low birth rate, many countries need immigration to sustain their population size. The age of the immigrants has severe implications on the stability of social security systems, therefore, the optimal age-pattern of immigrants is studied. The problem is on the infinite time horizon with a rather specific equality constraint. It is shown that for the non-concave problem an optimal solution exists, and that this optimal control is time-invariant. A numerical case study is carried out for the Austrian population. A second focus lies on heterogeneous systems with a fixed domain of heterogeneity, which are used in epidemiology to describe the spreading of contagious diseases, but are also employed in economics. While necessary optimality conditions for problems on the finite horizon are known, a Hamiltonian formulation was missing. A Hamiltonian functional is introduced and its constancy shown for autonomous problems. This functional also allows to reproduce the primal and the adjoint system. With explicitly defined solutions of the adjoint system (using the above mentioned approach), it is proved that for a problem on the infinite horizon, any weakly overtaking optimal control maximizes this Hamiltonian. The model is non-linear, and the non-local integral states (which do not depend explicitly on the control) may enter the objective function and the differential equation of the distributed states. The third type of heterogeneous systems considered in this thesis deals with models in which the domain of heterogeneity changes endogenously. Such systems arise, for example, for a profit-maximizing company which can invest to improve existing products, or invest in research to increase the variety of products. A maximum principle for such systems was proved by A. Belyakov, Ts. Tsachev, and V. Veliov. However, the strong form, in which the differential inclusion for the adjoint variable collapses to a differential equation, holds only under an a priori regularity assumption on the optimal control. It is shown for a certain optimal control problem arising in economics, that this regularity assumption is fulfilled. Additionally, in case of stationary data, it is proved that the Hamiltonian is constant along the optimal control.