In this example we will show the method to make the current executing program delay few seconds in Java.
Source Code
package com.beginner.examples;
import java.util.Date;
public class DelayRun {
public static void main(String[] args) {
System.out.println("It is : " + new Date());
try {
Thread.sleep(4000); // delay few seconds
System.out.println("It is : " + new Date());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Output:
It is : Wed Jun 17 02:28:31 UTC 2020
It is : Wed Jun 17 02:28:35 UTC 2020
References
Imported packages in Java documentation: