nohup is a Unix command that is used to run another command while suppressing the action of the HUP (hang-up) signal, enabling the command to keep running even after the user who issues the command has logged out. 

The question that comes to mind is can SIGHUP (hangup signal) be handled? You are in luck; we can trap it and define the action to execute upon receiving a SIGHUP, such as calling a function, ignoring it, or restoring the default action. The default action on POSIX-compliant systems is an abnormal termination of the program.

Once a program starts, it opens descriptors for stdin, stdout and stderr streams.
Either have your program close those descriptors or redirect them to /dev/null.  You probably want to use “nohup” to prevent the program from terminating abnormally on receiving SIGHUP e.g. here we start the java program using nohup and redirecting the all the 3 descriptors to /dev/null while running the program in background.

nohup java -cp . Test </dev/null >/dev/null 2>&1 &

Adding nohup to background jobs is recommended as logging out of the shell can cause the shell to hang on logout due to a race condition. This problem can also be overcome by redirecting all three I/O streams e.g. the stdout to foo.out, stderr to foo.err and stdin to /dev/null.

nohup myprogram > foo.out 2> foo.err < /dev/null &