Java: create a timer - how it works
In this practical tip we will show you how you can easily create a timer in Java.
Create timer with Java
If you are new to Java, you can read our introduction to Java first.
- Add the command "import java.util.concurrent.TimeUnit;" to your code to import the required package.
- The command »TimeUnit.SECONDS.sleep (1);« now makes your program wait exactly one second.
- So you can easily create different timers in Java.
- However, note that this command generates an InterruptedException.
In the next practical tip, we will show you how you can use conditions and loops in Java with precision.