> It is simply a matter of exiting the program that you have written.
Well, it's true that it's the normal way to exit a single-function
"main" style program, but System.exit does more than just exit your
program -- it also shuts down the vm, takes down running threads, may or
may not run finally{}'s, etc. It is a pretty harsh way to exit a
program, more the equivalent of an OS shutdown than a function exit.
On the other hand, to do any better you have to do some form of IPC.
I realize the OP is doing something relatively trivial with a program
that runs in main() and so is nervous about using exit(). It's
perfectly reasonable and common to exit main with System.exit(), but
that doesn't stop it from being a nasty, ugly thing to do. It's also
the only realistic way to get a shell exit code for a utility program.