• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 11 pages
Class notes

Working with Packages and Using Javadoc to document a Package

Document preview thumbnail
Preview 2 out of 11 pages

Packages provide two main advantages. First, when a project contains a large number of classes, packages can provide some logical structure to your application and make it easier to find the classes that your are looking for. Secondly, packages provide a way to avoid naming conflicts between classes. This is particularly important if you want to make your classes avaibable to other programmers.

Content preview

CSI21M1 Java Programming Notes, prepared by Mr. S. Nyika, Semester I, 2019


Lecture 4: Working with Packages and Using Javadoc to document a Package

Objectives:
At the end of this lecture, students will be able to:
• explain the idea of a package
• create a new package
• add a class to a package
• delete a package
• rename a package
• move a class from one package to another
• navigate existing packages
• understand documentation using javadoc
• create a library for a package
• use a library in an application

Notes:

To make it easy to find and access classes, the Java API organizes its classes into packages. This allows
you to import just the classes and packages that an application needs.

Packages provide two main advantages. First, when a project contains a large number of classes,
packages can provide some logical structure to your application and make it easier to find the classes
that your are looking for. Secondly, packages provide a way to avoid naming conflicts between classes.
This is particularly important if you want to make your classes avaibable to other programmers.

The following shows the directories and files of the StudenApp application




Page 1 of 11

, CSI21M1 Java Programming Notes, prepared by Mr. S. Nyika, Semester I, 2019



Here the project folder, StudentSofware, which has the following directory hierararchy:




contains the subdirectories for each package. Then, each subdirectory contains the classes which define
the business objects for this application.

When you name a package, you can use any name you want. However, if you want to make sure
that the name of your package is unique, its considered a good practice to start the name of your
internet domain name in reverse. For example za.ac.wsu.snyika, so all my classes would be stored
in this package. Even if you do not follow this convention, you should avoid using a general name, for
example a package name snyika would be too general.

Once you store a class in the correct directory, you must code a package statement at the beginning of
the class. This statement consists of the package keyword followed by the name of the package. For
example as shown earlier, the statement in the Student class is package za.ac.wsu.snyika. This
statement will make sure that the folders are created when your program is compiled.

If a class is stored in a package, it cannot be accessed from classes in other packages without qualifying
it with the name of the package. As a result, you typically import the class to make it easier to refer
to. This works the same for the packages and classes that your create as it does for the classes of the
Java API such as JoptionPane.




Page 2 of 11

Connected book
 image
John Lewis, Peter DePasquale, Joseph Chase Java Foundations
Publisher: 2010 ISBN: 9780132128810 Edition: Unknown

Document information

Uploaded on
June 16, 2021
Number of pages
11
Written in
2020/2021
Type
Class notes
Professor(s)
Dr simba
Contains
All classes
$3.15

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
1
Followers
1
Items
10
Last sold
5 year ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions