Thanks to visit codestin.com
Credit goes to www.slideshare.net

IADCS Diploma Course Object Oriented Programming U Nyein Oo COO/Director(IT) Myanma Computer Co., Ltd(MCC)
OOP? Software Development Technique Effective use of programmer productivity Way of Creating Large Scale Systems Approaching 100% solution
Basic Concepts Object Class Inheritance Polymorphism Encapsulation Data Abstraction
Object A Person, Place or Concepts Composed of Characteristics (data) and Behavior (Operation) Can operate directly on its data Interact sending message to each other
Class Structure that contains common data and function as entity for objects Each object is an instance of a class
Inheritance The mechanism that permits a class to share the attributes and operations defined in one or more classes
Inheritance(cont) Subclass The class which inherits from another class Super class The class from which another class inherits its behavior Multiple Inheritance A subclass inherits from two or more classes
Polymorphism The property that allows an operation to have different behavior on different objects
Encapsulation The process of binding data and methods together is known as encapsulation
Data Abstraction The process of identifying and grouping attributes and actions related to a particular entity as relevant to the application a hand. Advantages - It focus on the problem - It identifies the essential characteristics and  action  - It helps the eliminate unnecessary details.
Access Specifiers Public  Private Protected
Method Modifiers Static Abstract Final Native Volatile
Use of Modifiers No Yes No Volatile No No Yes Native Yes Yes Yes Final Yes No Yes Abstract Yes(nested) Yes Yes Protected Yes(nested) Yes Yes Private Yes Yes Yes Public Class Variable Method Modifier
Construction The process of bringing an object into existence is called construction A construction - Allocates memory -  Initializes attributes, if any - Enables access to attributes and methods
Constructor (cont) Explicit constructor User defined constructor in class definition Implicit constructor Default constructor which is provided by JVM
Destruction The process of deleting an objects is called destruction A destructor -  Frees allocated space - Disable access to attributes and methods
Method Overloading In the same class and same methods name But in different parameters and data types Form of compile time polymorphism
Method Overridden In the super class as well as subclass Allows general classes to specify methods that will common to its subclass Form of runtime polymorphism
Abstract class and method There is no code in abstract class and method Must be declared as abstract type Can not instantiated At least one abstract method in class
Writing Abstract class and Method abstract class GraphicObject  {  int x, y;   . . .  void moveTo(int newX, int newY)  { . . .  }  abstract void draw();  }
Interface A special kind of a class which consists of only the constants and the method prototypes Practically is Java substitute of multiple inheritance A class can implement multiple interfaces
Interface Vs Abstract Class A third party class must be rewritten to extend only from the abstract class. An interface implementation may be added to any existing third party classes Third party convenience Both instance and static constant are possible Static final constants only Constants An abstract class can provide complete code, default code An interface can’t provide any code at all Default implementation A class may extend only one abstract class A class May implement several interfaces. Multiple Inheritance Abstract Class Interface Feature
Package The group of classes and interfaces Can be used other java standard packages Need to specified class paths for it
Package and Access Control yes Yes No Yes Different package non-subclass Yes Yes No Yes Different package subclass Yes Yes No Yes Same package non-subclass Yes Yes No Yes Same package subclass Yes Yes Yes Yes Same class No modifier Protected Private Public
Example Java Package Java.lang Java.applet Java.awt Java.io Java.util Java.net Java.rmi….etc
//Constructor Example class Constructor_test{ public Constructor_test() { System.out.println("Hello "); } public Constructor_test(String txt) { System.out.println("Hello "+txt); } public static void main(String args[]) { Constructor_test obj=new Constructor_test(); Constructor_test obj2=new Constructor_test(args[0]); } }
Method Overloading class Method_overload{ public void Show(){ System.out.println("Hello Myanmar"); } public static int Show(int num){ int a=num+10; return a; } public static void main(String args[]){ Method_overload obj=new Method_overload(); obj.Show(); int num=Show(320); System.out.println(num); } }
Inheritance Example class Super{ public void Show(){ System.out.println("Hello"); } } class Sub extends Super{ public static void main(String args[]){ Sub obj=new Sub(); obj.Show(); } }
Method overridden Example class Super{ public void Show(){ System.out.println("Hello"); } } class Sub extends Super{ public void Show(int num){ System.out.println("Hello "+num); } public static void main(String args[]){ Sub obj=new Sub(); obj.Show(); obj.Show(20); } }
Example for Constructors //Constructor and Overloaded Constructor class Me{ public Me(){ System.out.println("Hello Constructor"); } public Me(String arg){ System.out.println("Hello " +arg); } public static void main(String args[]){ Me obj=new Me(); // implicit Me obj1=new Me("OverLoaded Constructor"); } }
Method and Overloaded Method //Method and Overloaded Method class Me{ public void Show(){ System.out.println("Hello Method"); } public void Show(String arg){ System.out.println("Hello " +arg); } public static void main(String args[]){ Me obj=new Me(); obj.Show(); obj.Show("Overloaded Method"); } }
Overridden Method class Me{ public void Show(){ System.out.println("Hello Method"); } } class Sub extends Me{ public void Show(String arg){ System.out.println("Hello " +arg); } public static void main(String args[]){ Sub obj=new Sub(); obj.Show(); obj.Show("Overloaded Method"); } }
Generation Interface //interface example  public interface MyInterface{ public void add(int x,int y); }
Implementing Interface class Demo implements MyInterface{ public void add(int x,int y){ System.out.println("  "+(x+y)); } public static void main(String args[]){ Demo obj=new Demo(); obj.add(20,30); } }
Generating Package package MyPackage; public class Compute{ public int Add(int x,int y){ return (x+y); } public int Subtract(int x,int y){ return (x-y); } public int Multiply(int x,int y){ return (x*y); } public int Divide(int x,int y){ return (x/y); } }
Applying Package import MyPackage.*; class PKDemo{ public static void main(String args[]){ Compute obj=new Compute(); int sum=obj.Add(10,20); int sub=obj.Subtract(20,10); System.out.println("the total is "+sum); System.out.println("the minus is "+sub); } }

