SlideShare a Scribd company logo
- Two basic components of a Java program
PACKAGES AND INTERFACES
IN
JAVA
OVERVIEW
 Interfaces
 Defining an interface
 Implementing interfaces
 Packages
 Defining a package
 Using package
I. INTERFACES
 Basically a kind of class
 specifies what a class must do, but not how it does it
Properties of interfaces-
o Implicitly abstract and public
o No constructors
o Multiple interface extension
o Bytecode appears in .class file
o Appear in packages
II. DEFINING AN INTERFACE
 Use of keyword “interface” allows to fully utilize the “one interface, multiple methods” aspect of
polymorphism
 General form:
interface interface name {
return-type method-name1(parameter-list);
return-type method-name2(parameter-list);
type final-varname1 = value;
type final-varname2 = value;
// …
return-type method-nameN(parameter-list);
type final-varnameN = value;
}
II. DEFINING AN INTERFACE (CONTINUED)
Note:
 access is either public or not used
 when access is declared as public, the interface can be used by any other code
 name is the name of the interface (any valid identifier)
 Variables can be declared inside of interface declarations that are implicitly final and
static
 Variables must be initialized with a constant value
 All methods and variables are implicitly public if the interface itself is declared as
public
III. IMPLEMENTING INTERFACES
 Include the implements clause in a class definition, then create the
methods defined by the interface
 General form of class that includes implements clause:
access class classname [extends superclass]
[implements interface [,interface…]]
{
// class-body
}
Note:
o If a class implements more than one interface, they are separated
with a comma
o Methods that implement an interface must be declared public
IV. PACKAGES
 Group of similar Java classes into namespaces
 Naming and visibility control mechanism
 Can be-
 Example: java.applet package
Types Details
Built-in java.lang, java.util
User-defined Created by user to categorize
classes and interface
V. DEFINING A PACKAGE
 Include a package command as the 1st statement in a Java source file
 General form of package statement:
package pkg;
[Note: pkg is the name of the package]
 Example:
package MyPackage;
[The above statement creates a package called MyPackage.]
V. DEFINING A PACKAGE (CONTINUED)
 Use of file system directories to store packages
 Same package statement inclusion in multiple files
 Creation of hierarchy of packages-
General form of multileveled package statement:
package pkg1[.pkg2[.pkg3]];
Example: a package declared as
package java.awt.image;
VI. USING PACKAGE
 The programs in which we want to use package should be placed inside the directory
where its subdirectory name is name of package.
 Import statement is used to call package which we want to use in a program.
 Example:
import packagename.classname2;
class classname1 extends classname2
{
body of class
}
CONCLUSION
It is a good coding practice to wrap codes using
packages for organizing similar files in one place
and to use interfaces wherever common
functionality is required more than once.
THANK YOU
FOR THE CONSIDERATION…

More Related Content

PPTX
Power point presentation on access specifier in OOPs
PDF
Unit 2 notes.pdf
PPTX
Z blue interfaces and packages (37129912)
PPT
PACKAGE.PPT12345678912345949745654646455
PPT
Unit 4 Java
PPTX
Package in Java
PPTX
java package in java.. in java packages.
PPTX
java package java package in java packages
Power point presentation on access specifier in OOPs
Unit 2 notes.pdf
Z blue interfaces and packages (37129912)
PACKAGE.PPT12345678912345949745654646455
Unit 4 Java
Package in Java
java package in java.. in java packages.
java package java package in java packages

Similar to Packages and interfaces (20)

PPTX
Java package
PPT
Packages,interfaces and exceptions
PPTX
javapackage,try,cthrow,finallytch,-160518085421 (1).pptx
PPTX
Lecture 19
PPTX
Java packages oop
PPTX
PPTX
Packages
PPTX
packages in java & c++
PPTX
Packages in java
PPTX
Introduction to package in java
PDF
Java - Packages Concepts
PDF
Java - Interfaces & Packages
PDF
JAVA 2-studenttrreadexeceptionpackages.pdf
PPTX
packages in java object oriented programming
DOCX
Class notes(week 7) on packages
PPTX
Packages and interface
PPT
packages.ppt
PPTX
Packages in java
DOCX
Unit4 java
DOCX
Module-4 Java Notes.docx notes about java
Java package
Packages,interfaces and exceptions
javapackage,try,cthrow,finallytch,-160518085421 (1).pptx
Lecture 19
Java packages oop
Packages
packages in java & c++
Packages in java
Introduction to package in java
Java - Packages Concepts
Java - Interfaces & Packages
JAVA 2-studenttrreadexeceptionpackages.pdf
packages in java object oriented programming
Class notes(week 7) on packages
Packages and interface
packages.ppt
Packages in java
Unit4 java
Module-4 Java Notes.docx notes about java
Ad

