Java Network Programming Research Topic Presentation Java Interfaces - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Java Network Programming Research Topic Presentation Java Interfaces

Description:

... or many interfaces, writes the method codes of all the interfaces in the class body. ... http://java.sun.com/docs/books/tutorial/java/interpack/interfaces.html ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 10
Provided by: ca26
Category:

less

Transcript and Presenter's Notes

Title: Java Network Programming Research Topic Presentation Java Interfaces


1
Java Network ProgrammingResearch Topic
PresentationJava Interfaces
  • Abbu Rajaram Rakesh Kumar
  • rakesh.abbu-rajaram_at_sunderland.ac.uk

2
Java Interfaces Introduction
  • An interface defines a protocol of behaviour that
    can be implemented by any class anywhere in the
    class hierarchy.
  • Definition An interface is a named collection of
    method definitions (without implementations). An
    interface can also declare constants.
  • When a method is called from one class to
    another, both the classes should be present at
    compile time for the verification of the
    signatures, thus as the class hierarchy gets high
    performance deteoriates. Interfaces are designed
    to avoid such a problem.

3
Java Interfaces Contd..
  • Structure similar to a class, but lack instance
    variables.
  • It is a simple list of unimplemented methods.
  • A class can be fully abstract by implementing
    interfaces.
  • The interfaces only define methods but not, what
    they do.
  • Any number of classes can implement a single
    interface.
  • A class can implement any number of interfaces.
  • They are designed to support dynamic method
    resolution at run time.
  • Interfaces do not follow hierarchy as the classes
    do.

4
Class Vs Interfaces
  • Interface does not implement any methods unlike
    an abstract classes.
  • A class can implement many interfaces but can
    have only one super class.
  • Many classes from different hierarchy can
    implement interfaces.

5
Define Implement Interfaces
  • Defined similar to class, uses interface
    keyword.
  • The access type is either abstract or public
    but never private.
  • Methods are declared but no bodies of the method
    are specified.
  • An example below
  • public interface CallBack
  • int x, y 0
  • string a yes
  • string b no
  • void callback(int p)

6
Define Implement contd..
  • Variables can be defined in the interfaces but
    they are done implicitly final and static.
  • The interface methods are declared as public
    access.
  • Class implementing one or many interfaces, writes
    the method codes of all the interfaces in the
    class body.
  • The class can write additional methods in
    addition to the interface methods.
  • The instance object of the class implementing the
    interface can also call the interface methods
    variables.
  • The method called is looked up dynamically at run
    time,

7
Define Implement contd..
  • here the classes are created later than the code
    which call them.
  • Calling code can dispatch thru interface, without
    having to know about the callee.
  • Be cautious while using because it requires lot
    of processing capability, because of its run time
    lookup.
  • An interface can inherit another interface.
  • Class implementing the interface can also do
    partially, then such a class and its inheriting
    class should be declared abstract.
  • Interface can be used to declare a variable of
    its type.

8
Applying Interfaces
  • Interface is a powerful tool, interface methods
    can be defined accordingly in the different
    implementing classes.
  • The called methods are invoked at the run time
    rather than at the compile time.
  • Thus run time polymorphism is achieved.

9
References
  • Herbert Schildt (2002), The Complete Reference,
    Java 2. Fifth Edition, Tata McGraw-Hill, India.
  • http//java.sun.com/docs/books/tutorial/java/inter
    pack/interfaces.html
Write a Comment
User Comments (0)
About PowerShow.com