Friday, 25 May 2018


To implement Singleton pattern, we have different approaches :

1.Eager initialization:

In this method the instance of clss is created at loading time .As whenever in java there is a requirement of species at loading time we first remember of Static keyword.
package com.questprogram.singleton;

public class EagerInitializedSingleton {
    private static final EagerInitializedSingleton instance = new EagerInitializedSingleton();
    //private constructor to avoid client applications to use constructor
    private EagerInitializedSingleton(){}

    public static EagerInitializedSingleton getInstance(){
        return instance;

2.Static block initialization

Static Block initialization implementation is similar to eager initialization, except that instance of class is created in the static block that provides option for exception handling.

package com.questprogram.singleton;

public class StaticBlockSingleton {

    private static StaticBlockSingleton instance;
    private StaticBlockSingleton(){}
    //static block initialization for exception handling
            instance = new StaticBlockSingleton();
        }catch(Exception e){
            throw new RuntimeException("Exception occured in creating singleton instance");
    public static StaticBlockSingleton getInstance(){
        return instance;

Saturday, 31 March 2018

Base knowledge for spring framework developer

Spring Framework :

Facts:Spring Framework is a lightweight framework.Do you know reason.Read out
Proof: As Spring follow MVC model as following 

Fig.1.MVC model 
Does the image show that spring framework is light weight framework.If you are new then you might be confuse.So Don't be confuse go to the below coding example which proves it's light weight properties.

Reason.1-> Use Of POJO's 

POJO means Plain Old Java Object. It refers to a Java object (instance of definition) that isn't bogged down by framework extensions. For example, to receive messages from JMS, you need to write a class that implements the MessageListener interface.

Coming to a simple example.

Here College class has it's own property name & Address.It include references s1 for student type class & similarly t1 for Teacher type class.As there is a case of Assciation(HAS-A) relationship between college and student.Similarly to teacher also.But if you analyze this College Pojo class you will find that this object model try to solve the lots ofcomplexity .Before the spring if you want to do the samething then you need to do as below.

This make the spring lightweight as you can see.

Reason.2-> Use of  IOC.

Before IOC  if  you want to configure your datasource connection you need to write lengthy code.

Properties of Database 
Drivermanger aquire the connection
                                        These above lines are called at Dao layer at every time when you want to execute your db query.Can you imagine how much weight could JVM handle for this purpose.Each time JVM cry .

After Spring IOC it turn the number of lines code to 
And simply use your datasource configuration where you need to get connect.

Thanks for Reading. Please comments.

Wednesday, 17 January 2018

AngularJs/javascript and Angular/typescript (version 2/4/latest) have a series of difference.


                     AngularJs vs Angular (Typescript)

                                               On basis of process of compilation
         ANGULARJS :
  • Angular Js compiler traverses the DOM looking for attributes.It takes two phase for compilation where initial phase traverse the DOM and collect all of the directives. The result is a linking function.
  •  Next phase evolves combine the directives with a scope and produce a live view. Any changes in the scope model are reflected in the view, and any user interactions with the view are reflected in the scope model. This makes the scope model the single source of truth.

Thursday, 4 January 2018

Difference between String ,StringBuffer & StringBuilder?

Run this simple java program and create scenerio of String object creation in your mind.You will see huge difference than expectation.

                               I would recommend to first try on your own then follow the solution .
As you execute the above line of codes in your Java Runtime Environment .As compiler
read the lines .In  case of 
                                   String a= new String("Hello");
       As it will allow compiler to create a new string object .It is always mandatory for 
compiler to allocate a memory space in heap whenever new keyword is used.So String
class object created successfully in heap with reference variable a.And a very important point 
need to be noted down that here  "new String("Hello');"  It will make a literal object in String 
pool with value "Hello".So total number of object created equals if you print value of a
using System.out.println(a);  It will print Hello as reference variable for object a contain same 
value. Similarly it happens with  the next line  
                                     String b= new String("Java");
it also creates the same scenerio as String referenced above.But in case of next following line 
                                     String c="HelloJava";
In this case there will be a literal stored in constant pool.It also rise three most important question.

Que:What is difference between  constant pool and heap?
Que:What makes String immutable & why?
Que:How JVM utilize the need of constant pool?

As next lines of code executed it work as follow.In the given case when evaluation for

Here a & b are object of type String .While c is an string literal which contain value "HelloJava".
So when + operator work between two different object .It does not evaluate result equal to any 
String literal which is stored in Constant pool. So for "c==a+b" it will result to boolean result 
which comes out to be false.So only false will be printed.
In the following next line while evaluating  c=="Hello"+"Java";
It will work as operator overloading between two String literals.And as describe "Hello" &
"Java" both are stored in Constant bool which concat and result equals to c.
So true will pe printed  in System.out.print(c=="Hello"+"Java");

StringBuffer is faster than String when performing simple concatenations. In String
 manipulation code, character strings are routinely concatenated.