THE Java™ Programming Language, Fourth Edition

(Jeff_L) #1

1.18. Other Topics Briefly Noted


There are several other features that we mention briefly here and cover later in more detail:


Threads The language has built-in support for creating multithreaded applications. It uses per-object
and per-class monitor-style locks to synchronize concurrent access to object and class data. See
Chapter 14 for more details.


Reflection The reflection mechanism (known as runtime type information RTTIin some languages)
allows browsing of class types and their members, and programmatic manipulation of objects. See
Chapter 16 for more information about reflection.


I/O The java.io package provides many different kinds of input and output classes. See Chapter 20
for specifics of the I/O capabilities.


Collections You will find many useful collection classes, such as List and HashMap in the
java.util package. See Chapter 21 for more information about collections.


Utility interfaces and classes The java.util package has many other useful classes, such as
BitSet, Scanner, and Date. See Chapter 22 for more information about these utility classes.


Internationalization If your application is available to people all over the world, you need to be able to
adapt the user interface to support interacting with the user in their language, and using their
conventionssuch as how dates are presented, or how numbers are formatted. There are a number of
classes, mainly in the java.util and java.text packages that aid you in this.
Internationalization and localization are discussed in Chapter 24.


Carefulwe don't want to learn from this!

Calvin and Hobbes

Chapter 2. Classes and Objects


First things first, but not necessarily in that order.

Dr. Who, Meglos

The fundamental programming unit of the Java programming language is the class. Classes provide the
structure for objects and the mechanisms to manufacture objects from a class definition. Classes define
methods: collections of executable code that are the focus of computation and that manipulate the data stored
in objects. Methods provide the behavior of the objects of a class. Although you can compute using only
primitive typesinteger, floating-point, and so onalmost any interesting program will create and manipulate
objects.


Object-oriented programming strictly separates the notion of what is to be done from how it is done. "What"
is described as a set of methods (and sometimes publicly available data) and their associated semantics. This
combinationmethods, data, and semanticsis often described as a contract between the designer of the class and
the programmer who uses it because it says what happens when certain methods are invoked on an object.
This contract defines a type such that all objects that are instances of that type are known to honor that
contract.


A common assumption is that the methods declared in a class are its entire contract. The semantics of those
operations are also part of the contract, even though they may be described only in documentation. Two
methods may have the same name and parameters and throw the same exceptions, but they are not equivalent
if they have different semantics. For example, not every method called print can be assumed to print a copy
of the object. Someone might define a print method with the semantics "process interval" or "prioritize
nonterminals"not that we'd recommend this. The contract of the method, both signature and semantics
together, defines what it means.

Free download pdf