You can use heat to kill the bacteria/viruses; even when they are dead, they still carry the antigens that your cells use to recognize them and mount an attack against them, even though they can't harm you. Memory cells will be generated in the process so the body is better prepared for the next "invasion".
-
Often times, the bacteria and viruses are fundamentally mutated so that they are no longer pathogenic, but still retain the ability to stimulate an immune response. This process is called "attenuation". Other times, they are actually killed.
-
Weaken a bacteria or virus are basically attenuated bacteria/virus. Attenuation occurs by either heating the culture or slightly "killing" them. You can also give a very small amount to build immunity.