Download presentation
Presentation is loading. Please wait.
Published byCrystal Tamsin Cain Modified over 9 years ago
1
Computer Science 209 Software Development Packages
2
What Is a Package? A package organizes related resources (interfaces and classes) into a conceptual unit Like a module in other languages Examples: –java.lang (basic Java resources) –java.util (collections, I/O resources, random numbers) –javax.swing, java.awt (GUIs) –newutil – resources for true stacks, etc.
3
Using a Package import java.util.*; import newutil.TrueStack; import newutil.ArrayStack; import newutil.LinkedStack; public class TestStack{ public static void main(String[] args){ // Blah blah blah }
4
Defining a Package package newutil; import java.util.Collection; public interface TrueStack extends Collection { // Blah blah blah } package newutil; import java.util.*; public class AbstractStack extends AbstractCollection implements TrueSTack { // Blah blah blah }
5
File Organization Source files for classes should be in a directory whose name is the package name When byte code is generated, it is placed in a directory with the package’s name These directories should be just below the directories of the source or byte code files that use them
6
File Organization truestack2 TestStack.java newutil TrueStack.java AbstractStack.java ArrayStack.java LinkedStack.java
7
Creating a Package from the Terminal Place the.java files in a directory whose name is the package name Attach to this directory and run javac *.java Place the package directory in the directory where your client program will be Run javac or java from this directory as needed
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.