What’s the difference between equals() and ==?

The “==” operator In Java, when the “==” operator is used to compare 2 objects, it checks to see if the objects refer to the same place in memory. In other words, it checks to see if the 2 object names are basically references to the same memory location. A very simple example will help […]

Difference between Set, List and Map

Set vs List vs Map in Java As I said Set, List and Map are interfaces, which defines core contract e.g. a Set contract says that it can not contain duplicates. Based upon our knowledge of List, Set and Map let’s compare them on different metrics. Duplicate Objects Main difference between List and Set interface in Java is that List allows duplicates while Set doesn’t allow duplicates. All implementation of Set honor this contract. Map  holds two […]

Concurrency API in Java

The Concurrency API introduces the concept of an ExecutorService as a higher level replacement for working with threads directly. Executors are capable of running asynchronous tasks and typically manage a pool of threads, so we don’t have to create new threads manually. All threads of the internal pool will be reused under the hood for […]

Run task periodically in Java

Schedular Task : For this functionality, You should create a class extending TimerTask(available in java.util package). TimerTask is a abstract class. Write your code in public void run() method that you want to execute periodically. Insert below code in your Main class. import java.util.TimerTask; import java.util.Date; /**  *   * @author Dhinakaran P.  */ // Create […]

Random String Generation in Java

import java.util.Random; public class RandomStringGen { private static final String CHAR_LIST =        “1234567890”;    private static final int RANDOM_STRING_LENGTH = 4;      /**     * This method generates random string     * @return     */    public String generateRandomString(){              StringBuffer randStr = […]