//deprecated in main thread:
try {
Thread.sleep(1000);//time is in ms (1000 ms = 1 second)
} catch (InterruptedException e) {e.printStackTrace();}
//please use bellow instead:
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
//what you want to do
}
}, 1000);//wait 1000ms before doing the action
import java.util.Date;
public class JavaHungry {
public static void main(String args[]) {
try
{
System.out.println("Start of delay: "+ new Date());
// Delay for 7 seonds
Thread.sleep(7000);
System.out.println("End of delay: "+ new Date());
}
catch(InterruptedException ex)
{
ex.printStackTrace();
}
}
}