SlideShare a Scribd company logo
1 of 2
Download to read offline
3/30/2019 Packages - access protection, importing packages: Your Guided Course Template
https://canvas.instructure.com/courses/1480238/pages/packages-access-protection-importing-packages?module_item_id=21012860 1/2
Packages - access protec on, impor ng
packages
Package
Package in Java is a mechanism to encapsulate a group of classes, sub packages and interfaces.
Packages are used for:
Java package is used to categorize the classes and interfaces so that they can be easily maintained.
Java package provides access protection.
Java package removes naming collision.
All related classes are put into packages. After that we can import a class from existing packages and use it in our
program. A packages is container of group of related classes where some of the classes are accessible are exposed
and others are kept for internal purpose.
We can reuse existing classes from the packages as many time as we need it in our program.
Adding a class to a Package : We can add more classes to an created package by using package name at the top of
the program and saving it in the package directory.
Subpackages: Packages that are inside another package are the subpackages. These are not imported by default,
they have to imported explicitly. Also, members of a subpackage have no access privileges, i.e., they are considered
as different package for protected and default access specifiers.
Types of packages:
Built-in Packages:
These packages consist of a large number of classes which are a part of Java API.Some of the commonly used built-
in packages are:
1) java.lang: Contains language support classes(e.g classed which defines primitive data types, math operations).
This package is automatically imported.
2) java.io: Contains classed for supporting input / output operations.
3) java.util: Contains utility classes which implement data structures like Linked List, Dictionary and support ; for
Date / Time operations.
4) java.applet: Contains classes for creating Applets.
5) java.awt: Contain classes for implementing the components for graphical user interfaces (like button , ;menus
etc).
6) java.net: Contain classes for supporting networking operations.
User-defined packages:
These are the packages that are defined by the user. First we create a directory myPackage (name should be same as
the name of the package). Then create the MyClass inside the directory with the first statement being the package
names.
The package keyword is used to create a package in java.
//save by A.java in 'pack' directory
package pack;
public class A
{
public void msg()
{
System.out.println("Hello");
}
}
There are three ways to access the package from outside the package.
3/30/2019 Packages - access protection, importing packages: Your Guided Course Template
https://canvas.instructure.com/courses/1480238/pages/packages-access-protection-importing-packages?module_item_id=21012860 2/2
1. import package.*;
2. import package.classname;
3. fully qualified name.
Using packagename.*
If you use package.* then all the classes and interfaces of this package will be accessible but not subpackages.
import pack.*;
class Demo
{
public static void main(String args[])
{
A obj = new A();
obj.msg();
}
}
Using packagename.classname
If you import package.classname then only declared class of this package will be accessible.
import pack.A;
class Demo
{
public static void main(String args[])
{
A obj = new A();
obj.msg();
}
}
Using fully qualified name
If you use fully qualified name then only declared class of this package will be accessible. Now there is no need to
import. But you need to use fully qualified name every time when you are accessing the class or interface.
It is generally used when two packages have same class name e.g. java.util and java.sql packages contain Date
class.
class Demo
{
public static void main(String args[])
{
A obj = new pack.A();
obj.msg();
}
}
Output:
Hello

More Related Content

What's hot

java interface and packages
java interface and packagesjava interface and packages
java interface and packagesVINOTH R
 
Java Thread Synchronization
Java Thread SynchronizationJava Thread Synchronization
Java Thread SynchronizationBenj Del Mundo
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPTPooja Jaiswal
 
backtracking algorithms of ada
backtracking algorithms of adabacktracking algorithms of ada
backtracking algorithms of adaSahil Kumar
 
Packages In Python Tutorial
Packages In Python TutorialPackages In Python Tutorial
Packages In Python TutorialSimplilearn
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handlingkamal kotecha
 
Security in distributed systems
Security in distributed systems Security in distributed systems
Security in distributed systems Haitham Ahmed
 
