Programming in JAVA
by
S. Thanga rathinam(181619)
M.Vivek mani(181620)
II B.Sc Mathematics(CA)
SBK College,Aruppukottai
TO
K.Padma Priya M.Sc(CS),M.Phill.
Assistant professor
Dept of mathematics(CA)
SBK College,Aruppukottai
Packages
Java API packages
Using system packages
Naming conventions
Creating packages
Accessing package
JAVA API packages:
JAVA API provides a large number of classes
grounded into a different packages according to
functionality. Most of the time we use the packages
available with the java API.
JAVA
lang util io awt net applet
Using system packages:
The packages are organaised in hierarchical
structure . The packages named java contains the
package awt which turn contains various classes
required for implementing graphical user interface.
There are two ways of accessing the class stored
in a packages.this is done by using the packges name
containing the class and then appending the class
name to it using the dot operator.
java.awt.colour
We want to use the class in a number of places in the
program or we may like to use many of the classes
contained in a package.
import packagename .*;
or
import packagename.classname;
These are known as import statements and must appear at
the top of the file,before any class declarations,import is a
keyword.
Naming conventions:
Packages can be named using the standard
java naming rules. By convention, however ,packages
begin with lowercase letters.
double y = java.lang.math.sqrt(x);
package class method
name name name
This statement uses a fully qualifed class name
math to invoke the method sqrt().
Creating packages:
we must first declare the name of the packages
using the package keyword followed by a package
name.
package first package;
public class firstclass
{
………….
……….... (body of class)
………….
}
Declare the package at the beginning of a file using the
form
package packagename;
Define the class that is to be put in the package
anddeclare it public .
Create a subdirectory under the directory where the main
source files are stored.
Store the listing as the classname .java file in the
subdirectory created.
Compile the file. This creates .class file in the
subdirectory.
Accessing a package:
The same approaches can be used to access the
user defined packages as well. The import statement can
be used to search the list of packages for a particular
class.
Import package 1[.package2] [.package3].
classname;
The import statement should appears before any class
definitions in a source file. Multiple import statements
are allowed.
Import first package.second package.myclass;
The statement must end with a semicolon(;).
Thankyou

Java packags

  • 1.
    Programming in JAVA by S.Thanga rathinam(181619) M.Vivek mani(181620) II B.Sc Mathematics(CA) SBK College,Aruppukottai TO K.Padma Priya M.Sc(CS),M.Phill. Assistant professor Dept of mathematics(CA) SBK College,Aruppukottai
  • 2.
    Packages Java API packages Usingsystem packages Naming conventions Creating packages Accessing package
  • 3.
    JAVA API packages: JAVAAPI provides a large number of classes grounded into a different packages according to functionality. Most of the time we use the packages available with the java API. JAVA lang util io awt net applet
  • 4.
    Using system packages: Thepackages are organaised in hierarchical structure . The packages named java contains the package awt which turn contains various classes required for implementing graphical user interface. There are two ways of accessing the class stored in a packages.this is done by using the packges name containing the class and then appending the class name to it using the dot operator.
  • 5.
    java.awt.colour We want touse the class in a number of places in the program or we may like to use many of the classes contained in a package. import packagename .*; or import packagename.classname; These are known as import statements and must appear at the top of the file,before any class declarations,import is a keyword.
  • 6.
    Naming conventions: Packages canbe named using the standard java naming rules. By convention, however ,packages begin with lowercase letters. double y = java.lang.math.sqrt(x); package class method name name name This statement uses a fully qualifed class name math to invoke the method sqrt().
  • 7.
    Creating packages: we mustfirst declare the name of the packages using the package keyword followed by a package name. package first package; public class firstclass { …………. ……….... (body of class) …………. }
  • 8.
    Declare the packageat the beginning of a file using the form package packagename; Define the class that is to be put in the package anddeclare it public . Create a subdirectory under the directory where the main source files are stored. Store the listing as the classname .java file in the subdirectory created. Compile the file. This creates .class file in the subdirectory.
  • 9.
    Accessing a package: Thesame approaches can be used to access the user defined packages as well. The import statement can be used to search the list of packages for a particular class. Import package 1[.package2] [.package3]. classname; The import statement should appears before any class definitions in a source file. Multiple import statements are allowed.
  • 10.
    Import first package.secondpackage.myclass; The statement must end with a semicolon(;).
  • 11.