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...

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 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...

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.

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..

Difference between implementation of Map

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

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...

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:

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.

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...