KEMBAR78
Java- language Lecture 7 | PDF
JAVA
FUNDAMENTALS
Eng : Hatem Abd El-Salam
Lecture 7
Agenda
 Wrapper classes
 Abstraction
 Interface
 Delection
© 2016 by Eng. Hatem Abd El-Salam
Wrapper classes
© 2016 by Eng. Hatem Abd El-Salam
Wrapper classes (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Wrapper classes (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Abstraction
 Abstraction is a process of hiding the implementation details and showing only
functionality to the user.
 Another way, it shows only important things to the user and hides the internal
details .
for example: sending sms, you just type the text and send the message. You don't
know the internal processing about the message delivery.
 Abstraction lets you focus on what the object does instead of how it does it
© 2016 by Eng. Hatem Abd El-Salam
Abstraction (Cont.)
Ways to achieve Abstraction
 There are two ways to achieve abstraction in java
1. Abstract class (0 to 100%)
2. Interface (100%)
Abstract class in Java
• A class that is declared as abstract is known as abstract class. It needs to be
extended and its method implemented. It cannot be instantiated.
• It can have abstract and non-abstract methods (method with body).
© 2016 by Eng. Hatem Abd El-Salam
Abstraction (Cont.)
Abstract method
 A method that is declared as abstract and does not have implementation is known
as abstract method.
© 2016 by Eng. Hatem Abd El-Salam
© 2016 by Eng. Hatem Abd El-Salam
© 2016 by Eng. Hatem Abd El-Salam
Abstraction (Cont.)
Rules
 If there is any abstract method in a class, that class must be abstract.
 If you are extending any abstract class that have abstract method, you must either
provide the implementation of the method or make this class abstract.
© 2016 by Eng. Hatem Abd El-Salam
Interface
 An interface in java is a blueprint of a class. It has static constants and abstract
methods only.
 The interface in java is a mechanism to achieve fully abstraction. There can be only
abstract methods in the java interface not method body. It is used to achieve fully
abstraction and multiple inheritance in Java.
 Java Interface also represents IS-A relationship.
 It cannot be instantiated just like abstract class.
© 2016 by Eng. Hatem Abd El-Salam
Interface (Cont.)
Why use Java interface ?
 There are mainly three reasons to use interface. They are given below.
1. It is used to achieve fully abstraction.
2. By interface, we can support the functionality of multiple inheritance.
3. It can be used to achieve loose coupling.
© 2016 by Eng. Hatem Abd El-Salam
Interface (Cont.)
 The java compiler adds public and abstract keywords before the interface method
and public, static and final keywords before data members.
© 2016 by Eng. Hatem Abd El-Salam
Interface (Cont.)
Understanding relationship between classes and interfaces
© 2016 by Eng. Hatem Abd El-Salam
Interface (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
Interface (Cont.)
Multiple inheritance in Java by interface
© 2016 by Eng. Hatem Abd El-Salam
Interface (Cont.)
© 2016 by Eng. Hatem Abd El-Salam
© 2016 by Eng. Hatem Abd El-Salam
© 2016 by Eng. Hatem Abd El-Salam
Delegation
Q:What are delegates?
When an object receives a request, the object can either handle the request itself or
pass the request on to a second object to do the work. If the object decides to pass
the request on, you say that the object has forwarded responsibility(delegate) for
handling the request to the second object.
Simple examples
© 2016 by Eng. Hatem Abd El-Salam
Complex examples
© 2016 by Eng. Hatem Abd El-Salam
© 2016 by Eng. Hatem Abd El-Salam
Name : Eng. Hatem Abd El-Salam
Email : Hatemabdelsalam@Hotmail.com
LinkedIn : linkedin.com/in/hatemabdelsalam
SlideShare : slideshare.net/HatemAbdElSalam
Contact Details
© 2016 by Eng. Hatem Abd El-Salam

Java- language Lecture 7

  • 1.
    JAVA FUNDAMENTALS Eng : HatemAbd El-Salam Lecture 7
  • 2.
    Agenda  Wrapper classes Abstraction  Interface  Delection © 2016 by Eng. Hatem Abd El-Salam
  • 3.
    Wrapper classes © 2016by Eng. Hatem Abd El-Salam
  • 4.
    Wrapper classes (Cont.) ©2016 by Eng. Hatem Abd El-Salam
  • 5.
    Wrapper classes (Cont.) ©2016 by Eng. Hatem Abd El-Salam
  • 6.
    Abstraction  Abstraction isa process of hiding the implementation details and showing only functionality to the user.  Another way, it shows only important things to the user and hides the internal details . for example: sending sms, you just type the text and send the message. You don't know the internal processing about the message delivery.  Abstraction lets you focus on what the object does instead of how it does it © 2016 by Eng. Hatem Abd El-Salam
  • 7.
    Abstraction (Cont.) Ways toachieve Abstraction  There are two ways to achieve abstraction in java 1. Abstract class (0 to 100%) 2. Interface (100%) Abstract class in Java • A class that is declared as abstract is known as abstract class. It needs to be extended and its method implemented. It cannot be instantiated. • It can have abstract and non-abstract methods (method with body). © 2016 by Eng. Hatem Abd El-Salam
  • 8.
    Abstraction (Cont.) Abstract method A method that is declared as abstract and does not have implementation is known as abstract method. © 2016 by Eng. Hatem Abd El-Salam
  • 9.
    © 2016 byEng. Hatem Abd El-Salam
  • 10.
    © 2016 byEng. Hatem Abd El-Salam
  • 11.
    Abstraction (Cont.) Rules  Ifthere is any abstract method in a class, that class must be abstract.  If you are extending any abstract class that have abstract method, you must either provide the implementation of the method or make this class abstract. © 2016 by Eng. Hatem Abd El-Salam
  • 12.
    Interface  An interfacein java is a blueprint of a class. It has static constants and abstract methods only.  The interface in java is a mechanism to achieve fully abstraction. There can be only abstract methods in the java interface not method body. It is used to achieve fully abstraction and multiple inheritance in Java.  Java Interface also represents IS-A relationship.  It cannot be instantiated just like abstract class. © 2016 by Eng. Hatem Abd El-Salam
  • 13.
    Interface (Cont.) Why useJava interface ?  There are mainly three reasons to use interface. They are given below. 1. It is used to achieve fully abstraction. 2. By interface, we can support the functionality of multiple inheritance. 3. It can be used to achieve loose coupling. © 2016 by Eng. Hatem Abd El-Salam
  • 14.
    Interface (Cont.)  Thejava compiler adds public and abstract keywords before the interface method and public, static and final keywords before data members. © 2016 by Eng. Hatem Abd El-Salam
  • 15.
    Interface (Cont.) Understanding relationshipbetween classes and interfaces © 2016 by Eng. Hatem Abd El-Salam
  • 16.
    Interface (Cont.) © 2016by Eng. Hatem Abd El-Salam
  • 17.
    Interface (Cont.) Multiple inheritancein Java by interface © 2016 by Eng. Hatem Abd El-Salam
  • 18.
    Interface (Cont.) © 2016by Eng. Hatem Abd El-Salam
  • 19.
    © 2016 byEng. Hatem Abd El-Salam
  • 20.
    © 2016 byEng. Hatem Abd El-Salam
  • 21.
    Delegation Q:What are delegates? Whenan object receives a request, the object can either handle the request itself or pass the request on to a second object to do the work. If the object decides to pass the request on, you say that the object has forwarded responsibility(delegate) for handling the request to the second object. Simple examples © 2016 by Eng. Hatem Abd El-Salam
  • 22.
    Complex examples © 2016by Eng. Hatem Abd El-Salam
  • 23.
    © 2016 byEng. Hatem Abd El-Salam Name : Eng. Hatem Abd El-Salam Email : Hatemabdelsalam@Hotmail.com LinkedIn : linkedin.com/in/hatemabdelsalam SlideShare : slideshare.net/HatemAbdElSalam Contact Details
  • 24.
    © 2016 byEng. Hatem Abd El-Salam