Java networking ●Java.net. oSocket,ServerSocket o Grab the associated streams OInputStream is =s.getInputStream(); OOutputStream os s.getOutputStream(; ●URL class OInputStream is u.openStream();
Java networking lJava.net. lSocket, ServerSocket lGrab the associated streams ¡InputStream is = s.getInputStream(); ¡OutputStream os = s.getOutputStream(); lURL class ¡InputStream is = u.openStream();
Inner class o Our internal implementation of a class is private ●Information hiding OOutside users don't know what we are doing to provide our services OWe can change our implementation without affecting others o Private methods,fields
Inner class lOur internal implementation of a class is private lInformation hiding ¡Outside users don’t know what we are doing to provide our services ¡We can change our implementation without affecting others lPrivate methods, fields
Inner class o What if we want to use classes for our internal implementation? OInner classes! OA class defined inside another class o Similar to the methods or fields of class OCan be static,public,private Can be private so no other class can use it oUsable by enclosing class
Inner class lWhat if we want to use classes for our internal implementation? ¡Inner classes! ¡A class defined inside another class lSimilar to the methods or fields of class ¡Can be static, public, private lCan be private so no other class can use it lUsable by enclosing class
Example oInnerClassTest.java
Example lInnerClassTest.java
Why use inner class? oInner class can access to all the elements of the enclosing class oInner classes can be hidden from other classes by using private o Anonymous inner classes are handy sometimes oConvenient when you are writing event- driven programs
Why use inner class? lInner class can access to all the elements of the enclosing class lInner classes can be hidden from other classes by using private lAnonymous inner classes are handy sometimes lConvenient when you are writing event- driven programs