How to merge Multiple CSV Files into One in Java

Introduction This tutorial shows how to merge multiple csv files into one in Java. You may need to merge multiple csv files into one in some situations for your business requirements. Suppose there are n number of csv files and each csv file is having different number of headers, so this example will show you how to merge multiple csv…

Marker Interface example in Java

Introduction The marker interface pattern is a design pattern that provide run-time type information about objects. It provides a means to associate metadata with a class when there is no explicit support for such metadata. The marker interface in Java does not have any method inside it, in other words, a marker interface in Java is an empty interface. Marker…

Externalization example in Java

The Externalizable interface provides the necessary means for implementing a custom serialization mechanism. Implementing the Externalizable interface means that we must override writeExternal() and readExternal() methods. These methods will be called when you serialize or deserialize a particular instance or object. The difference between Serialization and Externalization is that when we implement the Serializable interface we do not need to…

Simple Log4j Configuration in Java

Introduction We will see here an example on simple log4j configuration in Java. The purpose of inserting log statements into the code is a low-tech method for debugging it. It may also be the only way because debuggers are not always available or applicable. This is often the case for distributed applications.

How ThreadLocal Works In Java

Introduction Here you will see how ThreadLocal works in Java. Java ThreadLocal class is used to create thread-local variables. The thread-local variable can be read and written by the same thread only. In multi-threaded environments all threads of an Object share their variables, so if the variable is not thread safe, then an inconsistent state of the variable occurs. Therefore…

String Reverse Example In Java

String Reverse This tutorial will show you string reverse example in Java. You can use various ways to reverse a string in Java and I have presented here five ways to reverse a string. String class in Java is an immutable class and that’s why it does not have reverse() method to reverse the given string. I will use here…

How Singleton Design Pattern Works in Java

Introduction Here in this post I will discuss how singleton pattern works in Java. Singleton pattern is a design solution, where an application wants to have one and only one instance of a class, in all possible scenarios without any exceptional condition. The singleton instance is actually created per JVM but not across multiple JMVs. The singleton class has a…

How HashMap Works In Java

Introduction HashMap (also known as HashTable) is, a data structure that can map keys to values, used to implement an associative array. A HashMap uses a hash function to compute an index into an array of buckets or slots, from which the correct value can be found. Ideally, the hash function will assign each key to a unique bucket, but…

Override equals() and hashCode() Methods in Java

Introduction Here I will discuss how to override equals() and hashCode() methods in Java. In Java language the important contract is whenever you override one of the methods (equals() and hashCode()), then you must override the other method. So it means that when you override method equals() then you must override hashCode() or vice versa.

Encryption And Decryption Using RSA In Java

RSA Encryption/Decryption RSA is a cryptosystem, which is known as one of the first practicable public-key cryptosystems and is widely used for secure data transmission. In such a cryptosystem, the encryption key is public and differs from the decryption key which is kept secret. In RSA, this asymmetry is based on the practical difficulty of factoring the product of two…