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

Similar to Packages and interfaces

Java packages oop
Java packages oopJava packages oop
Java packages oop
Kawsar Hamid Sumon
 
Packages
PackagesPackages
Packages
PackagesPackages
Packages
Monika Mishra
 
packages in java & c++
packages in java & c++packages in java & c++
packages in java & c++
pankaj chelak
 
Packages in java
Packages in javaPackages in java
Packages in java
Elizabeth alexander
 
Introduction to package in java
Introduction to package in javaIntroduction to package in java
Introduction to package in java
Prognoz Technologies Pvt. Ltd.
 
Java - Packages Concepts
Java - Packages ConceptsJava - Packages Concepts
Java - Packages Concepts
Victer Paul
 
Java - Interfaces & Packages
Java - Interfaces & PackagesJava - Interfaces & Packages
Java - Interfaces & Packages
Arindam Ghosh
 
Class notes(week 7) on packages
Class notes(week 7) on packagesClass notes(week 7) on packages
Class notes(week 7) on packages
Kuntal Bhowmick
 
Packages and interface
Packages and interfacePackages and interface
Packages and interface
KarthigaGunasekaran1
 
packages.ppt
packages.pptpackages.ppt
packages.ppt
SanthiNivas
 
Packages in java
Packages in javaPackages in java
Packages in java
SahithiReddyEtikala
 
Unit4 java
Unit4 javaUnit4 java
Unit4 javamrecedu
 
Packages in java
Packages in javaPackages in java
Packages in java
Jerlin Sundari
 
OOP_packages_222902019.pptx
OOP_packages_222902019.pptxOOP_packages_222902019.pptx
OOP_packages_222902019.pptx
222902019
 
OOP_packages_222902019.pptx
OOP_packages_222902019.pptxOOP_packages_222902019.pptx
OOP_packages_222902019.pptx
222902019
 
Java packages
Java packagesJava packages
Java packages
Jeffrey Quevedo
 
5.interface and packages
5.interface and packages5.interface and packages
5.interface and packagesDeepak Sharma
 
150950107056 2150704
150950107056 2150704150950107056 2150704
150950107056 2150704
Prashant Mokani
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
VINOTH R
 

Similar to Packages and interfaces (20)

Java packages oop
Java packages oopJava packages oop
Java packages oop
 
Packages
PackagesPackages
Packages
 
Packages
PackagesPackages
Packages
 
packages in java & c++
packages in java & c++packages in java & c++
packages in java & c++
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Introduction to package in java
Introduction to package in javaIntroduction to package in java
Introduction to package in java
 
Java - Packages Concepts
Java - Packages ConceptsJava - Packages Concepts
Java - Packages Concepts
 
Java - Interfaces & Packages
Java - Interfaces & PackagesJava - Interfaces & Packages
Java - Interfaces & Packages
 
Class notes(week 7) on packages
Class notes(week 7) on packagesClass notes(week 7) on packages
Class notes(week 7) on packages
 
Packages and interface
Packages and interfacePackages and interface
Packages and interface
 
packages.ppt
packages.pptpackages.ppt
packages.ppt
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Unit4 java
Unit4 javaUnit4 java
Unit4 java
 
Packages in java
Packages in javaPackages in java
Packages in java
 
OOP_packages_222902019.pptx
OOP_packages_222902019.pptxOOP_packages_222902019.pptx
OOP_packages_222902019.pptx
 
OOP_packages_222902019.pptx
OOP_packages_222902019.pptxOOP_packages_222902019.pptx
OOP_packages_222902019.pptx
 
Java packages
Java packagesJava packages
Java packages
 
5.interface and packages
5.interface and packages5.interface and packages
5.interface and packages
 
150950107056 2150704
150950107056 2150704150950107056 2150704
150950107056 2150704
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
 

More from Andhra University

System development life cycle models
System development life cycle modelsSystem development life cycle models
System development life cycle models
Andhra University
 
Software testing
Software testingSoftware testing
Software testing
Andhra University
 
Software requirement specification
Software requirement specificationSoftware requirement specification
Software requirement specification
Andhra University
 
Software management
Software managementSoftware management
Software management
Andhra University
 
Modes of transfer
Modes of transferModes of transfer
Modes of transfer
Andhra University
 
Flip flops and registers
Flip flops and registersFlip flops and registers
Flip flops and registers
Andhra University
 
Error managing and exception handling in java
Error managing and exception handling in javaError managing and exception handling in java
Error managing and exception handling in java
Andhra University
 
Computer instruction set
Computer instruction setComputer instruction set
Computer instruction set
Andhra University
 

More from Andhra University (9)

System development life cycle models
System development life cycle modelsSystem development life cycle models
System development life cycle models
 
Software testing
Software testingSoftware testing
Software testing
 
Software requirement specification
Software requirement specificationSoftware requirement specification
Software requirement specification
 
Software management
Software managementSoftware management
Software management
 
Modes of transfer
Modes of transferModes of transfer
Modes of transfer
 
Flip flops and registers
Flip flops and registersFlip flops and registers
Flip flops and registers
 
Error managing and exception handling in java
Error managing and exception handling in javaError managing and exception handling in java
Error managing and exception handling in java
 
Computer instruction set
Computer instruction setComputer instruction set
Computer instruction set
 
Applet programming
Applet programming Applet programming
Applet programming
 

Recently uploaded

Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 

Recently uploaded (20)

Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 

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…