Recently I came across code of a desktop alarm. Actually I'm studying the way it is coded. In that the coder has implemented thread for playing sound using sampled package. So I have this doubt that when do we use threads in java. I'm pasting the code here. Thanks in advance.
Please be careful when posting code that isn't yours as you don't want to accidentally infringe someones copyright. Also it's generally considered good practice to quote the source of the code.
In this case you generally don't want the application to freeze whilst a sound is being played so you get a background thread to play the sound.
There are numerous reasons to use multiple threads such as allowing the application GUI to remain responsive whilst a long running task is executed, to run repeating tasks at timed intervals, to listen/wait for external triggers, to speed up execution (ie by splitting a complex task across multiple processors) etc etc.