What is the purpose of TimerTask in Java?
TimerTask is an abstract class in Java that represents a task that can be scheduled for execution by a Timer. Its purpose is to allow developers to execute specified tasks at specific time points or intervals. Developers can extend the TimerTask class and implement the run() method to define the specific task logic. The Timer class can schedule the execution of TimerTask and can execute tasks in a one-time or periodic manner. The role of TimerTask includes but is not limited to tasks such as scheduling tasks, timers, and repetitive tasks.