By encoding user input before storage. Frame the concept in practical terms so you can explain it during interview discussion.
Stored XSS can occur when user input is stored and later displayed on a web page without proper encoding. To prevent this in Java applications, encode user input before saving it to the database and before displaying it in the UI. Use libraries like OWASP Java Encoder to escape characters that could be interpreted as HTML or JavaScript.
Additional Notes
How can you mitigate stored XSS in a Java application?