The best definition depends on the system you are using and what quantity is being is considered. It is inversely proportional for the damping rate of the system. In general, it can be defined in terms of the value of oscillating (amplitude, energy, electric field, etc.) over the loss per cycle. For a mechanical (classical) oscillator it can be used to measure how quickly (or slowly) the motion dissipates; hence
For an optical cavity one typically defines it in terms of of resoance frequency over the width of the resonance. In any case, you can read a small book called "Vibrations and Waves" by A. P. French (M.I.T Introductory Physics Series) and for optical systems, any good laser physics book contains the definition of the quality factor (Milonni's Laser Physics and Siegman's Lasers are two good references.) And of course, you can use good old Google.
Refers to a damped oscillator. Is a quotient of two characteristic energies multiplied by 2 pi. The energies are: 1. Maximum energy stored in the oscillator and 2. energy lost (by damping) in one cycle. If one would not take the energy loss per cycle but the energy loss per phase angle (in rad) one would not have the factor 2 pi. In the French literature one finds 'finesse' for the quality factor (q-factor, Q).