Java Reference
In-Depth Information
Programmersnote:
Innumericdatatypesthedigitsymbolsrepresentquantities.Inalpha-
numericdatatypesthesesamesymbolsareusedasdesignators,asis
thecaseinatelephoneorasocialsecuritynumber.
NumericdatacanappearinJavacodeintheformofvariablesorcon-
stants.Inadditionnumericdatacanbeenteredexplicitlyinanoperation.
Explicitnumericdata,called literals ,arediscussedlaterinthischapter.
Thefloating-pointtypesarealsocalled reals.
Eachnumericdatatypecorrespondstoacategoryofnumbers,forex-
ample,theintegerdatatypeallowsrepresentingwholenumberswhilethe
floating-pointdatatypeallowsrepresentingfractionalnumbers.Foreach
datatype,Javaprovidesseveral typespecifiers thatfurtherdetermine
thecharacteristicandrangeofrepresentablevalues.Thesearelistedin
Table4-1 .
Character data
Character or alphanumeric data refers to items that serve as textual desig-
nators. The letters of the alphabet and other non-numeric symbols are often
used as designators. Number symbols are also valid in alphanumeric data.
This is the case of telephone numbers, street addresses, zip codes, social
security numbers, and many other designators.
In Java, alphanumeric data belongs either to the char data type or to
the String class. Data defined as char is treated by Java either as a 16-bit
unsigned integer, with values in the range 0 to 65535, or as a single
Unicode character. This means that the char data type can be used to rep-
resent unsigned integers in the range mentioned above, and that it sup-
ports basic arithmetic on these values. However, it is usually better to use
the numeric data types for this and leave the char type for alphanumeric
data.
The single quotation marks are used to declare a char data type. These
are sometimes called “tick” marks. For example:
char aLet = 'f';
Recall that String objects are declared using the double quotation
marks:
String aCity = "Mankato";
Search WWH ::




Custom Search