about packages by urssravan


•A package is a collection of related classes and interfaces that
 provides access protection and namespace management.
•Packages are created using the package keyword.
package graphics;

                         TCS Internal
•Classes belong to one package are stored in the subdirectory
 whose name is same as the package name.
•Package member can be accessed by using import keyword.
•Only public members of package are accessible to universe.

                        TCS Internal
Java Class Path
•When the Java compiler encounters a new class, it must be
 able to find that class in order to resolve names, do type
 checking etc.
•When the Java interpreter encounters a new class, it must be
 able to find the class to load it and invoke its methods, etc.

                         TCS Internal
Access Specifiers
•Java provides four distinct access specifiers for class
  – private
  – protected
  – public
  – default / (package wide scope)

                          TCS Internal
Various locations of classes
•The class itself
•Its sub class in the same package
•Other classes in the same package
•Its sub class in a different package
•Other classes in other packages.

                         TCS Internal
Java Class Path
•Both compiler and interpreter search for classes in the
 specified directory.
•The directory specification is provided by CLASSPATH
 environment variable.
•A class path is a list of directories or zip files to search for the
 class files.
•The classpath can also be passed explicitly to javac or java

                           TCS Internal
Access Control
                    Private                  Default   Protected   Public

                                                                 

Sub class, same
                                                                 
Other class, same
package                                                          

Sub class, diff
package                                                          

Other class, diff
package                                                          

                              TCS Internal
Java Language Library
•Defined in “java.lang” package.
•By default available for all Java programs and no need to
 import it explicitly.
•It contains classes and interfaces that are fundamental to
 virtually all classes.

                         TCS Internal
java.lang Package
•Wrapper classes                       •Process
  – Boolean, Integer, Float            •Runtime
     etc.                              •System
•String                                •Thread

                        TCS Internal
java.lang Package
   – Clonable
   – Comparable
   – Runnable

                    TCS Internal
Java.util Package

•StringTokenizer                            •Calendar
  – To parse strings                           – Calendar related utilities
•BitSet                                     •TimeZone
  – To store an array of                       – The time zone of various
     bits                                        places
  – Date related utilities
                                               – To generate Random number

                             TCS Internal
Java.util Package
• Collection Framework
    – ArrayList
    – LinkedList
    – HashSet
    – TreeSet
    – HashMap
    – TreeMap
• Legacy Classes
    – Vector
    – Hashtable
    – Stack
    – Properties

                         TCS Internal
Java.io Package
  – Byte Streams
  – Character Streams
•Abstract classes
  – Byte
  – Character
                        TCS Internal
Java.io Package
•Abstract Methods

                    TCS Internal
java.io Package

•Some Classes for byte streams
  – FileInputStream / FileOutputStream
  – ByteArrayInputStream/ByteArrayOutputStream
  – FilterOutputStream/FilterInputStream
  – BufferedInputStream/BufferedOutputStream
  – ObjectInputStream / ObjectOutputStream

                     TCS Internal
java.io Package

•Some Classes for character streams
  – FileReader / FileWriter
  – CharArrayReader / CharArrayWriter
  – BufferedReader / BufferedWriter
  – PushbackReader / PushbackWriter
  – PrintWriter

                      TCS Internal
Some Other Libraries
•java.net.*           - network related
•java.sql.*           - database related
•java.awt.*           - GUI related
•javax.swing.*        - Advanced GUI
•java.applet.*        - Applet Related
•java.security.*      - Security related

 And a lot more libraries are available for ready use.

                          TCS Internal
Using Java Documentation

            Classes &
           Interfaces in                    Class
            a Package                     Description

                           TCS Internal
•In this session, you learned:
   – Packages
   – Access Control
   – Java Language Library
   – Java Utility Library
   – Java I/O Library
   – Other Java Libraries
   – Using Java API documentation

                       TCS Internal

To top