Stored JavaScript functions are not the equivalent of server-side stored procedures and cannot be directly invoked from your Java code. These functions are only useful in a JavaScript execution context (for example, the mongo shell or Map/Reduce).
The db.loadServerScripts() command in the mongo shell eval()s saved scripts into the current shell session so those functions can be invoked client-side. The server eval command has been deprecated since MongoDB 3.0 and removed as of MongoDB 4.2. It had serious performance and security consequences and should not be used.
You should write your queries using the Java driver. See the Java driver tutorials for more examples.
I strongly recommend you sign up for the free M220: MongoDB for Java Developers course at MongoDB University. The latest session just started this week, so if you join now you can get started with lessons and assignments that will accelerate your learning around the essentials of creating a Java application using MongoDB.