A counter variable in Java is a special type of variable which is used in the loop to count the repetitions or to know about in which repetition we are in . In simple words, a counter variable is a variable that keeps track of the number of times a specific piece of code is executed.