Unit 2 Java
Unit 2 JavaUnit 2 Java
Unit 2 Javaarnold 7490
 
Access specifiers(modifiers) in java
Access specifiers(modifiers) in javaAccess specifiers(modifiers) in java
Access specifiers(modifiers) in javaHrithikShinde
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)Ritika Sharma
 
Learn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarLearn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarAbir Mohammad
 
Object oriented approach in python programming
Object oriented approach in python programmingObject oriented approach in python programming
Object oriented approach in python programmingSrinivas Narasegouda
 
Threads And Synchronization in C#
Threads And Synchronization in C#Threads And Synchronization in C#
Threads And Synchronization in C#Rizwan Ali
 
Presentation on Core java
Presentation on Core javaPresentation on Core java
Presentation on Core javamahir jain
 
Share preference
Share preferenceShare preference
Share preferenceSbahatNosheen
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaCPD INDIA
 

What's hot (20)

java interface and packages
java interface and packagesjava interface and packages
java interface and packages
 
Java program structure
Java program structure Java program structure
Java program structure
 
Introduction to package in java
Introduction to package in javaIntroduction to package in java
Introduction to package in java
 
Java Thread Synchronization
Java Thread SynchronizationJava Thread Synchronization
Java Thread Synchronization
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
backtracking algorithms of ada
backtracking algorithms of adabacktracking algorithms of ada
backtracking algorithms of ada
 
Packages In Python Tutorial
Packages In Python TutorialPackages In Python Tutorial
Packages In Python Tutorial
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Java
JavaJava
Java
 
Security in distributed systems
Security in distributed systems Security in distributed systems
Security in distributed systems
 
Unit 2 Java
Unit 2 JavaUnit 2 Java
Unit 2 Java
 
Access specifiers(modifiers) in java
Access specifiers(modifiers) in javaAccess specifiers(modifiers) in java
Access specifiers(modifiers) in java
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
 
Learn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarLearn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat Shahriyar
 
Object oriented approach in python programming
Object oriented approach in python programmingObject oriented approach in python programming
Object oriented approach in python programming
 
Threads And Synchronization in C#
Threads And Synchronization in C#Threads And Synchronization in C#
Threads And Synchronization in C#
 
Presentation on Core java
Presentation on Core javaPresentation on Core java
Presentation on Core java
 
Share preference
Share preferenceShare preference
Share preference
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Packages
PackagesPackages
Packages
 

Similar to Packages access protection, importing packages

Java - Packages Concepts
Java - Packages ConceptsJava - Packages Concepts
Java - Packages ConceptsVicter Paul
 
Java package
Java packageJava package
Java packageCS_GDRCST
 
Packages in java
Packages in javaPackages in java
Packages in javajamunaashok
 
Packages in java
Packages in javaPackages in java
Packages in javaJancypriya M
 
packages.ppt
packages.pptpackages.ppt
packages.pptSanthiNivas
 
Unit4 java
Unit4 javaUnit4 java
Unit4 javamrecedu
 
packages unit 5 .ppt
packages  unit 5 .pptpackages  unit 5 .ppt
packages unit 5 .pptthenmozhip8
 
packages in java & c++
packages in java & c++packages in java & c++
packages in java & c++pankaj chelak
 
Class notes(week 7) on packages
Class notes(week 7) on packagesClass notes(week 7) on packages
Class notes(week 7) on packagesKuntal Bhowmick
 
Lecture 19
Lecture 19Lecture 19
Lecture 19talha ijaz
 
Package.pptx
Package.pptxPackage.pptx
Package.pptxVeenaNaik23
 
Java packags
Java packagsJava packags
Java packagsPadma Kannan
 
Class notes(week 7) on packages
Class notes(week 7) on packagesClass notes(week 7) on packages
Class notes(week 7) on packagesKuntal Bhowmick
 
