Check out example codes for "java intercept ctrl c". It will help you in understanding the concepts better.

Code Example 1

Runtime.getRuntime().addShutdownHook(new Thread() {
    public void run() { /*
       my shutdown code here
    */ }
 });

Learn ReactJs, React Native from akashmittal.com