Home » Core Java » util


Java ScheduledExecutorService Example

1. Introduction It is common requirement in software development that we want tasks to run (i) periodically or (ii) start after a fixed delay. Since Java is known for richness of its development platform, it abstracts such requirements in an interface java.util.concurrent.ScheduledExecutorService and its concrete implementation java.util.concurrent.ScheduledThreadPoolExecutor In this post we would not just look into these APIs but also ...

Read More »

Java CompletionService Example

1. Introduction to CompletionService The Java JDK provides some “services” for common use cases. The asynchronous Producer-Consumer pattern is one such common use case which is often required in day to day software development. As such the JDK provides platform level support in the form of APIs like java.util.concurrent.CompletionService and java.util.concurrent.ExecutorCompletionService. CompletionService abstracts the service of handling tasks which could ...

Read More »

Java CompletionStage and CompletableFuture Example

1. Introduction Java JDK8 included the big fat interface called CompletionStage in the java.util.concurrent package. The same package also contains CompletableFuture which is a library implementation of CompletionStage. In this post we would see how CompletionStage and CompletableFuture provide piped asynchronous API thus enhancing reactive programming support in Java at the platform level. Since we are talking about JDK8 APIs, ...

Read More »

Groovy Regex Example

In this example I will show you how to use regular expressions in Groovy. 1. Groovy and Regular Expressions Groovy is one of the most commonly used JVM languages and regular expressions (or simply regex) as a powerful technique to search and manipulate texts have been around us for more than a half century. As most of the languages Java ...

Read More »

java.lang.Iterable Interface Example

This article shows an example of Iterable interface. This is defined in java.lang package and was introduced with Java 5. The Iterable is defined as a generic type; Iterable<T>, where T type parameter represents the type of elements returned by the iterator. An object that implements this interface allows it to be the target of the “foreach” statement. The for-each ...

Read More »

java.util.concurrent.ConcurrentSkipListMap Example

ConcurrentSkipListMap is a scalable concurrent navigable map implementation. The map is sorted based on natural ordering of its keys or by comparator depending on the usage of constructor. ConcurrentSkipListMap  class implements a concurrent  variant of Skip lists which provides expected average log(n) time cost for the get, put, containsKey and remove operations. These methods are multiple thread based  and safe ...

Read More »

Properties File Java Example

In this example, we shall show you how to use property files in java. Java property files are an easy and effective way to organize key value pairs in plain text files. Property files support two formats Text file format – In this  format, different key, value pairs are separated by newline character XML format – This is standard XML format. ...

Read More »

Java ReentrantReadWriteLock Example

This is an example of how to make use of the ReentrantReadWriteLock class of Java. It is an implementation of ReadWriteLock, that also supports ReentrantLock functionality. The ReadWriteLock is a pair of associated Locks, one for read-only operations and one for writing. Whereas, the ReentrantLock is a reentrant mutual exclusion Lock with the same behavior as the implicit monitor lock accessed using synchronized methods ...

Read More »

java.util.regex.Pattern Example

Pattern class represents a compiled representation of a regular expression. This is defined in the java.util.regex package as a final class. A regular expression is specified as a string. This string is to be first compiled into an instance of this class using the Pattern.compile() static method. This instance is used by a Matcher class to perform match operation. This ...

Read More »

java.util.concurrent.RejectedExecutionHandler Example

Here we will discuss about the RejectedExecutionHandler Interface in the java.util.concurrent package. This interface is really helpfull when working with the ThreadPoolExecutor. 1. Overview & Usage The interface java.util.concurrent.RejectedExecutionHandler is a handler for tasks that cannot be executed by a ThreadPoolExecutor ( a class that implements ExecutorService, ). This may occur when no more threads or queue slots are available ...

Read More »

Want to take your Java skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • Spring Interview QnA
  • Multithreading & Concurrency QnA
  • JPA Minibook
  • JVM Troubleshooting Guide
  • Advanced Java
  • Java Interview QnA
  • Java Design Patterns