When body is exposed to antigens ( bacteria or something) the body produce anti bodies to resist these antigens and hopefully kill them. If it is the first time ur body is exposed to this antigens, ur body will have a reaction due to this 'invasion' ie u experience fever. Subsequently, ur body remembers the experience w dealing this antigen and will produce and store specific antibodies and kill these antigens the next time u are exposed to it.
Hope it helps