Java Reference
In-Depth Information
5
Objects and Strings
5.1 Why do programmers need objects?
We have so far presented the basic primitive types (say, boolean , int and long ,
float and double ) of Java and explained how to build homogeneous arrays of
these primitive types. Objects are useful for two main reasons:
- (1) Objects allow one to encapsulate and structure a set of data,
- (2) Objects provide a set of functions called methods acting on the encapsu-
lated data.
For example, we would like to create objects for storing dates and write
an agenda program that manipulates these “date” objects. A date can be
defined as a triplet of numbers, say MM/DD/YYYY for storing respectively the
month, day and year of the considered date. This triplet of numbers represents
the core data-structure of dates. The object-oriented programming framework
allows one to define and work on complex entities by encapsulating the various
concepts at the object level . For example, we may like to define the following
object entities:
- A data-structure for manipulating 2D colored points,
- A data-structure for manipulating students.
The various data encapsulated in objects are called records , and the variables
to access them are called fields . For a 2D colored point object, we may wish
 
Search WWH ::




Custom Search