U is used for molecular mass, g is used for molar mass.
The mass of 1 molecule of a compound in u is exactly equal to the mass of 1 mole of a compound in grams.
u is a unit of mass for particles of very small sizes. It is equal to 1.66 x 10^-27 kg. It is used for measuring the mass of protons and neutrons and also molecules (the mass of molecules is mostly due to protons and neutrons).
g is used for measuring greater masses.