Java Experiance InterView Questions and answer

--> Example of SingleTone in java 

public final class SingleTone {
   
    /**
     * @author anand
     *
     */
   
   
    public static SingleTone single;
    //Can be act as SingleTone or make constructor as private
   
    private SingleTone(){}
   
    public static synchronized SingleTone getInstance(){
       
        if(single==null){
           
            single=new SingleTone();
        }
        return single;
    }
   

}


--> What is difference between StringBuffer and StringBuilder in Java ?

# Stringbuffer methods are synchronized while StringBuilder is non synchronized. See StringBuilder vs StringBuffer for more differences.
 # StringBuffer as slow in performance since Thread Safe whereas StringBuilder in faster .






Comments

Popular posts from this blog

Converting JSONArray into CSV file in java

Java Design pattern

Map class field to map