Monday, May 16, 2016

Java : Inner Class , Nested Class , Static Class and Interfaces

Inner Class , Nested Class , Static Class and Interfaces



interface A {//All implementation in Interface = Static
    static class X{}            //To Avoid : if(X instance of A) ,can be accessed as A.X
    static abstract class Y{}    //Not valid - Cannot instantiate abstract class (static)
    static interface Z{}        //Not valid - Cannot instantiate Interface (static)
}

abstract class B {
    class X{}            //X=private by default
    abstract class Y{}    //
    interface Z{}        //
}

class C {
    void m(){class c{}}//Local inner class(visible only inside this method    )
    static class W{}    //Accessed as C.W
    class X{}            //Nested Class
    abstract class Y{}    // Implementing class needs
    interface Z{}
}


Nested Class:
1. Private by Default
2. Can access all the private members of super class
3.     C face=new C();
    C.X ear1=face.new X(); //logical grouping, readable and maintainable code
    C.X ear2=face.new X();
4. Same operation can also be done using external classes

Friday, May 6, 2016

Java : Important API

Java : Important API


  1. Fileutils : Folder and File Related Operations (also does read ,write,append to text file)
  2. StringUtils: For String Related Operations (contains,indexof,mid,leftpad,join,split,rightpad,leftpad,replace,trim etc.,)
  3. Guava: Additional util operations
  4. WorkBookFactory : Excel Operations (Apache POI)


Alternatives
  1. File>FileReader>BufferedReader : To read text
  2. File>FileWriter >BufferedWriter: To write text