This is about secure Java coding as well as about security in general.

Remember that security is like a chain: as weak as its weakest link.
So use a secure operating system (e.g., OpenBSD), and keep it up-to-date.
Keep your servers in a secure location - if the cleaners or other
maintenance people can access your server hardware, you don't have security.

Read the CISSP paper on Secure Coding.

Check out https://owasp.org.
