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()

Related Posts:

  • Static inner class in Java Like Instance inner class we have also static inner class. Static instance class is loaded at the time of loading the outer class as it is declared as static that means it will act as the static member of the outer class and… Read More
  • super keyword in Java Like this in java one more most important keyword is there i.e super. super in Java has a wide use and it is mainly used to call the super class constructor explicitly by the user and implicitly used by the JVM to initialize… Read More
  • Inner Class in Java Inner class in a class defined as a class inside another class. So it is itself a class but first it will act as a member of that class. As we know that we cannot make a class as static but inner class can be made as static… Read More
  • ' this ' keyword in Java this is one of the most important keyword in java which refers to the current class object. Like we are creating an object for our class similarly internally a object is there called as this which points to the current class… Read More
  • Instance Inner class in Java As the name itself indicates that inner class with non-static scope that means a member of outer class which is of instance scope called as instance inner class. Instance inner class is itself a class but we cannot use any s… Read More

1 comment:

Ads 468x60px

.

Ads

.

Featured Posts

Popular Posts

Like Us On FaceBook

Total Pageviews

201978

Online Members

Live Traffic