All vertebrates have an adaptive immune system. This protects them against many infections and diseases caused by viruses and bacteria. V(D)J is the basic mechanism. The work is done by developing lymphocytes (B cells and T cells). They make the immune system adaptive. What this means is that the body is able to defend against many infections it has never met before, and the defence gets better against repeat attacks from the same agent.
The details are very complex. The system makes sequences of amino acids which bind on to the corresponding sequences of infective agents. The system also recognises "altered self cells" as seen in cancer. Of course all systems have limits, so when the system fails to recognise a pathogen or cancer, we suffer the consequences.