The best way is to run
Process p = Runtime.getRuntime.exec("groups `whoaim`");
and try to parse string to get group call root. Your JVM process could be run by user not call root but i.e. moderator but this user could be in root group and you have root privileges.