Enter your email address:

    Delivered by FeedBurner

Packages Java


Package : the Library Unit
• Managing “name spaces”
– Class members are already hidden inside class
– Class names could clash
– Need completely unique name
• Packages
– organize classes into libraries
– structure name space for classes
– restrict visibility
– may be nested

Creating a Library of Classes
package mypackage;
public class Class1{ ... }
package mypackage.mysubpackage1;
public class Class5{ ... }
• public class is under the umbrella mypackage
• Client programmer must import the package
import mypackage.*;
import java.util.Vector;

Compilation Units
• Compilation units (.java files)
– Name of .java file == name of single public class
– Other non-public classes are not visible
– Each class in file gets its own .class file
– Program is a bunch of .class files

Class Access
• Classes as a whole can be public or “friendly”
• Only one public class per file, usable outside the library
• All other classes “friendly,” only usable within the library

Package : the Library Unit
• Managing “name spaces”
– Class members are already hidden inside class
– Class names could clash
– Need completely unique name
• Packages
– organize classes into libraries
– structure name space for classes
– restrict visibility
– may be nested

Creating a Library of Classes
package mypackage;
public class Class1{ ... }
package mypackage.mysubpackage1;
public class Class5{ ... }
• public class is under the umbrella mypackage
• Client programmer must import the package
import mypackage.*;
import java.util.Vector;

Compilation Units
• Compilation units (.java files)
– Name of .java file == name of single public class
– Other non-public classes are not visible
– Each class in file gets its own .class file
– Program is a bunch of .class files

Class Access
• Classes as a whole can be public or “friendly”
• Only one public class per file, usable outside the library
• All other classes “friendly,” only usable within the library

Recent Articles

Blog Archive