This presentation introduces Java packages, including system packages that are part of the Java API and user-defined packages. It discusses how packages organize related classes and interfaces, the structure of package names and directories, and how to create and access packages. Packages provide advantages like grouping related code, preventing name collisions, and improving reusability.
This document discusses packages in Java. It defines packages as containers for grouping related classes and interfaces. There are built-in packages provided by Java, such as java.lang for core classes and java.util for utility classes. Users can also create their own packages by specifying the package name at the top of a file and storing the class files in a subdirectory matching the package name. Packages provide advantages like organizing related classes, hiding classes to prevent accidental deletion, and allowing class name reuse across packages.
This document presents information about Java packages. It introduces the topic of packages and discusses how to create, use, import and access packages and package members. The document provides examples to illustrate key concepts such as defining a package, matching package names to directory structures, importing packages and accessing classes from other packages. It also outlines some benefits of using packages such as avoiding name conflicts and restricting access. The presentation was delivered by group members with IDs ranging from 131-15-2223 to 131-15-2421.
This document discusses packages and interfaces in Java. It defines a package as a container for classes that organizes the class namespace. Packages can be built-in or user-defined. Interfaces define method signatures but do not provide implementations. Classes can implement interfaces. The key differences between classes and interfaces are that interfaces contain only abstract methods while classes can contain concrete methods, and multiple inheritance is only possible with interfaces.
This document discusses Java packages. It explains that packages allow for organizing classes into namespaces to achieve code reuse and prevent naming collisions. Packages act as containers that group related classes and interfaces. The document also provides details on using packages from the Java API, package access protection, creating JAR files, package naming conventions, and common mistakes when working with packages.
java notes, object oriented programming using java, java tutorial, lecture notes, java programming notes, java example programs, java programs with explanation, java source code with output, java programs, java coding, java codes, java slides, java notes,packages in java, java packages notes, java packages notes,different types of packages in Java,packages with an example, packages in Java
The document discusses Java packages. The key points are:
- Packages are containers that group related classes and interfaces together. They allow for organizing code and uniquely naming classes.
- The core Java packages are java.lang, java.util, java.io, java.awt, java.net, and java.applet. They contain fundamental classes for various purposes.
- To use classes from a package, the package must be imported or the fully qualified class name can be used. The package statement declares user-defined packages.
This document discusses Java packages. It defines packages as groups of related classes and interfaces, and notes there are two types: system packages from the Java API and user-defined packages. It explains how to create a user-defined package by declaring the package name at the top of a file, making classes within it public, compiling the file, and importing the package. An example is provided to demonstrate creating a package with two classes and using them in a main method after importing the package.
Packages in Java allow grouping of related classes and interfaces to avoid naming collisions. Some key points about packages include:
- Packages allow for code reusability and easy location of files. The Java API uses packages to organize core classes.
- Custom packages can be created by specifying the package name at the beginning of a Java file. The class files are then compiled to the corresponding directory structure.
- The import statement and fully qualified names can be used to access classes from other packages. The classpath variable specifies locations of package directories and classes.
This document discusses packages in Java. It defines a package as a mechanism to encapsulate a group of classes, subpackages, and interfaces. Packages are used to prevent naming conflicts, make classes and interfaces easier to locate and use, and provide access control. Package names are related to directory structure, and packages can be considered a form of data encapsulation. The document also discusses built-in packages that are part of the Java API, as well as how to define and use user-defined packages through directory structure and import statements.
This document discusses packages in Java. It defines a package as a mechanism to encapsulate a group of classes, subpackages, and interfaces. Packages are used to prevent naming conflicts, make classes and interfaces easier to locate and use, and provide access control. Package names are related to directory structure, and packages can be considered a form of data encapsulation. The document also discusses built-in packages that are part of the Java API, as well as how to define and use user-defined packages through directory structure and import statements.
Packages in Java allow grouping of related classes and avoid naming collisions. A package is mapped to a directory on the file system where Java files for that package are stored. There are predefined packages provided by Java and user-defined packages can also be created. Packages are specified using the package keyword and imported into other classes using import statements. The classpath variable is used to locate packages and classes for compilation and execution.
Packages and interfaces are two of Java's most innovative features. Packages are used to group related classes and avoid naming conflicts by providing a mechanism to partition the class namespace into more manageable chunks. Packages also provide access control, with protected and default members having package-level access. To define a package, the package statement is included at the top of a Java file specifying the package name. Import statements are used to make classes in other packages visible. Packages can be built-in, from the Java API, or user-defined.
Packages in Java help organize code by providing a layer of encapsulation and control. Packages group related classes and interfaces together, and allow classes to be made private to a package. To define a package, use the package statement at the top of a file with the package name. Multiple files can belong to the same package. Packages are hierarchical, with names separated by periods. Directories mirror package hierarchies.
java notes, object oriented programming using java, java tutorial, lecture notes, java programming notes, java example programs, java programs with explanation, java source code with output, java programs, java coding, java codes, java slides, java notes,packages in java, java packages notes, java packages notes,different types of packages in Java,packages with an example, packages in Java
Packages in Java are used to categorize classes and interfaces to facilitate organization and access protection. There are two types of packages - built-in packages that are part of the Java API, and user-defined packages that are created by the user. Classes can be imported into other packages using either "import package.*" to access all classes, "import package.classname" to access a specific class, or the fully qualified name. This allows code reuse through organizing related classes and controlling access.
Packages in Java allow classes to be grouped together and reused. Packages provide a way to uniquely name classes and hide classes from other packages. The Java API contains many pre-defined packages that are organized hierarchically, such as java.awt for graphical user interface classes. Classes in a package can be accessed using either fully qualified names or import statements. User-defined packages follow similar conventions as the Java API packages.
This document discusses Java packages and interfaces. It covers topics like:
- Packages are used to group related classes and interfaces and provide benefits like reuse and separation of design from code.
- Well-known Java API packages include java.lang, java.util, java.io, java.awt, and java.net.
- There are two ways to access classes from packages: using fully qualified names or import statements.
- Interfaces are used for multiple inheritance in Java and define abstract methods that implementing classes must define. Interfaces can extend other interfaces.
Packages in Java are used to organize classes and provide namespace management to avoid naming conflicts. A package groups related types like classes, interfaces, enums and annotations. Programmers can define their own packages to organize related classes. Packages create a new namespace to avoid conflicts and make classes easier to locate and access. The package name is specified in a source file using the package keyword and files for a package must be stored in a subdirectory matching the package name. Classes in other packages can be accessed using their fully qualified names or by importing the package.
Packages in Java allow classes to be grouped together logically and prevent naming collisions. The key Java packages are:
1) java.lang contains classes for primitive types, strings, math functions, and exceptions.
2) java.util contains utility classes like vectors and hash tables.
3) java.io contains stream classes for input/output.
Packages are organized hierarchically, for example the awt package contains classes for graphical user interfaces. Classes in packages can be accessed using their fully qualified name or by importing the package. Users can also create their own packages by specifying the package name at the top of Java files in a corresponding directory structure.
This document provides notes on packages, interfaces, and exception handling in Java. It discusses defining and accessing packages, defining and implementing interfaces, variables in interfaces and extended interfaces. It also covers exception types in Java like Try, Catch, Throw, Throws and Finally blocks, and the differences between exception and error types. Multiple examples are provided to illustrate packages, interfaces and exception handling concepts in Java.
Packages in Java prevent naming conflicts, control access to classes, and make classes easier to locate and use. A package is a grouping of related classes and interfaces that provides namespace management and access protection. Common Java packages include java.lang for core classes and java.io for input/output classes. Programmers can define their own packages to organize related classes. The package name becomes part of the class name and the package directory structure must match the class file locations.
The document discusses object oriented programming concepts related to packages, interfaces, and their implementation in Java. It defines what packages and interfaces are, how to create and access packages, differences between classes and interfaces, how to define and implement interfaces, and examples of applying packages and interfaces in Java code.
A package in Java is a grouping of related classes and interfaces that provides namespacing to avoid naming conflicts. There are two types of packages: predefined packages provided by Java and user-defined packages. Packages provide advantages like reusability and better organization. Some key predefined packages include java.lang, java.io, java.util, java.applet, and java.awt. To define a user package, include the package statement as the first line in a Java source file, which specifies the package name. Classes in that file will belong to that package.
The document discusses Java packages. The key points are:
- Packages are containers that group related classes and interfaces together. They allow for organizing code and uniquely naming classes.
- The core Java packages are java.lang, java.util, java.io, java.awt, java.net, and java.applet. They contain fundamental classes for various purposes.
- To use classes from a package, the package must be imported or the fully qualified class name can be used. The package statement declares user-defined packages.
This document discusses Java packages. It defines packages as groups of related classes and interfaces, and notes there are two types: system packages from the Java API and user-defined packages. It explains how to create a user-defined package by declaring the package name at the top of a file, making classes within it public, compiling the file, and importing the package. An example is provided to demonstrate creating a package with two classes and using them in a main method after importing the package.
Packages in Java allow grouping of related classes and interfaces to avoid naming collisions. Some key points about packages include:
- Packages allow for code reusability and easy location of files. The Java API uses packages to organize core classes.
- Custom packages can be created by specifying the package name at the beginning of a Java file. The class files are then compiled to the corresponding directory structure.
- The import statement and fully qualified names can be used to access classes from other packages. The classpath variable specifies locations of package directories and classes.
This document discusses packages in Java. It defines a package as a mechanism to encapsulate a group of classes, subpackages, and interfaces. Packages are used to prevent naming conflicts, make classes and interfaces easier to locate and use, and provide access control. Package names are related to directory structure, and packages can be considered a form of data encapsulation. The document also discusses built-in packages that are part of the Java API, as well as how to define and use user-defined packages through directory structure and import statements.
This document discusses packages in Java. It defines a package as a mechanism to encapsulate a group of classes, subpackages, and interfaces. Packages are used to prevent naming conflicts, make classes and interfaces easier to locate and use, and provide access control. Package names are related to directory structure, and packages can be considered a form of data encapsulation. The document also discusses built-in packages that are part of the Java API, as well as how to define and use user-defined packages through directory structure and import statements.
Packages in Java allow grouping of related classes and avoid naming collisions. A package is mapped to a directory on the file system where Java files for that package are stored. There are predefined packages provided by Java and user-defined packages can also be created. Packages are specified using the package keyword and imported into other classes using import statements. The classpath variable is used to locate packages and classes for compilation and execution.
Packages and interfaces are two of Java's most innovative features. Packages are used to group related classes and avoid naming conflicts by providing a mechanism to partition the class namespace into more manageable chunks. Packages also provide access control, with protected and default members having package-level access. To define a package, the package statement is included at the top of a Java file specifying the package name. Import statements are used to make classes in other packages visible. Packages can be built-in, from the Java API, or user-defined.
Packages in Java help organize code by providing a layer of encapsulation and control. Packages group related classes and interfaces together, and allow classes to be made private to a package. To define a package, use the package statement at the top of a file with the package name. Multiple files can belong to the same package. Packages are hierarchical, with names separated by periods. Directories mirror package hierarchies.
java notes, object oriented programming using java, java tutorial, lecture notes, java programming notes, java example programs, java programs with explanation, java source code with output, java programs, java coding, java codes, java slides, java notes,packages in java, java packages notes, java packages notes,different types of packages in Java,packages with an example, packages in Java
Packages in Java are used to categorize classes and interfaces to facilitate organization and access protection. There are two types of packages - built-in packages that are part of the Java API, and user-defined packages that are created by the user. Classes can be imported into other packages using either "import package.*" to access all classes, "import package.classname" to access a specific class, or the fully qualified name. This allows code reuse through organizing related classes and controlling access.
Packages in Java allow classes to be grouped together and reused. Packages provide a way to uniquely name classes and hide classes from other packages. The Java API contains many pre-defined packages that are organized hierarchically, such as java.awt for graphical user interface classes. Classes in a package can be accessed using either fully qualified names or import statements. User-defined packages follow similar conventions as the Java API packages.
This document discusses Java packages and interfaces. It covers topics like:
- Packages are used to group related classes and interfaces and provide benefits like reuse and separation of design from code.
- Well-known Java API packages include java.lang, java.util, java.io, java.awt, and java.net.
- There are two ways to access classes from packages: using fully qualified names or import statements.
- Interfaces are used for multiple inheritance in Java and define abstract methods that implementing classes must define. Interfaces can extend other interfaces.
Packages in Java are used to organize classes and provide namespace management to avoid naming conflicts. A package groups related types like classes, interfaces, enums and annotations. Programmers can define their own packages to organize related classes. Packages create a new namespace to avoid conflicts and make classes easier to locate and access. The package name is specified in a source file using the package keyword and files for a package must be stored in a subdirectory matching the package name. Classes in other packages can be accessed using their fully qualified names or by importing the package.
Packages in Java allow classes to be grouped together logically and prevent naming collisions. The key Java packages are:
1) java.lang contains classes for primitive types, strings, math functions, and exceptions.
2) java.util contains utility classes like vectors and hash tables.
3) java.io contains stream classes for input/output.
Packages are organized hierarchically, for example the awt package contains classes for graphical user interfaces. Classes in packages can be accessed using their fully qualified name or by importing the package. Users can also create their own packages by specifying the package name at the top of Java files in a corresponding directory structure.
This document provides notes on packages, interfaces, and exception handling in Java. It discusses defining and accessing packages, defining and implementing interfaces, variables in interfaces and extended interfaces. It also covers exception types in Java like Try, Catch, Throw, Throws and Finally blocks, and the differences between exception and error types. Multiple examples are provided to illustrate packages, interfaces and exception handling concepts in Java.
Packages in Java prevent naming conflicts, control access to classes, and make classes easier to locate and use. A package is a grouping of related classes and interfaces that provides namespace management and access protection. Common Java packages include java.lang for core classes and java.io for input/output classes. Programmers can define their own packages to organize related classes. The package name becomes part of the class name and the package directory structure must match the class file locations.
The document discusses object oriented programming concepts related to packages, interfaces, and their implementation in Java. It defines what packages and interfaces are, how to create and access packages, differences between classes and interfaces, how to define and implement interfaces, and examples of applying packages and interfaces in Java code.
A package in Java is a grouping of related classes and interfaces that provides namespacing to avoid naming conflicts. There are two types of packages: predefined packages provided by Java and user-defined packages. Packages provide advantages like reusability and better organization. Some key predefined packages include java.lang, java.io, java.util, java.applet, and java.awt. To define a user package, include the package statement as the first line in a Java source file, which specifies the package name. Classes in that file will belong to that package.
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetSritoma Majumder
Introduction
All the materials around us are made up of elements. These elements can be broadly divided into two major groups:
Metals
Non-Metals
Each group has its own unique physical and chemical properties. Let's understand them one by one.
Physical Properties
1. Appearance
Metals: Shiny (lustrous). Example: gold, silver, copper.
Non-metals: Dull appearance (except iodine, which is shiny).
2. Hardness
Metals: Generally hard. Example: iron.
Non-metals: Usually soft (except diamond, a form of carbon, which is very hard).
3. State
Metals: Mostly solids at room temperature (except mercury, which is a liquid).
Non-metals: Can be solids, liquids, or gases. Example: oxygen (gas), bromine (liquid), sulphur (solid).
4. Malleability
Metals: Can be hammered into thin sheets (malleable).
Non-metals: Not malleable. They break when hammered (brittle).
5. Ductility
Metals: Can be drawn into wires (ductile).
Non-metals: Not ductile.
6. Conductivity
Metals: Good conductors of heat and electricity.
Non-metals: Poor conductors (except graphite, which is a good conductor).
7. Sonorous Nature
Metals: Produce a ringing sound when struck.
Non-metals: Do not produce sound.
Chemical Properties
1. Reaction with Oxygen
Metals react with oxygen to form metal oxides.
These metal oxides are usually basic.
Non-metals react with oxygen to form non-metallic oxides.
These oxides are usually acidic.
2. Reaction with Water
Metals:
Some react vigorously (e.g., sodium).
Some react slowly (e.g., iron).
Some do not react at all (e.g., gold, silver).
Non-metals: Generally do not react with water.
3. Reaction with Acids
Metals react with acids to produce salt and hydrogen gas.
Non-metals: Do not react with acids.
4. Reaction with Bases
Some non-metals react with bases to form salts, but this is rare.
Metals generally do not react with bases directly (except amphoteric metals like aluminum and zinc).
Displacement Reaction
More reactive metals can displace less reactive metals from their salt solutions.
Uses of Metals
Iron: Making machines, tools, and buildings.
Aluminum: Used in aircraft, utensils.
Copper: Electrical wires.
Gold and Silver: Jewelry.
Zinc: Coating iron to prevent rusting (galvanization).
Uses of Non-Metals
Oxygen: Breathing.
Nitrogen: Fertilizers.
Chlorine: Water purification.
Carbon: Fuel (coal), steel-making (coke).
Iodine: Medicines.
Alloys
An alloy is a mixture of metals or a metal with a non-metal.
Alloys have improved properties like strength, resistance to rusting.
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...larencebapu132
This is short and accurate description of World war-1 (1914-18)
It can give you the perfect factual conceptual clarity on the great war
Regards Simanchala Sarab
Student of BABed(ITEP, Secondary stage)in History at Guru Nanak Dev University Amritsar Punjab 🙏🙏
How to Set warnings for invoicing specific customers in odooCeline George
Odoo 16 offers a powerful platform for managing sales documents and invoicing efficiently. One of its standout features is the ability to set warnings and block messages for specific customers during the invoicing process.
INTRO TO STATISTICS
INTRO TO SPSS INTERFACE
CLEANING MULTIPLE CHOICE RESPONSE DATA WITH EXCEL
ANALYZING MULTIPLE CHOICE RESPONSE DATA
INTERPRETATION
Q & A SESSION
PRACTICAL HANDS-ON ACTIVITY
This chapter provides an in-depth overview of the viscosity of macromolecules, an essential concept in biophysics and medical sciences, especially in understanding fluid behavior like blood flow in the human body.
Key concepts covered include:
✅ Definition and Types of Viscosity: Dynamic vs. Kinematic viscosity, cohesion, and adhesion.
⚙️ Methods of Measuring Viscosity:
Rotary Viscometer
Vibrational Viscometer
Falling Object Method
Capillary Viscometer
🌡️ Factors Affecting Viscosity: Temperature, composition, flow rate.
🩺 Clinical Relevance: Impact of blood viscosity in cardiovascular health.
🌊 Fluid Dynamics: Laminar vs. turbulent flow, Reynolds number.
🔬 Extension Techniques:
Chromatography (adsorption, partition, TLC, etc.)
Electrophoresis (protein/DNA separation)
Sedimentation and Centrifugation methods.
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessMark Soia
Boost your chances of passing the 2V0-11.25 exam with CertsExpert reliable exam dumps. Prepare effectively and ace the VMware certification on your first try
Quality dumps. Trusted results. — Visit CertsExpert Now: https://www.certsexpert.com/2V0-11.25-pdf-questions.html
Title: A Quick and Illustrated Guide to APA Style Referencing (7th Edition)
This visual and beginner-friendly guide simplifies the APA referencing style (7th edition) for academic writing. Designed especially for commerce students and research beginners, it includes:
✅ Real examples from original research papers
✅ Color-coded diagrams for clarity
✅ Key rules for in-text citation and reference list formatting
✅ Free citation tools like Mendeley & Zotero explained
Whether you're writing a college assignment, dissertation, or academic article, this guide will help you cite your sources correctly, confidently, and consistent.
Created by: Prof. Ishika Ghosh,
Faculty.
📩 For queries or feedback: [email protected]
The Pala kings were people-protectors. In fact, Gopal was elected to the throne only to end Matsya Nyaya. Bhagalpur Abhiledh states that Dharmapala imposed only fair taxes on the people. Rampala abolished the unjust taxes imposed by Bhima. The Pala rulers were lovers of learning. Vikramshila University was established by Dharmapala. He opened 50 other learning centers. A famous Buddhist scholar named Haribhadra was to be present in his court. Devpala appointed another Buddhist scholar named Veerdeva as the vice president of Nalanda Vihar. Among other scholars of this period, Sandhyakar Nandi, Chakrapani Dutta and Vajradatta are especially famous. Sandhyakar Nandi wrote the famous poem of this period 'Ramcharit'.
Odoo Inventory Rules and Routes v17 - Odoo SlidesCeline George
Odoo's inventory management system is highly flexible and powerful, allowing businesses to efficiently manage their stock operations through the use of Rules and Routes.
As of Mid to April Ending, I am building a new Reiki-Yoga Series. No worries, they are free workshops. So far, I have 3 presentations so its a gradual process. If interested visit: https://www.slideshare.net/YogaPrincess
https://ldmchapels.weebly.com
Blessings and Happy Spring. We are hitting Mid Season.
How to Subscribe Newsletter From Odoo 18 WebsiteCeline George
Newsletter is a powerful tool that effectively manage the email marketing . It allows us to send professional looking HTML formatted emails. Under the Mailing Lists in Email Marketing we can find all the Newsletter.
2. CONTENTS
Introduction
Types Of Packages
Pre-Defined Packages or Built in Packages
Pre-Defined Packages & Their Classes
User Defined Packages.
Creating User Defined Packages
Steps For Creating Package
Accessing a Package
o Advantages Of Packages
3. INTRODUCTION
In java, programmers can create several classes &
Interface. After creating these classes and
interface, it is better if they are divided into some
groups depending on their relationship. Thus, the
classes and interface which handle similar or same
task are put into the same directory or folder,
which is also known as package.
Packages act as “containers” for classes. A package
represents a directory that contain related group of
classes & interface.
4. TYPES OF PACKAGES
There are basically only 2 types of java packages.
They are as follow :
System Packages or Java API
User Defined Packages.
6. Pre-Defined Packages or Built in Packages
As there are built in methods , java also provides
inbuilt packages which contain lots of classes &
interfaces. These classes inside the packages are
already defined & we can use them by importing
relevant package in our program.
Java has an extensive library of packages, a
programmer need not think about logic for doing
any task. For everything, there are the methods
available in java and that method can be used by
the programmer without developing the logic on
his own. This makes the programming easy.
7. JAVA SYSTEM PACKAGES & THEIR CLASSES
java.lang
Language Support classes. These are classes that java compiler itself
uses & therefore they are automatically imported. They include classes
for primitive types, strings, maths function, threads &exception.
java .util
Language Utility classes such as vector, hash tables ,random
numbers, date etc.
java.io
Input /Output support classes. They provide facilities for the input &
output of data
java.awt
Set of classes for implementing graphical user interface. They include
classes for windows, buttons, list, menus & so on.
java.net
Classes for networking. They include classes for communicating with
local computers as well as with internet servers.
java.applet
Classes for creating & implementing applets.
8. 2. USER DEFINED PACKAGES :
The users of the Java language can also create their own packages. They
are called user-defined packages. User defined packages can also be
imported into other classes & used exactly in the same way as the Built in
packages.
i) Creating User Defined Packages
Syntax :
package packageName;
public class className
{
- - - - - - - - - - - - -
// Body of className
- - - - - - - - - - - -
}
We must first declare the name of the package using the package
keyword followed by the package name. This must be the first statement
in a Java source file. Then define a classes as normally as define a class.
9. Example :
package myPackage;
public class class1
{
- - - - - - - - - - - - -
// Body of class1
}
In the above example, myPackage is the name of the package. The class
class1 is now considered as a part of this package.
This listing would be saved as a file called class1.java & located in a
directory named mypackage. When the source file is compiled, java will
create a .class file & store it in the same directory.
The .class files must be located in a directory that has the same name as
the package & this directory should be a subdirectory of the directory
where classes that will import the package are located.
10. STEPS FOR CREATING PACKAGE :
To create a user defined package the following steps should
be involved :-
1: Declare the package at the beginning of a file using
the syntax :-
package packageName;
2: Define the class that is to be put in the package &
declare it public.
3: Create a subdirectory under the directory where the
main source files are stored.
4: Store the listing as the classname.java file in the
subdirectory created.
5: Compile the file. This create .class file in the
subdirectory.
11. Java also supports the concept of package hierarchy.
This is done by specifying multiple names in a package
statement, seprated by dots (.).
Ex :- package firstPackage.secondPackage;
This approach allows us to group related classes into a
package and their group related package into a larger
package. Store this package in a subdirectory named
firstpackage/secondPackage.
A java package file can have more than one class
definition. In such cases, only one of the classes may be
declared public & that class name with .java extension
is the source file name. When a source file with more
than one class definition is compiled, java creates
independent .class files for those classes.
12. ACCESSING A PACKAGE
Java package can be accessed either using a fully qualified class
name or using a shortcut approach through the import statement.
Syntax :
import package1[.package2][.package3].classname;
Here, package1 is the name of the top level package, package2 is
the name of the package that is inside the package & so on. We
can have any number of packages in a package hierarchy. Finally
the explicit classname is specified. The import statement must
end with a semicolon (;). The import startment should appear
before any class definitions in a source file. Multiple import
statements are allowed.
Ex :
import firstpackage.secondPackage.Myclass; or
import firstpackage;
13. ADVANTAGES OF PACKAGES
There are several advantages of package some of them are as
follow :-
1: Packages are useful to arrange related classes and interface
into a group. This makes all the classes & interface performing
the same task to put together in the same package.
2: Packages hide the classes & interfaces in a seprate
subdirectory, so that accidental deletion of classes & interfaces
will not take place.
3: The classes & interfaces of a packages are isolated form the
classes & interfaces of another packages. This means that we
can use same names for classes of two different classes.
4: A group of packages is called a library. The classes &
interface of a package are like books in a library & can
be reused several times. This reusability nature of
packages makes programming easy.
14. Importing a Package
If we want to use a package in Java program it is
necessary to import that package at the top of the
program by using the import keyword before the
package name.
Syntax:
import packageName;
15. SIMPLE EXAMPLE OF JAVA
PACKAGE
The package keyword is used to create a
package in java.
/save as Simple.java
package mypack;
public class Simple{
public static void main(String args[]){
System.out.println("Welcome to package");
}
}
16. EXAMPLE OF PACKAGE BY IMPORT
PACKAGE.CLASSNAME
//save by A.java
package pack;
public class A{
public void msg()
{
System.out.println("Hello");}
}
//save by B.java
package mypack;
import pack.A;
class B{
public static void main(String args[]){
A obj = new A();
obj.msg();
}
}
Output: Hello