OOP_packages_222902019.pptx
OOP_packages_222902019.pptxOOP_packages_222902019.pptx
OOP_packages_222902019.pptx222902019
 

Similar to Packages access protection, importing packages (20)

Java - Packages Concepts
Java - Packages ConceptsJava - Packages Concepts
Java - Packages Concepts
 
Java package
Java packageJava package
Java package
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Java packages oop
Java packages oopJava packages oop
Java packages oop
 
packages.ppt
packages.pptpackages.ppt
packages.ppt
 
Unit4 java
Unit4 javaUnit4 java
Unit4 java
 
packages.ppt
packages.pptpackages.ppt
packages.ppt
 
packages.ppt
packages.pptpackages.ppt
packages.ppt
 
packages unit 5 .ppt
packages  unit 5 .pptpackages  unit 5 .ppt
packages unit 5 .ppt
 
packages in java & c++
packages in java & c++packages in java & c++
packages in java & c++
 
Unit 2 notes.pdf
Unit 2 notes.pdfUnit 2 notes.pdf
Unit 2 notes.pdf
 
Class notes(week 7) on packages
Class notes(week 7) on packagesClass notes(week 7) on packages
Class notes(week 7) on packages
 
Lecture 19
Lecture 19Lecture 19
Lecture 19
 
Package.pptx
Package.pptxPackage.pptx
Package.pptx
 
Java packags
Java packagsJava packags
Java packags
 
Class notes(week 7) on packages
Class notes(week 7) on packagesClass notes(week 7) on packages
Class notes(week 7) on packages
 
Practice Program-9-Packages-Unit 4.docx
Practice Program-9-Packages-Unit 4.docxPractice Program-9-Packages-Unit 4.docx
Practice Program-9-Packages-Unit 4.docx
 
OOP_packages_222902019.pptx
OOP_packages_222902019.pptxOOP_packages_222902019.pptx
OOP_packages_222902019.pptx
 

More from TharuniDiddekunta

Exception handling basic
Exception handling basicException handling basic
Exception handling basicTharuniDiddekunta
 
Creating your own exception
Creating your own exceptionCreating your own exception
Creating your own exceptionTharuniDiddekunta
 
Inheritance used in java
Inheritance used in javaInheritance used in java
Inheritance used in javaTharuniDiddekunta
 
Operators, control statements represented in java
Operators, control statements  represented in javaOperators, control statements  represented in java
Operators, control statements represented in javaTharuniDiddekunta
 
Classes, objects, methods, constructors, this keyword in java
Classes, objects, methods, constructors, this keyword  in javaClasses, objects, methods, constructors, this keyword  in java
Classes, objects, methods, constructors, this keyword in javaTharuniDiddekunta
 
Software Metrics (Testing)
Software Metrics (Testing)Software Metrics (Testing)
Software Metrics (Testing)TharuniDiddekunta
 
risk managment and quality
risk managment and qualityrisk managment and quality
risk managment and qualityTharuniDiddekunta
 
Transport layer and Application layer
Transport layer and Application layerTransport layer and Application layer
Transport layer and Application layerTharuniDiddekunta
 
Congection control and Internet working
Congection control and Internet workingCongection control and Internet working
Congection control and Internet workingTharuniDiddekunta
 

More from TharuniDiddekunta (17)

String class
String classString class
String class
 
Exception handling basic
Exception handling basicException handling basic
Exception handling basic
 
Creating your own exception
Creating your own exceptionCreating your own exception
Creating your own exception
 
Built in exceptions
Built in exceptions Built in exceptions
Built in exceptions
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
Inheritance used in java
Inheritance used in javaInheritance used in java
Inheritance used in java
 
Operators, control statements represented in java
Operators, control statements  represented in javaOperators, control statements  represented in java
Operators, control statements represented in java
 
