Rainbow tables exploit pre-computed hashes of common passwords. By adding a unique salt to each password, the resulting hash is distinct, making rainbow tables ineffective. In Java, using BCrypt's gensalt() method generates a unique salt for every password.
Additional Notes
How does a unique salt defeat rainbow table attacks?