A new theory is presented for calculating the structure of finite nuclei from the nucleon-nucleon interaction. The essential features of the reaction matrix in finite nuclei are obtained from nuclear-matter theory through the local-density approximation. The resulting density- and energy-dependent effective interaction is justified in detail, and it is shown that the tensor force plays an important role in saturation. The effective interaction is cast into two different forms, one convenient for use in calculating matrix elements and the other specialized for a Hartree-Fock calculation in position space. The density-dependent Hartree-Fock equations are derived by variation of the ground-state expectation value of the energy, and in addition to the usual Hartree-Fock terms, one obtains rearrangement terms arising from the variation of the density appearing in the density-dependent interaction. The appropriate angular-momentum reduction for closed j-shell nuclei is performed. The need for modifying the effective interaction to account for higher-order corrections is discussed, and the constraints imposed on this modification by the properties of nuclear matter are examined. The results of this theory for O16, Ca40, Ca48, Zr90, and Pr208 are shown to yield very satisfactory agreement with experimental binding energies, single-particle energies, and electron scattering cross sections. The rearrangement terms in the density-dependent theory are demonstrated to have two essential effects on nuclear structure: a significant reduction in the central density of the nucleus, and a modification of the usual Hartree-Fock relation between single-particle energies and the binding energy. Equivalent local single-particle potentials are calculated and are shown to have significant state dependence.