Java Reference
In-Depth Information
When we look at data we observe that it comes in two flavors: numbers
and names. The main difference between numbers and names is that we
can perform arithmetic on numbers, but not on names. Numbers belong
to a type called numeric data, while names are
alphanumeric
or
charac-
ter data
. You may have also noticed that some data items refer to individ-
ual objects and others are a collection of objects. For example, the data
item “131 Calm Court” is a collection of three simpler items. Data types
that encode individual objects are called
scalar
types, while those that
represent collections of objects are called
structured
data types. Java
provides means for storing and manipulating numeric and alphanumeric
data objects of both scalar and structured types.
Once a data item is assigned to a particular type, its processing is done
according to the rules for that particular type. In other words: you cannot
do arithmetic on objects defined as a character type. By the same token,
numeric data cannot be separated into its individual symbols. As a pro-
grammer you assign each data object to the data type that corresponds to
its intended use. In doing this, you must not be confused by an object's
appearance. For example, a telephone number, which is actually a collec-
tion of digits, is usually considered an alphanumeric data type. What
would be the use of adding or subtracting telephone numbers?
Identifiers
Before we get into the details of creating and using data we must take a brief
look at the Java rules for naming program elements. Java
identifiers
are
used to name data items, classes, and methods. Legal characters for identi-
fiers are the letters and digits of the Unicode character set, as well as the
symbols $ and _. The space is not a legal character in an identifier since Java
uses the space to mark the end of names. Because Java is
case-sensitive,
the names aVar and Avar represent different identifiers. An identifier can-
not start with a digit. The length of an identifier is virtually unlimited, al-
though it is a good idea to keep identifiers to less than 30 characters. The
following are legal identifiers in Java:
personalName
PI
y_121
$$128
user_address
The following identifiers are illegal:
1_value
User name
%%123