Write a java code to demonstrate concurrency.

Operating system

Write a java code to demonstrate concurrency. Write the following java code in different java code form but same context and explanation as well.

public class Counter implements Runnable {

private int count;
public Counter() {
count = 0;
}
public void run() {
for (int i = 0; i < 5; i++) {
count++;
System.out.println(“Count is ” + count + ” in thread ” + Thread.currentThread().getId());
}
}
public static void main(String[] args) {
Counter counter = new Counter();
Thread thread1 = new Thread(counter);
Thread thread2 = new Thread(counter);
thread1.start();
thread2.start();