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;
}
}
# 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 .
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 as slow in performance since Thread Safe whereas StringBuilder in faster .
Comments
Post a Comment