Category Archives: JAVA

JAVA

Collection Sorting using Comparator Interface

Output: Before Sorting 1, Rahul 5, Mehul 3, Manisha 6, Shahnahwaz 2, Hitesh After Sorting using Comparator 1, Rahul 2, Hitesh 3, Manisha 5, Mehul 6, Shahnahwaz

Collection Sort using Comparable Interface

Output: Before Sorting 1, Rahul 5, Mehul 3, Manisha 6, Shahnahwaz 2, Hitesh After Sorting 1, Rahul 2, Hitesh 3, Manisha 5, Mehul 6, Shahnahwaz

EnumMap vs HashMap

Both implement Map interface. 1. EnumMap is optimized for enums to store in a map. EnumMap internally uses array and provide constant time performance for common methods like get() and put(). 2. You can only use Enum as a key in EnumMap whereas in HashMap you can use any object including Enum 3. As EnumMap Continue Reading…

Stackoverflow vs Outofmemory error

JVM divides its memory into two parts Heap memory and Stack : heap memory is used to store the instance objects whereas stack memory is used to store the calling hirarchy of the methods as well as the local variables of the method. OutOfMemoryError is related to Heap. If you have large object which is Continue Reading…

Thread Dump

How to take Thread Dump: 1. Get the process Id of the process ps -aef | grep java 2. Get the Thread dump for all the threads within a process jstack {pid} > dump.log

Immutable Objects in java

If we can not modify the object after creation that object is called Immutable object. String is the best example for Immutable Object. Rules for making the objects Immutable: Class should be final. Class members should be final. If we have any mutable object in our class then return the copy of that object through Continue Reading…

Facade Design Pattern

Facade pattern hides the complexities of the system and provide the interface to use that system. Here we are going to create a shape interface that will be provided to client for using the Shape Maker. Step-1 Create an interface Shape Output: Hi, this is circle Hi, this is rectangle Hi, this is square