Sams Teach Yourself C in 21 Days

(singke) #1
Object-Oriented Programming Languages 643

BD1


Packages ........................................................................................................

Code reuse is a strong point of any object-oriented language, and inheritance is perhaps
the main mechanism by which reusability is accomplished. Java takes this one step fur-
ther with packages (sometimes also called class libraries). A Java package streamlines
and simplifies the reuse of classes (objects). A package is in many ways like a library or
applications programming interface (API) in other languages.
Packages also help to manage name spaces. The idea of a name space is related to the
fact that two different classes might have the same name. Because a Java program is
likely to use at least several packages—some that are part of the Java language, others
from third-party firms, and some you create yourself—the possibility exists for confusion
between same-name classes. In Java, each package defines a separate name space, and a
class name needs to be unique only within its own name space. In other words, a class is
identified by both its package (name space) and its name.

Java Applets Versus Applications ..................................................................

Java was designed to write to different types of programs. An application is a full-
fledged program designed to run on its own, just like the programs you have been creat-
ing in C. An applet is a special kind of program designed to be distributed over the
Internet and executed in a browser. For the most part, there is not much difference in
writing applications or applets, except that applets are a bit simpler because the browser
in which they execute performs some of the tasks that a Java application must do for
itself.

Java’s Class Libraries ....................................................................................

Java is more than just a programming language. When you install a Java development
tool you also get a comprehensive set of classes that are ready for you to use. Java’s class
libraries are similar to the function library that is part of C and to the class libraries that
are provided with C++ compilers. For most of the commonly needed program functions,
such as screen display, networking, or Internet access, you are likely to find the function-
ality you need already built and tested in one of Java’s class libraries. Whichever Java
development tool you use, it will have documentation on the details of its class libraries.

Although Java is supposed to be platform independent, things have not
worked out that way. It is still a lot better than any other language, but a
variety of factors have resulted in Java not having the complete platform
independence that was intended.

Caution


36 448201x-Bonus1 8/13/02 11:18 AM Page 643

Free download pdf