Export RGB Image by code: jpeg "opaque" output

JPEG does not support transparency. Why it looks like it does when you export from the SANP Desktop is the background colour of the image view. In your Java code the no-data area is probably filled black and in SNAP desktop the bakground colour is used.
Both scenes shown are exported in the Desktop. On the left is the JPEG and on the right the PNG. You can see the difference:


You can test it by changing the background colour in the settings.