You will find many examples in Java API java.util package, java.lang package etc.

To include a class into a package add a statement

package package_name

before the class header.

4package Definition

1. Add package package_name to all the java source files that contains class definition to be included in the package.

2. Create a directory package_name

3. Compile and place the class files in a directory package_name

5package Usage

1. Update your CLASSPATH environment variable to include the path where the directory is located.

2. Make sure the update is effective by executing source .cshrc

3. Include import package_name. in the application/applets where you want to use these classes.

6Example

Look at ch17, fig17_04

The application is in CreateSequentialFile.java.

The classes it uses are BankU.javaI and BankAccountRecord.java

Lets create a package ch17 out of these two classes.

Create a directory ch17 anywhere you want. Move BankUI.java and BanAccountRecord.java into this directory.

Add package ch17 at the top of the two files. Remove any other reference to packages.

7Example (contd.)

Compile the files BankUI.java and BankAccountRecord.java

Update .cshrc to include the path to the parent directory of ch17.

source .cshrc

Update CreateSequentialFile.java to import classes from ch17

import ch17.

Compile and execute.

8Archiving the Package

Often once the classes are related by package, and after they are tested well, they are compressed using a jar tool to provide an easy way to transport the package as one.

Command (See man jar)

jar cf jar_file_name classes to be archived

Examples

jar ch17.jar BankUI.class Record.class BankAccountRecord.class

9Including jar file in CLASSPATH

When a package is in the form of a .jar file, you need actually include the jar file in the CLASSPATH.

Example

setenv CLASSPATH ./projects/bina/ch17.jar

10Jar your files for Prj2

Create a jar files out of all the source files (java) into a prj2.jar

Submit prj2.jar file.

One more modification No need for print in prj2. We will do that prj3.

But save and load are needed. These can be hidden operations, that is, no need for an user interface for data saving and restoring.

11Summary

You can collect all the useful classes you have created into a package.

Create a CS2 package.

Use it in your future applications.

About PowerShow.com

PowerShow.com is a leading presentation/slideshow sharing website. Whether your application is business, how-to, education, medicine, school, church, sales, marketing, online training or just for fun, PowerShow.com is a great resource. And, best of all, most of its cool features are free and easy to use.

You can use PowerShow.com to find and download example online PowerPoint ppt presentations on just about any topic you can imagine so you can learn how to improve your own slides and
presentations for free. Or use it to find and download high-quality how-to PowerPoint ppt presentations with illustrated or animated slides that will teach you how to do something new, also for free. Or use it to upload your own PowerPoint slides so you can share them with your teachers, class, students, bosses, employees, customers, potential investors or the world. Or use it to create really cool photo slideshows - with 2D and 3D transitions, animation, and your choice of music - that you can share with your Facebook friends or Google+ circles. That's all free as well!

For a small fee you can get the industry's best online privacy or publicly promote your presentations and slide shows with top rankings. But aside from that it's free. We'll even convert your presentations and slide shows into the universal Flash format with all their original multimedia glory, including animation, 2D and 3D transition effects, embedded music or other audio, or even video embedded in slides. All for free. Most of the presentations and slideshows on PowerShow.com are free to view, many are even free to download. (You can choose whether to allow people to download your original PowerPoint presentations and photo slideshows for a fee or free or not at all.) Check out PowerShow.com today - for FREE. There is truly something for everyone!

presentations for free. Or use it to find and download high-quality how-to PowerPoint ppt presentations with illustrated or animated slides that will teach you how to do something new, also for free. Or use it to upload your own PowerPoint slides so you can share them with your teachers, class, students, bosses, employees, customers, potential investors or the world. Or use it to create really cool photo slideshows - with 2D and 3D transitions, animation, and your choice of music - that you can share with your Facebook friends or Google+ circles. That's all free as well!

For a small fee you can get the industry's best online privacy or publicly promote your presentations and slide shows with top rankings. But aside from that it's free. We'll even convert your presentations and slide shows into the universal Flash format with all their original multimedia glory, including animation, 2D and 3D transition effects, embedded music or other audio, or even video embedded in slides. All for free. Most of the presentations and slideshows on PowerShow.com are free to view, many are even free to download. (You can choose whether to allow people to download your original PowerPoint presentations and photo slideshows for a fee or free or not at all.) Check out PowerShow.com today - for FREE. There is truly something for everyone!