Scheduling Task using Timer in Java

Java provides class called Timer using which you can schedule task at specific intervals.

Signature of Schedule method of Timer class follows as 
schedule(TimerTask task, Date firstTime, long period)

Here, task is the task to be executed
firstTime is firstTime at which task to be executed first
period is interval time in milliseconds at which task will be executed automatically at this interval.

Creating Thread using Extend and Runnable in Java

In Java, You can create thread using 2 ways.

1. Using extend Thread
  •  MyThread t1 = new MyThread("Thread t1"); 
  • where MyThread is class which extends Java's Thread Class.
2. Using implements Runnable
  •    MyRunnable runnable = new Runnable();
  •    Thread t1 = new Thread(runnable,"Thread t1");   
  •     where MyRunnable is class which implements Runnable Interface.

Implement your own LinkedList using Java

LinkedList consist of Nodes where each Node represent two things. One is Data and other is reference to Next node.

Let's check How you can create your own LinkList Implementation :)
  1. Create Node class containing two things. Object (basically data which node will hold) and Node which is reference to Next Node
  2. Create Your Own linkedList class which will have following methods.
    1. add(Object data) - add element to tail of LinkedList
    2. add(Object data,int index) - create new Node and add that new node containing given data at specific index.

Immutable Collections Vs Unmodifiable Collections in Java

Unmodifiable Collection is kind of collection which is readonly view of Collections. You can not do modification into this kind of collections. They always present Latest Value. If any of source collection changes then unmodifiable collection contains those changes.

While Immutable Collections are such kind of Collection which is readonly copy of Collections. They can not be modified. if any of source collection changes then immutable collections will not reflect with changes.

Runtime Polymorphism in Java

Polymorphism means ability to take more than one form. In RunTime Polimorphism resolution to call to method is determined at runtime rather than compile time.
  • Method are overriden but data member are not so runtime polymorphism is not applied to data members