Serialization and Deserialization in java

Serialization is a process of converting object into a sequences of byte which can be written to disk or database or sent over network to any other running JVM. The reverse process of creating object from sequences of byte is called Deserialization. A class must implement the Serializable interface present…

Continue reading

Collection Interview Questions

How can we make Hashmap synchronized? HashMap can be synchronized by Map m = Collections.synchronizedMap(hashMap); Question 13 : What are IdentityHashMap and WeakHashMap? IdentityHashMap : IdentityHashMap is similar to HashMap except that it uses reference equality when comparing elements. IdentityHashMap class is not a widely used Map implementation. While this…

Continue reading

Thread Local

Thread Local Thread Local can be considered as a thread scope. You can set any object in Thread Local and this object will be global and local to the specific thread which is accessing this object. Values stored in Thread Local are global to the thread, meaning that they can…

Continue reading

Race condition in Java multi-threading

Race condition occurs in a multi-threaded environment when more than one thread try to access a shared resource (modify, write) at the same time. Note that it is safe if multiple threads are trying to read a shared resource as long as they are not trying to change it. Since…

Continue reading

ConcurrentHashMap

ConcurrentMap The java.util.concurrent.ConcurrentMap interface represents a Map which is capable of handling concurrent access (puts and gets) to it. The ConcurrentMap has a few extra atomic methods in addition to the methods it inherits from its superinterface, java.util.Map. ConcurrentMap Implementations Since ConcurrentMap is an interface, you need to use one…

Continue reading

Immutable-Class

Points to Remember : Declare your class as final.[public final class xxx] Set the values of properties using constructor only. Make the properties of the class final and private Do not provide any setters for these properties. If the instance fields include references to mutable objects, don’t allow those objects…

Continue reading

Comparble and Comparator Interface

Comparable Interface : Comparable is an public interfaces which is used to impose an natural ordering (if numbers then 1,2,3 or in alphabetical order ‘a’,’b’,’c’ ) of the class that implements it. It has only one method compareTo(); The default sorting order is based on the ASCII values Comparator: is…

Continue reading

Call by Value vs Call by Reference

While calling a method ,we can provide some information (data) from calling method to called method.this information is called as Parameters or Arguments. Now we will see about passing parameters to methods,We must understand that Java types are classified into 2 broad categories Value Types Reference Types Primitive types of…

Continue reading

Exception handling in Java

What is an exception? An Exception can be anything which interrupts the normal flow of the program. When an exception occurs program processing gets terminated and doesn’t continue further. In such cases we get a system generated error message. The good thing about exceptions is that they can be handled.…

Continue reading

Producer Consumer Example using BlockingQueue

Producer Consumer design pattern BlockingQueue example JavaProducer consumer pattern is every where in real life and depict coordination and collaboration. Real Time Example: Like one person is preparing food (Producer) while other one is serving food (Consumer), both will use shared table for putting food plates and taking food plates.…

Continue reading