Initializer Block in Java

When you create an instance of a class, constructor is called to initialize the instance variables. An alternative to using a constructor to initialize instance variable is to use initializer block in Java. Initializer block is always executed when an instance of the class is created. General form of Initializer…

Continue reading

Difference Between Synchronized And ReentrantLock in Java

The traditional way of acquiring a mutual exclusion lock in Java is to use synchronized keyword but Java 5 added new lock implementations like ReentrantLock and ReentrantReadWriteLock which provide extended locking operations capabilities. In this post we’ll see the difference between synchronized and ReentrantLock in Java. ReentrantLock Vs synchronized in…

Continue reading

Class in Java

A class is the foundation for object oriented programming in Java language. Any logic that has to be implemented in Java must be encapsulated with in the class. Once a class is created in Java that defines a new data type which can be used for creating object of that…

Continue reading

Constructor in Java

Constructor in Java is a special method which is called automatically to initialize an object when the object is created. Need for a constructor When an object is created it is a very common requirement to initialize that object (provide values for its instance variables). To facilitate that a constructor…

Continue reading