Thursday, 16 March 2017

Functional Programming in java

Java 8 introduced a new feature called lambda expressions. Before Java 8 it only followed object oriented programming and its concepts. Now it has allowed to write functional programming as well by passing code as an argument to a method. Functional programming is a hot topic for some other programming languages.  But Java doesn't had any feature like that before java 8.
In this blog I will try to cover following topics:
  1. Lambda expression
  2. Functional interface
  3. Variable capture
  4. Method References
  5. Default method
Before starting anything, lets come to questions of WHY and then HOW.

Monday, 13 February 2017

Introduction to AbstractQueuedSynchronizer in java

For managing multi-threading applications, java follows monitor construct. According to Monitor construct if a thread is executing a critical section while holding mutex (or intrinsic lock) of an object, no other thread can execute this critical section with lock of same object. synchronized method and synchronized block are simple implementation of this technique.Many concepts of Semaphore and latches are implemented in java over this concept. All concurrent classes introduced in java 1.5 like ReentrantLock, ThreadPoolExecutor and many others are based on this technique. There are times when we require either to wait a thread or to start running a thread, based on the state of an object. Thread can sleep/wait/run depending on some conditions. These types of classes are known as state dependent classes.