Presentation is loading. Please wait.

Presentation is loading. Please wait.

“Packages in Java”.

Similar presentations


Presentation on theme: "“Packages in Java”."— Presentation transcript:

1 “Packages in Java”

2 Contents Introduction Classification Java API packages
Using system packages Naming conventions Creating package Accessing package Using a package Conclusion Bibliography

3 Introduction Packages are Java’s way of grouping a variety of classes and/or interfaces together

4 Classification Java packages are classified into two types 1) Java API
2) User defined packages

5 Java API package JAVA lang util io awt net applet

6 Using system package Java awt Package containing awt package Color
Graphics Package containing classes Font Classes containing methods Image

7 Naming convention double y = java . lang . Math . sqrt (x);
Package name Class name Method name

8 Creating package package firstPackage; public class FirstClass {
……………………… } (Body of class)

9 Continued…. Declare the package at the beginning of a file using the form Define the class that is to be put it the package and declare it public Create a sub directory under the directory where the main source files are stored package packagename;

10 Continued…… Store the listing as the classname .java file in the sub directory created Compile the file. This creates .class file in the sub directory

11 Accessing a Package import package1 [.package2]
[.package3] .classname;

12 Using a Package package package1; public class ClassA { public void displayA() System.out.println(“welcome”); s } }

13 Cont.. import package1.classA; class Test { public static void main(String args[]) classA obj=new classA(); obj.displayA(); }

14 conclusion Ability to reuse the code within the same programs is achieved in oops by means of extending and implementing. Including this property java also provides a mechanism,that is reuse of the code out side the program without physical copy, is achieved by using packages.


Download ppt "“Packages in Java”."

Similar presentations


Ads by Google