Here's java: https://realm.io/docs/java/latest/#access-control
Yes, the user has to be an admin of the realm to set permissions. So user A creates a realm from your app. They are an admin fo the realm that they've created, and then user A can set permissions to share with user B and so on.
Alternatively, you could use a server-wide admin via one of our server side bindings (like node.js or C#). From a script, you could login with the server admin (who has admin access to all realms), and have them set the permissions for any realm as necessary.