Back to Browse

Learn Java timertasks in 6 minutes! ⏲️

8.5K views
Dec 19, 2024
6:23

#java #javatutorial #javacourse import java.util.Timer; import java.util.TimerTask; public class Main { public static void main(String[] args) { // Timer = Class that schedules tasks at specific times or periodically // Useful for: sending notifications, scheduled updates, repetitive actions // TimerTask = Represents the task that will be executed by the Timer // You will extend the TimerTask class to define your task // Create a subclass of TimerTask and @Override run() Timer timer = new Timer(); TimerTask task = new TimerTask(){ @Override public void run(){ System.out.println("Hello!"); } }; timer.schedule(task, 0, 1000); // (task, delay, period) } }

Download

1 formats

Video Formats

360pmp46.5 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Learn Java timertasks in 6 minutes! ⏲️ | NatokHD