August 2017

Java Timer

  • Satish 

1. Timer – the Basics Timer and TimerTask are java util classes used to schedule tasks in a background thread. In a few words – TimerTask is the task to perform and Timer is the scheduler. 2. Schedule a Task Once 2.1. After a Given Delay Let’s start by simply running a single task with the help of a Timer: @Test public void givenUsingTimer_whenSchedulingTaskOnce_thenCorrect() { TimerTask task = new TimerTask() { public void run() { System.out.println(“Task performed on: ” + new Date() + “n” + “Thread’s name: ” + Thread.currentThread().getName());… Read More »Java Timer

Iterating over Enum Values in Java

  • Satish 

1. Overview Enum in Java is a datatype that helps us assign a predefined set of constants to a variable. In this quick article, we’ll see different ways in which we can iterate over an Enum in Java. 2. Iterating Over Enum Values Let’s first define an Enum, so that we can create some simple code examples: public enum DaysOfWeekEnum { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY } Enums do not have methods for iteration like forEach() or iterator(). Instead, we can use the array of the Enum values returned… Read More »Iterating over Enum Values in Java