Reentrant Lock

The ReentrantLock class is an implementation of Lock Interface, which will lock() the execution block for the thread which calls it.Until the locked thread calls the lock.unlock() method, the code block in between will not be available to other Threads…even when it is idle or sleeping or taking long time.Hence the block after lock.lock() is … Continue reading “Reentrant Lock”

Semaphore

A semaphore maintains a fixed number of threads in executions if exceeds lock can be acquired for that semaphore thread. Below method will get the lock of semaphore within semaphore.availablePermits()

If there are more that fixed threads, it will wait to acquire/get the semaphore lock until it has semaphore.availablepermits() greater than ‘0’.A semaphore initialised to … Continue reading “Semaphore”

Binary To Decimal Conversions

This example shows the conversion of Decimal to Binary & Binary to Decimal  in Java. The toBinary() method in BinaryConversion class uses the recursion logic of modulo(%) 2 of given number(which is reminder), and calls the same method recursively with number/2( from 512>>2 =256) , until the reminder is one. The toDecimal() method uses the … Continue reading “Binary To Decimal Conversions”

Factory Design Pattern

Factory Pattern is a design pattern to create objects based on the type with the help of Factory class. Factory Class create and return the object based on the type of request, and Caller class not aware of which class returned, however the created class do the operation based on the requested type. In this … Continue reading “Factory Design Pattern”

Singleton Design Pattern

A Singleton design Pattern is a very simple design pattern where only one instance(object) is created for a Class. And the Object can be accessed publicly, however only one instance will be there available through out its life time. In Java, Singleton Pattern can be easily implemented by making the constructor to private and provide … Continue reading “Singleton Design Pattern”

Design Patterns & Types

A design pattern is a template in which application can be designed so that it will provide us the tight cohesion and loose coupling of the components/classes, so that the application can be extended/modified very easily for further use. Designers gave us the templates so that the design can be picked up based on the … Continue reading “Design Patterns & Types”

Building JSON Object Java

A JSON Object can be created using Java very easily using any JSON library.We are using JSON-Simple.jar to build/parse the JSON Object using Java.

Results: {“names”:”testjsonuser3″,”actions”:”IllustrateJSONObjectInScript”,”logincount”:3} We could see the result displays the JSON Object., and it has string field printed with double quotes.The java Object is created with only name value pairs in … Continue reading “Building JSON Object Java”

Parsing JSON Object – Java

In Java, JSON object can be directly converted to String and we can do String manipulations. Also, the JSON Object created can be parsed using the field name present in JSON Object.

Result:

The “names”, “actions” and “logincount” values is displayed by parsing the object jsonObject directly in java as explained.