It is a private class or more specifically we can say its a ' private - package ' class i.e it is declared as not public and as abstract. As it was not there before the release of JDK 1.5 and was first introduced in java 5.0 as the superclass for both StringBuffer and StringBuilder.  Initially before JDK 1.5 there was only one class i.e StringBuffer ( which is thread safe ) and was extending Object class, but later with the release of JDK 1.5 AbstractStringBuilder and StringBuilder was introduced and now StringBuffer is extending AbstractStringBuilder . 

What is private - package class ?
If we declare a non-public class in a package whose scope will be within that package only , in other terms we create any instance of the class outside the package and hence can be considered as private class and called as private-package class. 


Aim behind intoducing AbstractStringBuilder ?
As we knowing that there are two identical class i.e StringBuilder and StringBuffer expects StringBuffer is thread safe and where as StringBuilder is not. Thus all the methods and their implementation are almost identical so instead of writing two times for both the classes they introduce a non-public abstract class i.e AbstractStringBuilder class which has same method with implementation and hence both are classes are using its implementation. 


Interesting facts of AbstractStringBuilder 

If we notice in AbstractStringBuilder class many method returns its own class instance only and its sub-classes i,e StringBuffer and StringBuilder both the classes override the methods of AbstractStringBuilder class and restrict the return type to their own class instance, this narrowing the return type by overiding the method in its sub-class is termed as ' co-variant return ', which is seen with the release of JDK 1.5 and with the later versions.    


Constrcutors of AbstractStringBuilder class


  AbstractStringBuilder(int i)

Instance variables of AbstractStringBuilder class

1. char[]   value;
2. int        count;
3. static final int[]    sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, 2147483647 };

Methods of AbstractStringBuilder class

  
  public int capacity()

  public void ensureCapacity(int i)

  void expandCapacity(int i)

  public void trimToSize()

  public void setLength(int i)

  public char charAt(int i)

  public int codePointAt(int i)

  public int codePointBefore(int i)

  public int codePointCount(int i, int j)

  public int offsetByCodePoints(int i, int j)

  public void getChars(int i, int j, char[] c, int k)

  public void setCharAt(int i, char c)

  public AbstractStringBuilder append(Object obj)

  public AbstractStringBuilder append(String s)

  public AbstractStringBuilder append(StringBuffer sb)

  public AbstractStringBuilder append(CharSequence cs)

  public AbstractStringBuilder append(CharSequence cs, int i, int j)
  
  public AbstractStringBuilder append(char[] ch)
  
  public AbstractStringBuilder append(char[] ch, int i, int j)

  public AbstractStringBuilder append(boolean b)

  public AbstractStringBuilder append(char c)

  public AbstractStringBuilder append(int i)

  static int stringSizeOfInt(int i)

  public AbstractStringBuilder append(long l)

  static int stringSizeOfLong(long l)

  public AbstractStringBuilder append(float f) 

  public AbstractStringBuilder append(double d)

  public AbstractStringBuilder delete(int i, int j)

  public AbstractStringBuilder appendCodePoint(int i)

  public AbstractStringBuilder deleteCharAt(int i)
  
  public AbstractStringBuilder replace(int i, int j, String s)
  
  public String substring(int i)

  public CharSequence subSequence(int i, int j)

  public String substring(int i, int j)

  public AbstractStringBuilder insert(int i, char[] c, int j, int k)
  
  public AbstractStringBuilder insert(int i, Object o)

  public AbstractStringBuilder insert(int i, String s)

  public AbstractStringBuilder insert(int i, char[] c)

  public AbstractStringBuilder insert(int i, CharSequence cs)

  public AbstractStringBuilder insert(int i, CharSequence cs, int j, int k)

  public AbstractStringBuilder insert(int i, boolean b)

  public AbstractStringBuilder insert(inti, char c)

  public AbstractStringBuilder insert(int i, int j)

  public AbstractStringBuilder insert(int i, long l)

  public AbstractStringBuilder insert(int i, float f)

  public AbstractStringBuilder insert(int i, double d)

  public int indexOf(String s)

  public int indexOf(String s, int i)

  public int lastIndexOf(String s)

  public int lastIndexOf(String s, int i)

  public AbstractStringBuilder reverse()

  public abstract String toString();

  final char[] getValue()

1 comment:

Ads 468x60px

.

Ads

.

Featured Posts

Popular Posts

Like Us On FaceBook

Total Pageviews

Online Members

Live Traffic