More from Andhra University (9)

PPTX
System development life cycle models
PPTX
Software testing
PPTX
Software requirement specification
PPTX
Software management
PPTX
Modes of transfer
PPTX
Flip flops and registers
PPTX
Error managing and exception handling in java
PPTX
Computer instruction set
PPTX
Applet programming
System development life cycle models
Software testing
Software requirement specification
Software management
Modes of transfer
Flip flops and registers
Error managing and exception handling in java
Computer instruction set
Applet programming
Ad

Recently uploaded (20)

PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
Getting Started with Data Integration: FME Form 101
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
Hybrid model detection and classification of lung cancer
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
1 - Historical Antecedents, Social Consideration.pdf
PPTX
Web Crawler for Trend Tracking Gen Z Insights.pptx
PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PPT
What is a Computer? Input Devices /output devices
PPTX
Tartificialntelligence_presentation.pptx
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPT
Module 1.ppt Iot fundamentals and Architecture
PPTX
Chapter 5: Probability Theory and Statistics
PPTX
Modernising the Digital Integration Hub
PDF
Unlock new opportunities with location data.pdf
PDF
WOOl fibre morphology and structure.pdf for textiles
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Getting Started with Data Integration: FME Form 101
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
A review of recent deep learning applications in wood surface defect identifi...
Hybrid model detection and classification of lung cancer
Developing a website for English-speaking practice to English as a foreign la...
1 - Historical Antecedents, Social Consideration.pdf
Web Crawler for Trend Tracking Gen Z Insights.pptx
observCloud-Native Containerability and monitoring.pptx
Taming the Chaos: How to Turn Unstructured Data into Decisions
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
What is a Computer? Input Devices /output devices
Tartificialntelligence_presentation.pptx
Group 1 Presentation -Planning and Decision Making .pptx
Module 1.ppt Iot fundamentals and Architecture
Chapter 5: Probability Theory and Statistics
Modernising the Digital Integration Hub
Unlock new opportunities with location data.pdf
WOOl fibre morphology and structure.pdf for textiles

Packages and interfaces

  • 1. - Two basic components of a Java program PACKAGES AND INTERFACES IN JAVA
  • 2. OVERVIEW  Interfaces  Defining an interface  Implementing interfaces  Packages  Defining a package  Using package
  • 3. I. INTERFACES  Basically a kind of class  specifies what a class must do, but not how it does it Properties of interfaces- o Implicitly abstract and public o No constructors o Multiple interface extension o Bytecode appears in .class file o Appear in packages
  • 4. II. DEFINING AN INTERFACE  Use of keyword “interface” allows to fully utilize the “one interface, multiple methods” aspect of polymorphism  General form: interface interface name { return-type method-name1(parameter-list); return-type method-name2(parameter-list); type final-varname1 = value; type final-varname2 = value; // … return-type method-nameN(parameter-list); type final-varnameN = value; }
  • 5. II. DEFINING AN INTERFACE (CONTINUED) Note:  access is either public or not used  when access is declared as public, the interface can be used by any other code  name is the name of the interface (any valid identifier)  Variables can be declared inside of interface declarations that are implicitly final and static  Variables must be initialized with a constant value  All methods and variables are implicitly public if the interface itself is declared as public
  • 6. III. IMPLEMENTING INTERFACES  Include the implements clause in a class definition, then create the methods defined by the interface  General form of class that includes implements clause: access class classname [extends superclass] [implements interface [,interface…]] { // class-body } Note: o If a class implements more than one interface, they are separated with a comma o Methods that implement an interface must be declared public
  • 7. IV. PACKAGES  Group of similar Java classes into namespaces  Naming and visibility control mechanism  Can be-  Example: java.applet package Types Details Built-in java.lang, java.util User-defined Created by user to categorize classes and interface
  • 8. V. DEFINING A PACKAGE  Include a package command as the 1st statement in a Java source file  General form of package statement: package pkg; [Note: pkg is the name of the package]  Example: package MyPackage; [The above statement creates a package called MyPackage.]
  • 9. V. DEFINING A PACKAGE (CONTINUED)  Use of file system directories to store packages  Same package statement inclusion in multiple files  Creation of hierarchy of packages- General form of multileveled package statement: package pkg1[.pkg2[.pkg3]]; Example: a package declared as package java.awt.image;
  • 10. VI. USING PACKAGE  The programs in which we want to use package should be placed inside the directory where its subdirectory name is name of package.  Import statement is used to call package which we want to use in a program.  Example: import packagename.classname2; class classname1 extends classname2 { body of class }
  • 11. CONCLUSION It is a good coding practice to wrap codes using packages for organizing similar files in one place and to use interfaces wherever common functionality is required more than once.
  • 12. THANK YOU FOR THE CONSIDERATION…