Object Oriented Programming with Java

  • 1.
    IADCS Diploma CourseObject Oriented Programming U Nyein Oo COO/Director(IT) Myanma Computer Co., Ltd(MCC)
  • 2.
    OOP? Software DevelopmentTechnique Effective use of programmer productivity Way of Creating Large Scale Systems Approaching 100% solution
  • 3.
    Basic Concepts ObjectClass Inheritance Polymorphism Encapsulation Data Abstraction
  • 4.
    Object A Person,Place or Concepts Composed of Characteristics (data) and Behavior (Operation) Can operate directly on its data Interact sending message to each other
  • 5.
    Class Structure thatcontains common data and function as entity for objects Each object is an instance of a class
  • 6.
    Inheritance The mechanismthat permits a class to share the attributes and operations defined in one or more classes
  • 7.
    Inheritance(cont) Subclass Theclass which inherits from another class Super class The class from which another class inherits its behavior Multiple Inheritance A subclass inherits from two or more classes
  • 8.
    Polymorphism The propertythat allows an operation to have different behavior on different objects
  • 9.
    Encapsulation The processof binding data and methods together is known as encapsulation
  • 10.
    Data Abstraction Theprocess of identifying and grouping attributes and actions related to a particular entity as relevant to the application a hand. Advantages - It focus on the problem - It identifies the essential characteristics and action - It helps the eliminate unnecessary details.
  • 11.
    Access Specifiers Public Private Protected
  • 12.
    Method Modifiers StaticAbstract Final Native Volatile
  • 13.
    Use of ModifiersNo Yes No Volatile No No Yes Native Yes Yes Yes Final Yes No Yes Abstract Yes(nested) Yes Yes Protected Yes(nested) Yes Yes Private Yes Yes Yes Public Class Variable Method Modifier
  • 14.
    Construction The processof bringing an object into existence is called construction A construction - Allocates memory - Initializes attributes, if any - Enables access to attributes and methods
  • 15.
    Constructor (cont) Explicitconstructor User defined constructor in class definition Implicit constructor Default constructor which is provided by JVM
  • 16.
    Destruction The processof deleting an objects is called destruction A destructor - Frees allocated space - Disable access to attributes and methods
  • 17.
    Method Overloading Inthe same class and same methods name But in different parameters and data types Form of compile time polymorphism
  • 18.
    Method Overridden Inthe super class as well as subclass Allows general classes to specify methods that will common to its subclass Form of runtime polymorphism
  • 19.
    Abstract class andmethod There is no code in abstract class and method Must be declared as abstract type Can not instantiated At least one abstract method in class
  • 20.
    Writing Abstract classand Method abstract class GraphicObject { int x, y; . . . void moveTo(int newX, int newY) { . . . } abstract void draw(); }
  • 21.
    Interface A specialkind of a class which consists of only the constants and the method prototypes Practically is Java substitute of multiple inheritance A class can implement multiple interfaces
  • 22.
    Interface Vs AbstractClass A third party class must be rewritten to extend only from the abstract class. An interface implementation may be added to any existing third party classes Third party convenience Both instance and static constant are possible Static final constants only Constants An abstract class can provide complete code, default code An interface can’t provide any code at all Default implementation A class may extend only one abstract class A class May implement several interfaces. Multiple Inheritance Abstract Class Interface Feature
  • 23.
    Package The groupof classes and interfaces Can be used other java standard packages Need to specified class paths for it
  • 24.
    Package and AccessControl yes Yes No Yes Different package non-subclass Yes Yes No Yes Different package subclass Yes Yes No Yes Same package non-subclass Yes Yes No Yes Same package subclass Yes Yes Yes Yes Same class No modifier Protected Private Public
  • 25.
    Example Java PackageJava.lang Java.applet Java.awt Java.io Java.util Java.net Java.rmi….etc
  • 26.
    //Constructor Example classConstructor_test{ public Constructor_test() { System.out.println("Hello "); } public Constructor_test(String txt) { System.out.println("Hello "+txt); } public static void main(String args[]) { Constructor_test obj=new Constructor_test(); Constructor_test obj2=new Constructor_test(args[0]); } }
  • 27.
    Method Overloading classMethod_overload{ public void Show(){ System.out.println("Hello Myanmar"); } public static int Show(int num){ int a=num+10; return a; } public static void main(String args[]){ Method_overload obj=new Method_overload(); obj.Show(); int num=Show(320); System.out.println(num); } }
  • 28.
    Inheritance Example classSuper{ public void Show(){ System.out.println("Hello"); } } class Sub extends Super{ public static void main(String args[]){ Sub obj=new Sub(); obj.Show(); } }
  • 29.
    Method overridden Exampleclass Super{ public void Show(){ System.out.println("Hello"); } } class Sub extends Super{ public void Show(int num){ System.out.println("Hello "+num); } public static void main(String args[]){ Sub obj=new Sub(); obj.Show(); obj.Show(20); } }
  • 30.
    Example for Constructors//Constructor and Overloaded Constructor class Me{ public Me(){ System.out.println("Hello Constructor"); } public Me(String arg){ System.out.println("Hello " +arg); } public static void main(String args[]){ Me obj=new Me(); // implicit Me obj1=new Me("OverLoaded Constructor"); } }
  • 31.
    Method and OverloadedMethod //Method and Overloaded Method class Me{ public void Show(){ System.out.println("Hello Method"); } public void Show(String arg){ System.out.println("Hello " +arg); } public static void main(String args[]){ Me obj=new Me(); obj.Show(); obj.Show("Overloaded Method"); } }
  • 32.
    Overridden Method classMe{ public void Show(){ System.out.println("Hello Method"); } } class Sub extends Me{ public void Show(String arg){ System.out.println("Hello " +arg); } public static void main(String args[]){ Sub obj=new Sub(); obj.Show(); obj.Show("Overloaded Method"); } }
  • 33.
    Generation Interface //interfaceexample public interface MyInterface{ public void add(int x,int y); }
  • 34.
    Implementing Interface classDemo implements MyInterface{ public void add(int x,int y){ System.out.println(" "+(x+y)); } public static void main(String args[]){ Demo obj=new Demo(); obj.add(20,30); } }
  • 35.
    Generating Package packageMyPackage; public class Compute{ public int Add(int x,int y){ return (x+y); } public int Subtract(int x,int y){ return (x-y); } public int Multiply(int x,int y){ return (x*y); } public int Divide(int x,int y){ return (x/y); } }
  • 36.
    Applying Package importMyPackage.*; class PKDemo{ public static void main(String args[]){ Compute obj=new Compute(); int sum=obj.Add(10,20); int sub=obj.Subtract(20,10); System.out.println("the total is "+sum); System.out.println("the minus is "+sub); } }