If the above code is implemented properly, the characters "Hello, World!" will be printed to the standard output system every two seconds (two thousand milliseconds).
Using a timer can be extremely helpful, and sometimes even necessary. For example, if you want to create something like a spammer program, there are times where you'll need a delay. If you're creating a spammer for a computer game, there are usually things to stop you from sending too many messages at once. Therefore, you'll need a delay to comply with it.
(11-10-2015, 10:01 AM)Harry Wrote: Great share, JAVA is pretty un-complicated once you've gotten used to it. We used to need timers for programs we made in College, however we had a different variation on this!
I'm sure this will help people learn JAVA or at least get them on the road to learning it.
Yeah, I had to do a controlled assessment on it for my GCSE. For me it was piss easy.
That's awesome! One thing about it though, is that while it's waiting on the timer to be ready, it's constantly running through the while loop! If you want to ensure that the CPU isn't spending all its time iterating through that loop, you might want to put a small rest time in there, something like Thread.sleep(5) which won't really be noticed unless your project requires very precise timing.