We solve the quantum harmonic oscillator with time-dependent mass and frequency in the Heisenberg picture. The generalized invariant and the exact quantum motions are found in terms of classical solutions. We construct the number state (Fock space) and the coherent state of the invariant or the instantaneous Hamiltonian and find the squeezing operator which connects the Fock spaces of the different invariants. We find the exact Schroedinger wave functions up to time-dependent phase. For a periodic oscillator, we construct the cyclic initial state (CIS) and calculate the corresponding nonadiabatic Berry phase. We find a new type of CIS whose period is a multiple of the period of the oscillator. For the system of harmonic oscillators, the density operator is defined as a function of a generalized invariant. The temperature change driven by the time-varying Hamiltonian is calculated for an adiabatic change and the appearance of nonequilibrium is exemplified for a nonadiabatic change. Finally, we study the quantum fields in the expanding and inflating universe, respectively. In the functional Schroedinger picture, we study the particle creation for the universe with two static geometries and examine the temperature change of the universe for an adiabatic expansion. We calculate the classical solutions and generalized invariants for the scalar fields which are minimally and nonminimally coupled to the gravity. We also calculate the vacuum expectation values of the Hamiltonian density for an adiabatic vacuum of the early universe and a conformal vacuum.