Java Articles

Java Memory Model

The article describes about how the memory space is divided in JVM. The article also explains the different type of GC algorithms and also its behavior with the memory space...

Log Structure Merge Trees

LSM trees are designed to achieve higher throughput and are used as the storage engine of various DB such as HBase, Cassandra, LevelDB, SQLite. As the name suggests, writes are made to log files in append-only mode. These logs files are merged and compacted in the background and indexed for efficient search.

Java 8 Lambda Explained

The main intention of using lambda is to pass a block of code. The code block can be used of immediate execution or can be later too. But Java is object oriented programming and until now creation of any block had to be done by wrapping around the class and creating an object..

Java 8 Stream By Examples

Collections is an in memory data structure which holds all the elements in the memory. In Stream the elements are computed on demand and the values are passed to next stream or returned. In Collection, the entire collection has to be computed to pass on to the next collection..

Stack And Heap

Java Memory is one of the most interesting concepts in JVM and its always fun to know how java memory model is designed. Java memory model (JMM) has quite a few components of which stack and heap are two of them...

Java Hashcode and Equals

Object class provides two methods hashcode() and equals() to represent the identity of an object. It is a common convention that if one method is overridden then other should also be implemented...

Producer Consumer problem using wait() and notifyAll()

Object class provides two methods hashcode() and equals() to represent the identity of an object. It is a common convention that if one method is overridden then other should also be implemented...

Difference between implementation of Map

Java collections Map Interface have multiple implementations. Different types of maps, such as HashMap, TreeMap, HashTable and LinkedHashMap.

Producer Consumer problem using BlockingQueue

Producer Consumer problem is a classic concurrency problem and is often asked in interview. The problem goes as follows: Producer and Consumer are two separate threads which share a same bounded Queue...

Comparable and Comparator in java

Producer Consumer problem is a classic concurrency problem and is often asked in interview. The problem goes as follows: Producer and Consumer are two separate threads which share a same bounded Queue.

How ConcurrentHashMap works?

ConcurrentHashMap is designed to be more efficient and have better performance in multi-threaded enivorment when compared to hashtable.

Difference betwen equals and ==

== operator is binary operator used to compare the primitives and objects in java. Primitives such as int, float, boolean can use == to compare the values of primitive variables...

How does HTTPS work?

To send the data securely, https was invented which is nothing but HTTP +SSL (Secure Socket Layer). SSL uses cryptography to encrypt the text.

Converting java object to JSON

One of the common uses case is to work with Json string. Simple use case is to convert a strong to POJO object, java collections or vice versa. Json jackson library is a common library for such use cases...

Singleton Design Pattern

A singleton is simply a class that is instantiated exactly once in the Java Virtual Machine. It is used to provide global point of access to the object. In terms of practical use Singleton patterns are used in ...

Difference between abstract class and interface

One of the common uses case is to work with Json string. Simple use case is to convert a strong to POJO object, java collections or vice versa. Json jackson library is a common library for such use cases...

Fail Fast and Fail Safe Iterators

In Java the iterators allow to traverse the collections. Iterator is an interface which has two methods hasNext() and next(). Iterators returned by the Collection are either fail-fast in nature or fail-safe in nature...

Difference between final, finally and finalize

final - final keyword can be used with a class, variable or a method. The underlying behavior of using final keyword is to act as constant...

Immutable class in java

When an object of immutable class is created, the state or value of it cannot be changed , it means any modification on immutable object will result in a new immutable object. Immutable objects are particularly useful in concurrent applications.

Builder pattern using java.

Static factories and constructors share a limitation, they do not scale well for large number of optional parameters. Consider an example where you have a class representing a Book.

Semphores and Mutex

Mutexes, monitors and semaphores are all synchronization mechanisms i.e. they are used to mediate access to a shared resource between multiple processes or threads (referred to as processes henceforth). However, they are used differently:

CAP theorem Explained

The BASE acronym was defined by Eric Brewer, who is also known for formulating the CAP theorem. Distributed systems are prone to outages and not safe from network failures...

Difference between String and StringBuffer or StringBuilder

Main difference between String and StringBuffer is String is immutable while StringBuffer is mutable means you can modify a StringBuffer object once you created it without creating any new object.