Characters Count

Problem: Suppose you are given a collection of strings like [swquiz,gkhive,testdriven ]. Each string shall have characters from ‘a’ to ‘z’, only lower case, there can be repetition of characters in a given string. Write a program for following 1) Count of characters that are available in all the input strings 2) Count of characters [...]
Continue reading…

 

BlockingQueue in Java – How to implement producer-consumer design using BlockingQueue?

Java 5 util.concurrent package provides a very useful class named “BlockingQueue” to implement producer-consumer design. In java 1.4 world developers used to use wait and notify mechanism to implement the same design. BlockingQueue class made code more readable and reduced the chances of bug in the code. In the below given example, we have a [...]
Continue reading…

 

Iterating forward and backward using java ListIterator.

ListIterator can be effectively used to travel forward and backward in a List implementation.

Continue reading…

 

JSR 303 – How to write a custom validator?

Bean validation specifications. JSR 349 is the specification for Bean Validation 1.1. JSR 303 is the specification for Bean Validation 1.0 Bean validation is an important task irrespective of the architecture (enterprise web application or thick client-server) of the application. JSR 303 specification standardize the bean validation process. JSR 303 is not intended for use [...]
Continue reading…

 

Serialization and Deserialization in java.

Serialization is the process of converting the state of an object into byte stream. De-serialization allow you to restore the serialized state into another instance of the same type. As you know, only the state of an object can serialized. Behavior is run-time phenomenon and it can’t be converted to a stream. Classes java.io.ObjectOutputStream and [...]
Continue reading…

 

Java Reflection – Invoking Method at Runtime.

Using Java Reflection we can inspect and invoke methods at runtime. This is achieved using a class named java.lang.reflect.Method. There are basically three steps involved in invoking a method using reflection. Create a instance of the given class Prepare the parameters to invoke the method Invoke method using the java.lang.reflect.Method Create a instance of the [...]
Continue reading…

 

How to create and start threads in java?

Unlike many other languages it is simple to create and manage threads in java. Your class can gain the concurrent behavior through either extending java.lang.Thread class or implementing java.lang.Runnable interface. Thread class itself implements Runnable interface, due to the same reason compiler will not force the programmer to give an implementation of run() method if [...]
Continue reading…

 

Invoking constructor using java reflection.

Invoking non parameterized and parameterized constructors in java is possible thru reflection API. This helps the programmers to instantiate classes which are configured in a property file or in database on the runtime. Below given example demonstrate the power of jave reflection API, program creates instances using parameterized and non parameterized constructors. Code snippet to [...]
Continue reading…

 

How to write a custom class loader in java?

In this post we will give you a simple example of custom class loader. We will also touch upon out of the box class loaders in java and the chaining concept. Java Class Loaders Bootstrap Class Loader Extensions Class Loader System Class Loader Custom class loader or User Defined Class Loader Class loader responsibility Except [...]
Continue reading…