SlideShare a Scribd company logo
JAVA concepts
Packages and interfaces
Exception handling
Accessing
classes from
package
Naming
conventions
API
packages
Creating
packages
Packages and interfaces
Packages
Packages are java’s way of grouping a variety of classes and
interfaces together.
Packages acts as “containers ” for classes.
Benefits of using packages:
Reused
Hiding
separating “design” from “coding”.
Two classes in two different packages can have same name.
packages
Packages and interfaces
Java
API
Packages
Java API provides a large number of classes grouped into
different packages according to functionality.
Packages and interfaces
Package name Contents
java.lang Language support classes that java compiler itself uses and
automatically imported . They include classes for primitive types ,
strings , math functions , threads and exceptions.
java.util Language utility classes such as vectors , hash tables , random
numbers , date , etc.
java.io Input/output support classes that provide facilities for input and
output of data.
java.awt Set of classes for implementing GUI like windows , buttons , lists ,
menus , colors , etc.
java.net Classes for networking for communication with local computer as
well as with internet servers
java.applet Classes for creating and implementing applets
Packages and interfaces
Using
system
Packages
jav
a
Package
Containing
awt package
Package
Containing
classes
Classes
Containing
methods
Hierarchical representation of
java.awt package
There are two ways of accessing the classes stored in the package.
Java.awt.Color;
import packagename.classname;
(or)
import packagename.*;
First approach is perhaps easy and best way to access a class only
once or when we need not have to access any other classes of the
package.
But, in many situations we want to use a class in number of places
in program then we use second approach
Packages and interfaces
Accessing
the
classes
stored in
the
package
There are known as import statements and must appear at the top
of the file , before any class declarations , import is a keyword.
import Java.awt.Color;
This statement allows specified class in specified package to
be imported
import java.awt.*;
This statement imports every class contained in the specified
package.
Packages and interfaces
Accessing
the
classes
stored in
the
package
Naming
conventio
ns
Packages begin with lowercase .
java.lang.Math.sqrt(x);
Packages and interfaces
Package
name
Class
name
Method
name
Packages and interfaces
CLICK HERE FOR MORE INFO
Creating packages
We must first declare the name of the package using package
keyword followed by package name.
This must be the first statement in the source file except the
comments and whitespaces followed by normal class definition.
package firstPackage; //package declaration
public class firstclass //class definition
{
………….
…………..
…………..
}
Packages and interfaces
CLICK HERE FOR MORE INFO
Creating packages
Remember that the .class files must be located in a directory that has the same
name as the package and this directory should be a subdirectory where classes
will import the package are located.
Creating ore own packages involve the following steps:
Declare the package at the beginning of the file using the form
package packagename;
Define the class that is to be put in the package and declare it public.
Create the subdirectory under the directory where the main source files are
stored.
Store the listing as the class name java file in the subdirectory created.
Compile the file . This creates .class file in the subdirectory
Packages and interfaces
Accessing a package
import package1 [.package2] [.package3].classname;
Packages and interfaces
Adding a class to a package
It is simple to add a class to an existing package.
package p1;
public class A
{
//body of A
}
if we want to add another class B to this package
Define the class and make it public
Place the package statements
package p1;
public class B{
//body of B }
Store B.java file in p1 directory.
Compile B.java file . This will create B.class file and place it in the directory
p1.
0
Implementing
interface
Naming
conventions
Extending
interface
Creating
packages
Packages and interfaces
Why do we need Interfaces?
For the use of multiple inheritance which is not supported by
Java
A java class cannot be a subclass of more than one super class , it
can implement more than one interface , enabling us to create
classes that build upon other classes without the problem created
by multiple inheritance.
Interface
Packages and interfaces
Defining
interfaces
An interface is
basically a kind
of class
What is the difference between
an interface and a class?
Interface defines only abstract methods and fields. I .e. , the
interface do not specify any code to implement these methods
and data fields contain only constants
Therefore it is the responsibility of the class that implements an
interface to define the code for implementation of these methods.
Packages and interfaces
Syntax
for
interface
interface interfacename
{
variables declaration;
methods declaration;
}
Here interface is the keyword .
Example :
interface area
{
final static float pi=3.14f;
Float compute(float x , float y)
void show();
}
Like classes , interfaces can also be extended by the key word
extends
Syntax :
interface name2 extends name1{
//Body of name2}
Example :
interface ItemConstants
{
int code = 1001;
String name=“fan”;
}
Interafce Item extends Item Constans
{
void display();
}
Packages and interfaces
Extending
interfaces
Impleme
nting
interfaces
Interfaces are used as “ superclasses ” whose properties
are inherited by classes.
It is necessary to create a class that inherits the given
interface.
Syntax:
class classname implements interfacename
{
//body of class
}
Here class implements the interface. implements is the
keyword
If a class that implements an interface does not
implement all the methods of the interface then the class
becomes an abstract class and cannot be instantiated
Packages and interfaces
Impleme
nting
interface
with an
example
interface Area
{
final static float pi=3.14f;
float compute (float x , float y );
}
Class Rectangle implements Area
{
public float compute(float x, float y)
{
Return(x*y);
}
}
class Circle implements Area
{
public float compute(float x, float y)
{
return(pi*x*x);
}
}
class InterfaceTest
Packages and interfaces
Packages and interfaces
Various Forms of interface
implementation
nterface
mplementation
class
Extension
class
class
class
class
Extension
Extension
interface
interface
implementation
Extension
Various Forms of interface
implementation
nterface
implementation
class
class class
Extension
interface interface
implementation
Accessing
interface
variable
Packages and interfaces
Interfaces can be used to declare a set of constants that can be
used in different classes
This is similar to creating header files in C++
The constant class will be available to any class that implements
the interface . The values can be used in any method.
Ex : interface A{
int m=10;
Int n=50;}
Class B implements A
{
int x=m;
void methodB ( int size
{
………..
If (size<n)
……….
)
Thank
you
Ad

More Related Content

What's hot (20)

Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
Kumar
 
OOP java
OOP javaOOP java
OOP java
xball977
 
Constants, Variables and Data Types in Java
Constants, Variables and Data Types in JavaConstants, Variables and Data Types in Java
Constants, Variables and Data Types in Java
Abhilash Nair
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
Tareq Hasan
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
Abishek Purushothaman
 
Scanner class java
Scanner class javaScanner class java
Scanner class java
Kongu Engineering College, Perundurai, Erode
 
Exception handling
Exception handlingException handling
Exception handling
PhD Research Scholar
 
Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
Elizabeth alexander
 
Java packages
Java packagesJava packages
Java packages
Raja Sekhar
 
Creating your own exception
Creating your own exceptionCreating your own exception
Creating your own exception
TharuniDiddekunta
 
Java Presentation
Java PresentationJava Presentation
Java Presentation
pm2214
 
History Of JAVA
History Of JAVAHistory Of JAVA
History Of JAVA
ARSLANAHMED107
 
Bca sem 5 c# practical
Bca sem 5 c# practicalBca sem 5 c# practical
Bca sem 5 c# practical
Hitesh Patel
 
Java keywords
Java keywordsJava keywords
Java keywords
Ravi_Kant_Sahu
 
Java program structure
Java program structureJava program structure
Java program structure
shalinikarunakaran1
 
Static Members-Java.pptx
Static Members-Java.pptxStatic Members-Java.pptx
Static Members-Java.pptx
ADDAGIRIVENKATARAVIC
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
Lovely Professional University
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
Nahian Ahmed
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
kamal kotecha
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
Shubham Dwivedi
 

Viewers also liked (20)

Chap1 packages
Chap1 packagesChap1 packages
Chap1 packages
raksharao
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
Ganesh kumar reddy
 
Java packages oop
Java packages oopJava packages oop
Java packages oop
Kawsar Hamid Sumon
 
exception handling
exception handlingexception handling
exception handling
Manav Dharman
 
Java packages
Java packagesJava packages
Java packages
Shreyans Pathak
 
Java - Interfaces & Packages
Java - Interfaces & PackagesJava - Interfaces & Packages
Java - Interfaces & Packages
Arindam Ghosh
 
Java interface
Java interfaceJava interface
Java interface
Arati Gadgil
 
Java - Exception Handling
Java - Exception HandlingJava - Exception Handling
Java - Exception Handling
Prabhdeep Singh
 
Java package
Java packageJava package
Java package
CS_GDRCST
 
Java Exception Handling Best Practices - Improved Second Version
Java Exception Handling Best Practices - Improved Second VersionJava Exception Handling Best Practices - Improved Second Version
Java Exception Handling Best Practices - Improved Second Version
Lemi Orhan Ergin
 
5.interface and packages
5.interface and packages5.interface and packages
5.interface and packages
Deepak Sharma
 
java packages
java packagesjava packages
java packages
aptechsravan
 
Interface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar SinghInterface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar Singh
dheeraj_cse
 
Packages and inbuilt classes of java
Packages and inbuilt classes of javaPackages and inbuilt classes of java
Packages and inbuilt classes of java
kamal kotecha
 
Packages in java
Packages in javaPackages in java
Packages in java
Abhishek Khune
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
Prasad Sawant
 
Java packages
Java packagesJava packages
Java packages
BHUVIJAYAVELU
 
Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Java
parag
 
Java exception handling ppt
Java exception handling pptJava exception handling ppt
Java exception handling ppt
JavabynataraJ
 
Exception handling
Exception handlingException handling
Exception handling
Abhishek Pachisia
 
Chap1 packages
Chap1 packagesChap1 packages
Chap1 packages
raksharao
 
Java - Interfaces & Packages
Java - Interfaces & PackagesJava - Interfaces & Packages
Java - Interfaces & Packages
Arindam Ghosh
 
Java - Exception Handling
Java - Exception HandlingJava - Exception Handling
Java - Exception Handling
Prabhdeep Singh
 
Java package
Java packageJava package
Java package
CS_GDRCST
 
Java Exception Handling Best Practices - Improved Second Version
Java Exception Handling Best Practices - Improved Second VersionJava Exception Handling Best Practices - Improved Second Version
Java Exception Handling Best Practices - Improved Second Version
Lemi Orhan Ergin
 
5.interface and packages
5.interface and packages5.interface and packages
5.interface and packages
Deepak Sharma
 
Interface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar SinghInterface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar Singh
dheeraj_cse
 
Packages and inbuilt classes of java
Packages and inbuilt classes of javaPackages and inbuilt classes of java
Packages and inbuilt classes of java
kamal kotecha
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
Prasad Sawant
 
Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Java
parag
 
Java exception handling ppt
Java exception handling pptJava exception handling ppt
Java exception handling ppt
JavabynataraJ
 
Ad

Similar to Packages,interfaces and exceptions (20)

Z blue interfaces and packages (37129912)
Z blue   interfaces and  packages (37129912)Z blue   interfaces and  packages (37129912)
Z blue interfaces and packages (37129912)
Narayana Swamy
 
javapackage,try,cthrow,finallytch,-160518085421 (1).pptx
javapackage,try,cthrow,finallytch,-160518085421 (1).pptxjavapackage,try,cthrow,finallytch,-160518085421 (1).pptx
javapackage,try,cthrow,finallytch,-160518085421 (1).pptx
ArunPatrick2
 
java package java package in java packages
java package java package in java packagesjava package java package in java packages
java package java package in java packages
ArunPatrick2
 
java package in java.. in java packages.
java package in java.. in java packages.java package in java.. in java packages.
java package in java.. in java packages.
ArunPatrickK1
 
PACKAGE.PPT12345678912345949745654646455
PACKAGE.PPT12345678912345949745654646455PACKAGE.PPT12345678912345949745654646455
PACKAGE.PPT12345678912345949745654646455
meetjaju38
 
Unit 4 Java
Unit 4 JavaUnit 4 Java
Unit 4 Java
arnold 7490
 
Packages and interface
Packages and interfacePackages and interface
Packages and interface
KarthigaGunasekaran1
 
Unit4 java
Unit4 javaUnit4 java
Unit4 java
mrecedu
 
Package in Java
Package in JavaPackage in Java
Package in Java
lalithambiga kamaraj
 
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
PackagesPackages
Packages
MSharmilaDeviITDEPT
 
Unit 2 notes.pdf
Unit 2 notes.pdfUnit 2 notes.pdf
Unit 2 notes.pdf
GayathriRHICETCSESTA
 
Java packages
Java packagesJava packages
Java packages
Jeffrey Quevedo
 
Packages in java
Packages in javaPackages in java
Packages in java
SahithiReddyEtikala
 
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.ppt
packages.pptpackages.ppt
packages.ppt
SanthiNivas
 
Package.pptx
Package.pptxPackage.pptx
Package.pptx
VeenaNaik23
 
Java - Packages Concepts
Java - Packages ConceptsJava - Packages Concepts
Java - Packages Concepts
Victer Paul
 
packages in java & c++
packages in java & c++packages in java & c++
packages in java & c++
pankaj chelak
 
Packages and interfaces
Packages and interfacesPackages and interfaces
Packages and interfaces
bhuvaneshwariA5
 
Z blue interfaces and packages (37129912)
Z blue   interfaces and  packages (37129912)Z blue   interfaces and  packages (37129912)
Z blue interfaces and packages (37129912)
Narayana Swamy
 
javapackage,try,cthrow,finallytch,-160518085421 (1).pptx
javapackage,try,cthrow,finallytch,-160518085421 (1).pptxjavapackage,try,cthrow,finallytch,-160518085421 (1).pptx
javapackage,try,cthrow,finallytch,-160518085421 (1).pptx
ArunPatrick2
 
java package java package in java packages
java package java package in java packagesjava package java package in java packages
java package java package in java packages
ArunPatrick2
 
java package in java.. in java packages.
java package in java.. in java packages.java package in java.. in java packages.
java package in java.. in java packages.
ArunPatrickK1
 
PACKAGE.PPT12345678912345949745654646455
PACKAGE.PPT12345678912345949745654646455PACKAGE.PPT12345678912345949745654646455
PACKAGE.PPT12345678912345949745654646455
meetjaju38
 
Unit4 java
Unit4 javaUnit4 java
Unit4 java
mrecedu
 
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
 
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
 
Java - Packages Concepts
Java - Packages ConceptsJava - Packages Concepts
Java - Packages Concepts
Victer Paul
 
packages in java & c++
packages in java & c++packages in java & c++
packages in java & c++
pankaj chelak
 
Ad

More from Mavoori Soshmitha (6)

Ppt on java basics1
Ppt on java basics1Ppt on java basics1
Ppt on java basics1
Mavoori Soshmitha
 
Multi threading
Multi threadingMulti threading
Multi threading
Mavoori Soshmitha
 
Inheritance
InheritanceInheritance
Inheritance
Mavoori Soshmitha
 
main memory
main memorymain memory
main memory
Mavoori Soshmitha
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
Mavoori Soshmitha
 
Ppt on java basics
Ppt on java basicsPpt on java basics
Ppt on java basics
Mavoori Soshmitha
 

Recently uploaded (20)

Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
João Esperancinha
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Christian Folini
 
IT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information TechnologyIT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information Technology
SHEHABALYAMANI
 
Artificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptxArtificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptx
03ANMOLCHAURASIYA
 
fennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solutionfennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solution
shallal2
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
AI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamsonAI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamson
UXPA Boston
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
João Esperancinha
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Christian Folini
 
IT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information TechnologyIT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information Technology
SHEHABALYAMANI
 
Artificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptxArtificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptx
03ANMOLCHAURASIYA
 
fennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solutionfennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solution
shallal2
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
AI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamsonAI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamson
UXPA Boston
 

Packages,interfaces and exceptions

  • 1. JAVA concepts Packages and interfaces Exception handling
  • 2. Accessing classes from package Naming conventions API packages Creating packages Packages and interfaces Packages Packages are java’s way of grouping a variety of classes and interfaces together. Packages acts as “containers ” for classes. Benefits of using packages: Reused Hiding separating “design” from “coding”. Two classes in two different packages can have same name. packages
  • 3. Packages and interfaces Java API Packages Java API provides a large number of classes grouped into different packages according to functionality.
  • 4. Packages and interfaces Package name Contents java.lang Language support classes that java compiler itself uses and automatically imported . They include classes for primitive types , strings , math functions , threads and exceptions. java.util Language utility classes such as vectors , hash tables , random numbers , date , etc. java.io Input/output support classes that provide facilities for input and output of data. java.awt Set of classes for implementing GUI like windows , buttons , lists , menus , colors , etc. java.net Classes for networking for communication with local computer as well as with internet servers java.applet Classes for creating and implementing applets
  • 5. Packages and interfaces Using system Packages jav a Package Containing awt package Package Containing classes Classes Containing methods Hierarchical representation of java.awt package
  • 6. There are two ways of accessing the classes stored in the package. Java.awt.Color; import packagename.classname; (or) import packagename.*; First approach is perhaps easy and best way to access a class only once or when we need not have to access any other classes of the package. But, in many situations we want to use a class in number of places in program then we use second approach Packages and interfaces Accessing the classes stored in the package
  • 7. There are known as import statements and must appear at the top of the file , before any class declarations , import is a keyword. import Java.awt.Color; This statement allows specified class in specified package to be imported import java.awt.*; This statement imports every class contained in the specified package. Packages and interfaces Accessing the classes stored in the package
  • 8. Naming conventio ns Packages begin with lowercase . java.lang.Math.sqrt(x); Packages and interfaces Package name Class name Method name
  • 9. Packages and interfaces CLICK HERE FOR MORE INFO Creating packages We must first declare the name of the package using package keyword followed by package name. This must be the first statement in the source file except the comments and whitespaces followed by normal class definition. package firstPackage; //package declaration public class firstclass //class definition { …………. ………….. ………….. }
  • 10. Packages and interfaces CLICK HERE FOR MORE INFO Creating packages Remember that the .class files must be located in a directory that has the same name as the package and this directory should be a subdirectory where classes will import the package are located. Creating ore own packages involve the following steps: Declare the package at the beginning of the file using the form package packagename; Define the class that is to be put in the package and declare it public. Create the subdirectory under the directory where the main source files are stored. Store the listing as the class name java file in the subdirectory created. Compile the file . This creates .class file in the subdirectory
  • 11. Packages and interfaces Accessing a package import package1 [.package2] [.package3].classname;
  • 12. Packages and interfaces Adding a class to a package It is simple to add a class to an existing package. package p1; public class A { //body of A } if we want to add another class B to this package Define the class and make it public Place the package statements package p1; public class B{ //body of B } Store B.java file in p1 directory. Compile B.java file . This will create B.class file and place it in the directory p1. 0
  • 13. Implementing interface Naming conventions Extending interface Creating packages Packages and interfaces Why do we need Interfaces? For the use of multiple inheritance which is not supported by Java A java class cannot be a subclass of more than one super class , it can implement more than one interface , enabling us to create classes that build upon other classes without the problem created by multiple inheritance. Interface
  • 14. Packages and interfaces Defining interfaces An interface is basically a kind of class What is the difference between an interface and a class? Interface defines only abstract methods and fields. I .e. , the interface do not specify any code to implement these methods and data fields contain only constants Therefore it is the responsibility of the class that implements an interface to define the code for implementation of these methods.
  • 15. Packages and interfaces Syntax for interface interface interfacename { variables declaration; methods declaration; } Here interface is the keyword . Example : interface area { final static float pi=3.14f; Float compute(float x , float y) void show(); }
  • 16. Like classes , interfaces can also be extended by the key word extends Syntax : interface name2 extends name1{ //Body of name2} Example : interface ItemConstants { int code = 1001; String name=“fan”; } Interafce Item extends Item Constans { void display(); } Packages and interfaces Extending interfaces
  • 17. Impleme nting interfaces Interfaces are used as “ superclasses ” whose properties are inherited by classes. It is necessary to create a class that inherits the given interface. Syntax: class classname implements interfacename { //body of class } Here class implements the interface. implements is the keyword If a class that implements an interface does not implement all the methods of the interface then the class becomes an abstract class and cannot be instantiated Packages and interfaces
  • 18. Impleme nting interface with an example interface Area { final static float pi=3.14f; float compute (float x , float y ); } Class Rectangle implements Area { public float compute(float x, float y) { Return(x*y); } } class Circle implements Area { public float compute(float x, float y) { return(pi*x*x); } } class InterfaceTest Packages and interfaces
  • 20. Various Forms of interface implementation nterface mplementation class Extension class class class class Extension Extension interface interface implementation Extension
  • 21. Various Forms of interface implementation nterface implementation class class class Extension interface interface implementation
  • 22. Accessing interface variable Packages and interfaces Interfaces can be used to declare a set of constants that can be used in different classes This is similar to creating header files in C++ The constant class will be available to any class that implements the interface . The values can be used in any method. Ex : interface A{ int m=10; Int n=50;} Class B implements A { int x=m; void methodB ( int size { ……….. If (size<n) ………. )
  翻译: