Java source code to determine when application exit by print a line of text on command prompt

*************************************************************
COMPLETE SOURCE CODE FOR : DetermineWhenApplicationExit.java
*************************************************************


public class DetermineWhenApplicationExit
{
public static void main(String[]args)
{
Runtime.getRuntime().addShutdownHook(new Thread()
{
public void run()
{
//Application will print "BYE" when it close
System.out.println("BYE");
}
});

//Make this application terminate
System.exit(0);
}
}


*************************************************************
JUST COMPILE AND EXECUTE IT
*************************************************************