Welcome To My Presentation
Name : Tahmid Mobashir
ID : 01319106034
Introduction Of Java Packages
• Definition : A package is a collection of related classes and inferfaces
that provides access protection and namespace management .
• Package Member : A java package can have member of either or both
of the following kinds
• Sub packages of the package.
• Types declared in the compilation units.
What do we need java Packages
• Java programmers bundle groups of related classes into packages.
• To make class easier to find and use .
• To avoid naming conflicts suppose you wrote a data class and there is
already another class called data.
• To control access .
• A package is like a project in c .
How To create a package
• While creating a package, programmers must choose a name for the
package and include a package statement along with that name at the
top of the source program that contains the classes, interfaces,
enumerations, and annotation types that you want to include in the
package. There can be only one statement of the package in each
source code, and it applies to all types in the file.
• To compile the Java programs with package programmers have to do
used option as shown below .
javac -d Destination_folder file_name.java
• After that, a folder is created with the given package name in a
specific location, and the compiled class files will be placed in that
folder.
• The general form of creating a package is:
package pack_name;
public class firstClass
{ . . . . . . . . //body of the class.
. . . . . . . . }
• Here, the package name is pack_name, and the class
firstClass is considered a part of this package. This listing
would be saved in as a file called firstClass.java and will be
stored in the directory named pack_name. When the file
gets compiled, Java will create a .class file and store it in the
same directory.
Example of Java program package
package weapons;
interface ammo
{
public void sniper();
public void rifle();
}

Java Packages

  • 1.
    Welcome To MyPresentation Name : Tahmid Mobashir ID : 01319106034
  • 2.
    Introduction Of JavaPackages • Definition : A package is a collection of related classes and inferfaces that provides access protection and namespace management . • Package Member : A java package can have member of either or both of the following kinds • Sub packages of the package. • Types declared in the compilation units.
  • 3.
    What do weneed java Packages • Java programmers bundle groups of related classes into packages. • To make class easier to find and use . • To avoid naming conflicts suppose you wrote a data class and there is already another class called data. • To control access . • A package is like a project in c .
  • 4.
    How To createa package • While creating a package, programmers must choose a name for the package and include a package statement along with that name at the top of the source program that contains the classes, interfaces, enumerations, and annotation types that you want to include in the package. There can be only one statement of the package in each source code, and it applies to all types in the file. • To compile the Java programs with package programmers have to do used option as shown below . javac -d Destination_folder file_name.java
  • 5.
    • After that,a folder is created with the given package name in a specific location, and the compiled class files will be placed in that folder. • The general form of creating a package is: package pack_name; public class firstClass { . . . . . . . . //body of the class. . . . . . . . . }
  • 6.
    • Here, thepackage name is pack_name, and the class firstClass is considered a part of this package. This listing would be saved in as a file called firstClass.java and will be stored in the directory named pack_name. When the file gets compiled, Java will create a .class file and store it in the same directory.
  • 7.
    Example of Javaprogram package package weapons; interface ammo { public void sniper(); public void rifle(); }