AllExperts > Experts 
Search      

Java

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Java Answers
Question Library

Ask a question about Java
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Neal Ziring
Expertise
Almost anything about the core Java platform, with an emphasis on networking. Not familiar with JDBC or the new Java graphics APIs. [Sun Certified Java Programmer, JDK 1.1]

Experience
Certified Java Programmer for JDK 1.1 and 2.0.
 
   

You are here:  Experts > Computing/Technology > Focus on Java > Java > Java Package

Topic: Java



Expert: Neal Ziring
Date: 5/31/2008
Subject: Java Package

Question
Sir,
I would like to know regaring the package concept in java.Would u please prive me the tutorial regarding package and also one example.How do I declare the user defined package in java.

Answer
Samujeet,

Many good Java instructions and tutorials exist on the Web,
including ones about packages.  I've included some links
at the end of this answer.

A Java Package is just a namespace for classes.  Every class
belongs to a package.  (Classes that are not explicitly given
a package belong to the special "unnamed" package.)

The Java compiler and Java run-time system automatically
associate packages with directories.  For example, a package
named
       com.sun.tools.compiler

corresponds to a directory

       com/sun/tools/compiler

somewhere on your CLASSPATH or in a loaded Jar file.

For example, let's say you are writing a program for handling
drawings.  You might have a package for all your graphics
primitives: Circle, Rectangle, Arc, Text, ...

So, you might define the package

             chakra.graphics

and put each graphics primitive class in the package.
The class chakra.graphics.Circle would be in the file

      chakra/graphics/Circle.java    and
      chakra/graphics/Circle.class

If you wanted to use these classes from other parts of
your code, you would need to import them.

To declare a class as belonging to a particular package, you
must use the "package" directive in your code.


      package chakra.graphics;

      import java.awt.*;

      public class Circle extends Shape {
           double radius;

           .
               .
                    .
      }


For more information, check here:

http://java.sun.com/docs/books/tutorial/java/package/packages.html
http://www.jarticles.com/package/package_eng.html
http://tinf2.vub.ac.be/~dvermeir/java/other_doc/JavaPackages.html
http://virtual.lncc.br/~rodrigo/cursos/unused/Java/01_Apostilas/outros/CriandoPacotes_English.pdf


Good luck...

...nz  

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.