Classes, objects, methods, constructors, this keyword in java
Classes, objects, methods, constructors, this keyword  in javaClasses, objects, methods, constructors, this keyword  in java
Classes, objects, methods, constructors, this keyword in java
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
Software Metrics (Testing)
Software Metrics (Testing)Software Metrics (Testing)
Software Metrics (Testing)
 
unit 3 Design 1
unit 3 Design 1unit 3 Design 1
unit 3 Design 1
 
Unit 4 testing
Unit 4 testingUnit 4 testing
Unit 4 testing
 
risk managment and quality
risk managment and qualityrisk managment and quality
risk managment and quality
 
Design
DesignDesign
Design
 
Network layer
Network layerNetwork layer
Network layer
 
Transport layer and Application layer
Transport layer and Application layerTransport layer and Application layer
Transport layer and Application layer
 
Congection control and Internet working
Congection control and Internet workingCongection control and Internet working
Congection control and Internet working
 

Recently uploaded

VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixingviprabot1
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 

Recently uploaded (20)

VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixing
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 

Packages access protection, importing packages

  • 1. 3/30/2019 Packages - access protection, importing packages: Your Guided Course Template https://canvas.instructure.com/courses/1480238/pages/packages-access-protection-importing-packages?module_item_id=21012860 1/2 Packages - access protec on, impor ng packages Package Package in Java is a mechanism to encapsulate a group of classes, sub packages and interfaces. Packages are used for: Java package is used to categorize the classes and interfaces so that they can be easily maintained. Java package provides access protection. Java package removes naming collision. All related classes are put into packages. After that we can import a class from existing packages and use it in our program. A packages is container of group of related classes where some of the classes are accessible are exposed and others are kept for internal purpose. We can reuse existing classes from the packages as many time as we need it in our program. Adding a class to a Package : We can add more classes to an created package by using package name at the top of the program and saving it in the package directory. Subpackages: Packages that are inside another package are the subpackages. These are not imported by default, they have to imported explicitly. Also, members of a subpackage have no access privileges, i.e., they are considered as different package for protected and default access specifiers. Types of packages: Built-in Packages: These packages consist of a large number of classes which are a part of Java API.Some of the commonly used built- in packages are: 1) java.lang: Contains language support classes(e.g classed which defines primitive data types, math operations). This package is automatically imported. 2) java.io: Contains classed for supporting input / output operations. 3) java.util: Contains utility classes which implement data structures like Linked List, Dictionary and support ; for Date / Time operations. 4) java.applet: Contains classes for creating Applets. 5) java.awt: Contain classes for implementing the components for graphical user interfaces (like button , ;menus etc). 6) java.net: Contain classes for supporting networking operations. User-defined packages: These are the packages that are defined by the user. First we create a directory myPackage (name should be same as the name of the package). Then create the MyClass inside the directory with the first statement being the package names. The package keyword is used to create a package in java. //save by A.java in 'pack' directory package pack; public class A { public void msg() { System.out.println("Hello"); } } There are three ways to access the package from outside the package.
  • 2. 3/30/2019 Packages - access protection, importing packages: Your Guided Course Template https://canvas.instructure.com/courses/1480238/pages/packages-access-protection-importing-packages?module_item_id=21012860 2/2 1. import package.*; 2. import package.classname; 3. fully qualified name. Using packagename.* If you use package.* then all the classes and interfaces of this package will be accessible but not subpackages. import pack.*; class Demo { public static void main(String args[]) { A obj = new A(); obj.msg(); } } Using packagename.classname If you import package.classname then only declared class of this package will be accessible. import pack.A; class Demo { public static void main(String args[]) { A obj = new A(); obj.msg(); } } Using fully qualified name If you use fully qualified name then only declared class of this package will be accessible. Now there is no need to import. But you need to use fully qualified name every time when you are accessing the class or interface. It is generally used when two packages have same class name e.g. java.util and java.sql packages contain Date class. class Demo { public static void main(String args[]) { A obj = new pack.A(); obj.msg(); } } Output: Hello