21.08.2013 Views

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

224 Chapter 16 ■ <strong>Programming</strong> in the large<br />

UML provides a graphical notation <strong>for</strong> describing packages. Figure 16.1 shows a<br />

package named util which consists of three classes Random, ArrayList and Stack.<br />

Showing the contents of a package is optional. This notation is useful <strong>for</strong> visualizing the<br />

large-scale architectural structure of software.<br />

Packages represent the highest-level programming units, which ranges from the<br />

small size to the large, as follows:<br />

■ statements<br />

■ methods<br />

■ classes<br />

■ packages.<br />

util<br />

Stack<br />

Figure 16.1 A package diagram<br />

ArrayList<br />

The languages C++ and C# provide a mechanism termed namespaces that is similar<br />

to packages.<br />

We will now see how packages are used within a programming language.<br />

16.3 ● Using packages<br />

Java programs typically start with import statements, such as:<br />

import java.awt.*;<br />

import java.awt.event.*;<br />

import javax.swing.*;<br />

Random<br />

java.awt, java.awt.event and javax.swing are the names of packages. Each of<br />

these packages contains a number of useful classes. For example, the class JButton is<br />

in the package javax.swing.<br />

The import statements enable a program conveniently to use the classes provided by<br />

the packages. Because the import statement is present, we can simply refer to JButton

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!