SOFT SKILLS AND
PERSONALITY DEVELOPMENT
TOPIC:INTERFACE AND PACKAGES
SUBMITTED BY
MOHAMMAD AZHAR UD DIN
ROLLNO:13YYSB6009
*
An interface is a keyword , it is a special java class
which is fully abstracted.
•There are two types of interface:-
-Public final static variables.
-Public abstract methods .
•To inherit interface by a class then use the keyword
‘Implements’
• To inherit interface by an interface then use the
keyword ‘Extends’
Syntax :
Interface interfacename
{
Variable declaration
Method declaration
}
- An interface can extends one or more interfaces
- Interface cannot extends class
- Interface cannot implements interfaces
- Class can extends at most only one class
- Class can implements one or more interfaces
- A class can extends one class and implements multiple
interface at the time.
Syntax: Class sub-class extends super class implements
interface 1,… n;
Interface
Example : for implementing interface
Interface one
{
Int i = 10;
Void show();
}
Class two implement one
{
Void show()
{
System.out.print(i);
}
}
Class Sample
{
Public static void main(String
a[])
{
Two t = new two();
t.show()
}
}
Example for extending Interface:
Interface one
{
Abstract void show();
}
Class sam1 implements one
{
Int a, b;
Sam1(int i, int j)
{
a = i ;
b = j;
}
Void show()
{
System.out.print(a);
System.out.print(b);
}
{
Abstract class sam2 implements
one
{
Void print()
System.out.print(“sam2 class”)
}
}
Class sam3 extends sam2
{
Void show()
{
System.out.print(sam3 class”);
}
}
Class sample
{
Public static void main(String a[])
{
Sam1 s1 = new sam1(10 , 20);
s1.show();
Sam2 s3 = new sam3 ();
s3.print();
s3.show();
}
}
THE DIFFERENCES BETWEEN CLASS AND
INTERFACES
Class
• Class can implement more
Than one interface.
•Class contain design and
implementation of code.
* contains constants, variables and
Methods.
•Class can be instantiated.
Interface
*Interface can extend more than
one interface
•Pure design.
•Contains constants and abstract
methods.
*Interfaces can’t be instantiated.
DEFINING INTERFACES
The general form of a definition is
Interfaces <INTERFACE NAME>
{
<Final Fields>
<abstract methods>
}
Extending interfaces
The Interfaces can be extended .
That is an inheritance
Can extended from another
interface.
•Sub Interface
•Super Interface
Super interface
Interface
TYPES OF PACKAGES
Packages is collection of a class or interfaces.
Two types of packages are there:
Java API Packages
User defined Packages
i. Java API packages provides larges no. of classes grouped into
different package to functionality.
java
Lang utile io awt net applet
I. Java . lang.*: This package includes in classes for primitive type
, math functions threads , string and exceptions
II. Java . util.*: This package contains classes such as data , vector,
hash table
III. Java.io.*: This package contains classes that support input and
output operation.
IV. Java.awt.*: This package contains set of classes for
implementing graphical user interface. It include buttons menu
, window etc.
V. Java.net.*: This packages contains classes for networking , it
includes classes for communicating with local & internet server.
VI. Java . applet.*: This package includes for creating and
implementing applets
APPLICATION PROGRAMMING INTERFACE
PACKAGES DEFINITION
User defined packages:
This are the packages that are defined by user
or programmer.
o Creating packages:
Syntax: package packagesname;
‘package’ is a keyword and packagename is
identifier.
E.g : package p1;
o Accessing packages.
Packages can be access using ‘import’ statement
Import package1 [.package 2][.package
3].classname;

Interface &amp;packages

  • 1.
    SOFT SKILLS AND PERSONALITYDEVELOPMENT TOPIC:INTERFACE AND PACKAGES SUBMITTED BY MOHAMMAD AZHAR UD DIN ROLLNO:13YYSB6009
  • 2.
    * An interface isa keyword , it is a special java class which is fully abstracted. •There are two types of interface:- -Public final static variables. -Public abstract methods . •To inherit interface by a class then use the keyword ‘Implements’ • To inherit interface by an interface then use the keyword ‘Extends’ Syntax : Interface interfacename { Variable declaration Method declaration }
  • 3.
    - An interfacecan extends one or more interfaces - Interface cannot extends class - Interface cannot implements interfaces - Class can extends at most only one class - Class can implements one or more interfaces - A class can extends one class and implements multiple interface at the time. Syntax: Class sub-class extends super class implements interface 1,… n; Interface
  • 4.
    Example : forimplementing interface Interface one { Int i = 10; Void show(); } Class two implement one { Void show() { System.out.print(i); } } Class Sample { Public static void main(String a[]) { Two t = new two(); t.show() } }
  • 5.
    Example for extendingInterface: Interface one { Abstract void show(); } Class sam1 implements one { Int a, b; Sam1(int i, int j) { a = i ; b = j; } Void show() { System.out.print(a); System.out.print(b); } { Abstract class sam2 implements one { Void print() System.out.print(“sam2 class”) } } Class sam3 extends sam2 { Void show() { System.out.print(sam3 class”); } } Class sample { Public static void main(String a[]) { Sam1 s1 = new sam1(10 , 20); s1.show(); Sam2 s3 = new sam3 (); s3.print(); s3.show(); } }
  • 6.
    THE DIFFERENCES BETWEENCLASS AND INTERFACES Class • Class can implement more Than one interface. •Class contain design and implementation of code. * contains constants, variables and Methods. •Class can be instantiated. Interface *Interface can extend more than one interface •Pure design. •Contains constants and abstract methods. *Interfaces can’t be instantiated.
  • 7.
    DEFINING INTERFACES The generalform of a definition is Interfaces <INTERFACE NAME> { <Final Fields> <abstract methods> }
  • 8.
    Extending interfaces The Interfacescan be extended . That is an inheritance Can extended from another interface. •Sub Interface •Super Interface Super interface Interface
  • 9.
    TYPES OF PACKAGES Packagesis collection of a class or interfaces. Two types of packages are there: Java API Packages User defined Packages i. Java API packages provides larges no. of classes grouped into different package to functionality. java Lang utile io awt net applet
  • 10.
    I. Java .lang.*: This package includes in classes for primitive type , math functions threads , string and exceptions II. Java . util.*: This package contains classes such as data , vector, hash table III. Java.io.*: This package contains classes that support input and output operation. IV. Java.awt.*: This package contains set of classes for implementing graphical user interface. It include buttons menu , window etc. V. Java.net.*: This packages contains classes for networking , it includes classes for communicating with local & internet server. VI. Java . applet.*: This package includes for creating and implementing applets APPLICATION PROGRAMMING INTERFACE PACKAGES DEFINITION
  • 11.
    User defined packages: Thisare the packages that are defined by user or programmer. o Creating packages: Syntax: package packagesname; ‘package’ is a keyword and packagename is identifier. E.g : package p1; o Accessing packages. Packages can be access using ‘import’ statement Import package1 [.package 2][.package 3].classname;