We present recent advances in the magnetism and superconductivity of rare earth and uranium compounds. Heavy fermions are formed on the basis of the competition between the RKKY interaction and the Kondo effect in these compounds. The application of pressure to these compounds is useful to control the electronic states in the antiferromagnets CeRh 2 Si 2 and CeRhIn 5 , and the ferromagnet UGe 2 . The quadrupole interaction or the quadrupole Kondo effect is found to be responsible for heavy fermions in PrFe 4 P 12 . A rich variety of superconducting properties are demonstrated: superconductivity of CeCoIn 5 and CeRhIn 5 in the vicinity of a quantum critical point, coexistence of ferromagnetism and superconductivity in UGe 2 , and superconductivity based on the quadrupole fluctuations in PrOs 4 Sb 12 , together with the relation between the superconducting transition temperature and the quasi-two dimensionality of the electronic states.