For a very simple numeric only value, you can use the exit() method. IIRC, it's in java.lang.System.Runtime.
For more complex return values such as larg numbers, signed numbers, text
string, and so forth, the easiest thing to do is use System.out.println() to send the data to the stdout stream, which can then be piped into another Unix command. The "read" BASH command can be used to store returned stdout.
Use of stdout for this purpose is quite common. For example:
echo "Hi" | mail -s "Hello there"
moose@javaranch.com The mail program gets its message body on stdin, so you can use the "echo" command to place a string on stdout, which gets piped into stdin for the "mail" command.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.