Home » Author Archives: Anirudh Bhatnagar

Author Archives: Anirudh Bhatnagar

Anirudh Bhatnagar
Anirudh is a Java programmer with extensive experience in building Java/J2EE applications. He has always been fascinated by the new technologies and emerging trends in software development. He has been involved in propagating these changes and new technologies in his projects. He is an avid blogger and agile enthusiast who believes in writing clean and well tested code.

Java.util.concurrent.CyclicBarrier Example

In one of the previous posts, we talked about CountdownLatch and its use case. Today we are going to talk about a similar yet different synchronisation mechanism called as CyclicBarrier. Java.util.Concurrent.CyclicBarrier is a synchronisation aid that allows a set of threads to wait for each other to reach a common barrier point. This means that all the threads reaching a ...

Read More »

Java.util.EnumMap Example

In this example we will see how and when to use Java.util.EnumMap. EnumMap is used when we need to have keys of the map as enums. EnumMaps are represented internally as arrays. This representation is extremely compact and efficient. Enummaps are maintained in the natural order of their keys (the order in which the enum constants are declared). Lets see ...

Read More »

Java.util.TreeSet Example

In this example we will see how and when to use java.util.TreeSet. A TreeSet is a set implementation which provides total ordering on its elements. The elements are ordered using their natural ordering, or by a Comparator typically provided at sorted set creation time. A TreeSet is typically used when we want to keep the elements sorted all times. A ...

Read More »

java.util.Timer Example

In this example we will see how we can use java.util.Timer class to schedule tasks for future execution in a background thread. The tasks may be scheduled for one-time execution, or for repeated execution at regular intervals. This class is thread safe and multiple threads can share a single Timer object without need for external synchronisation. For our example we ...

Read More »

java.util.concurrent.CountDownLatch Example

In this example we will see how and when to use java.util.concurrent.CountDownLatch CountDownLatch is used in synchronisation to allow one or more threads to wait until a set of operations being performed in other threads completes. For Example, it can be used when a Thread has to wait until few dependent threads have started. CountDownLatch is initialised with a given count. This ...

Read More »

Thread.UncaughtExceptionHandler Example

In this example we will see how to use Thread.UncaughtExceptionHandler. UncaughtExceptionHandler is used as a way to provide an elegant way to handle Runtime Exceptions which are not handled otherwise in the programs. As soon as a thread terminates due to an uncaught exception,JVM will query the thread for its UncaughtExceptionHandler using Thread.getUncaughtExceptionHandler() and will invoke the handler’s uncaughtException method, ...

Read More »

Send Email with Gmail in Java Example

In this example we will see JavaMail API method to send an email via Gmail SMTP server. The JavaMail API provides a platform-independent and protocol-independent framework to build mail and messaging applications. Java Mail API Jar can be included in the maven project by adding the following dependency in pom.xml.         1. Add dependency in POM <dependency> ...

Read More »

Write/Read Excel files in Java Example

In this example we will see how we can write and read excel files in Java. For writing/reading Excel Files we will use the library Apache POI Apache POI provides Java APIs for manipulating various file formats based upon the Office Open XML standards (OOXML) and Microsoft’s OLE 2 Compound Document format (OLE2). Using Apache POI HSSF and XSSF APIs ...

Read More »

Java.util.concurrent.SynchronousQueue Example

In this example we will see how to use Java.util.concurrent.SynchronousQueue. SynchronousQueue is a type of Blocking Queue (it implements BlockingQueue) As mentioned in the java docs , it is a blocking queue in which each insert operation must wait for a corresponding remove operation by another thread, and vice versa. This means that the queue can only contain a single ...

Read More »

Java.sql.DatabaseMetaData Example

In this example we will see how we can make use of class java.sql.DatabaseMetaData to extract the meta data of the database. We can view details like table names, primary keys, database name, DB driver version, etc. Lets see few examples of it. In order to run this code we need to make sure that a DB server is installed ...

Read More »