There seem to be few open source Java libraries for optimizing images. But there are many libraries that offer image optimization as part of their functions.
For instance:
im4java is a pure java library that offers ImageMagick interfaces that can be used to optimize images.
ImageJ , it can be used as a library according to this answer
source share