How Garbage Collection works in WeakHashMap

Here we will discuss about how an entry gets garbage collected from WeakhashMap. You may check first how garbage collection works in Java. WeakHashMap uses a special class called WeakReference to refer to the keys. A weak reference is an object that acts like an indirect reference (a reference to an object holding another reference). It has the interesting property…

How to join multiple strings using append(), StringJoiner, String.join() in Java

In this tutorial we will see the difference between StringJoiner and String.join(). These were introduced into Java 8 version. The example we create here will show how to join multiple string objects or literals or list of strings using append(), StringJoiner, String.join() API. Situation may occur when you need to join multiple string literals or objects into one. You may…

How Deadlock Occurs And How To Fix It In Java

Deadlock in Java Deadlock describes a situation where two or more threads are blocked forever, waiting for each other. Java deadlock situation arises with at least two threads(multitasking or multi-threading) and two or more resources. There are several ways you can detect deadlock in Java applications.

How to execute Java Threads in the same Order they were started using join() Method

In this tutorial I will discuss about the join() method from Thread class. This method is important method from Thread class and it imposes order on execution of the threads. Therefore join() method ensures that multiple threads run in sequence, i.e., in the same order the threads were started. Let’s say threads t1, t2, t3 started execution in order and…

Inter Thread Communication using wait(), notify() and notifyAll() in Java

We will discuss here what are the purpose of wait(), notify() and notifyAll() methods in Java. These methods are used in inter-thread communication. Each thread in Java has its own separate path of execution, so when you need to establish communication among threads then you need to use these methods. Let’s say a thread wants to tell another thread that…

What are WeakReference, SoftReference, StrongReference, PhantomReference in Java

Here we are going to discuss about the StrongReference, PhantomReference, WeakReference and SoftReference. Reference classes are important in the context of how garbage collection works in Java memory model. Garbage collector reclaims memory from objects which are eligible for garbage collection and this eligibility is decided upon what kind if reference is pointing to the object – WeakReference or SoftReference…

Find Unique Strings Or Objects Using Java Stream API

Unique Strings/Objects In this tutorial you will see an example on how to find unique strings or objects using Java stream API. Stream API was introduced in Java 8 and I am going to show you how to use this stream API to remove duplicates from strings or objects. Java stream API has a method distinct() that removes duplicates and…

How to check broken links in Website using Selenium Web Driver

Introduction In this tutorial we will see how to check broken links in website using Selenium web driver. Broken links are not reachable or simply do not work. A URL for the website is no longer available. A URL of the web page was moved without a redirect being added. The URL structure of a website was changed. The link…

How to create Jenkins Pipeline for Java Project

Introduction Jenkins Pipeline (or simply “Pipeline”) is a suite of plugins which supports implementing and integrating continuous delivery pipelines into Jenkins. A continuous delivery pipeline is an automated expression of your process for getting software from version control right through to your users and customers. Jenkins Pipeline provides an extensible set of tools for modeling simple-to-complex delivery pipelines “as code”….

Merge Two String Arrays and Produce Unique Values using Java

Unique elements by merging arrays In this tutorial, I will show you how to merge string values from two arrays and produce the final array with unique string values. I will use Set data structure to produce the unique results in final array. When passed two arrays of strings, it will return an array containing the string values that appear…