When a Java Virtual Machine starts up, there is usually a single non-daemon thread (which typically calls the method named
mainof some designated class).
Threads in java are created as non daemon default, and the prolongs life time of application
Lets explain with examples
In example 1, process prints current time at each 1 sec period endlessly since thread of Timer is non deamon, and JVM waits for job completion of that thread.
In example 2, nothing is printed and process is terminated without waiting timer to do its job since Timer thread is created as daemon, see line 8.
In example 3, timer gets chance to execute during 10 seconds since main thread waits 10 sec (see line 19) and than process is terminated since main thread does its job after line 19 and thread of timer is a daemon thread which does not prevent JVM to terminate the process.