Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Packages

Packages

  • Although classes are the central unit of object-oriented design in Java, packages provide an additional level of organizational support. Packages are used to store sets or related classes and interfaces. (packages usually correspond to a directory in which you store your class files). As such, packages define relationships between classes and how they should work together. They also protect the name space since they provide the JVM another way to identify classes by name. Thus, you may have two classes of the same name so long as they reside in separate packages.

  • You can specifically define a package name using the "package" keyword on the first line of a class such as in:

    package myPakage;

  • Another benefit of using packages is it allows you to reference entire packages of classes using the "import" keyword. Thus, rather than specifying a class absolutely, you can import its package and reference it relative to its package. Thus, you often see the line:

    import java.awt.*;

  • In this case, you can use any class in the awt package using only its name. Consider the following code:

    import java.applet.*;
    public class myApplet extends Applet
      {
      .. code...
      }
    

  • Without the import, you would need to write the following:

    public class myApplet extends java.applet.Applet
      {
      .. code...
      }
    

    Note that you get all the classes in java.lang for free since it is loaded automatically by the JVM

  • Relationships between classes are also handled by modifiers or access specifiers. We'll talk about this in just a minute.

Additional Resources:

Ineheritance
Table of Contents
Creating and Using Classes by Example


Up to => Home / Authoring / Scripting / Tutorial




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers