When you get infected it takes a while for your white blood cells to deal with them, in the meanwhile this could lead to serious illness or death. To avoid this you can be immunised against some diseases. This involves injecting dead/weak micro-organisms into the body, these carry antigens, though harmless your body still produces antibodies to attack them. If you get then get infected with the same micro-organism used, your body has antibodies to deal with as you already developed antibodies for it.