I think if you wanted it to be a true screensaver, you'd have to do something different for each OS (and use a different programming language).

However, if you want to just do it for fun, you could make it so that after you open your app it has a timer that checks for key input, and if there hasn't been any for long enough it will enter full screen exclusive mode and display your screen saver. You'll need to use something like JInput in order to get key presses and mouse movements when your program is not in focus.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org