Java Reference
In-Depth Information
AnidentifiercannotbeoneofthespecialkeywordsusedbytheJava
language.AppendixBliststheJavareservedwords.
Programmersnote:
Oneoftheprogrammer'smostimportanttasksiscomingupwithgood
identifiers.Agoodidentifierisonethatisdescriptiveandatthesame
timeeasytotype.Forexample,ifadataitemistoholdtheageofan
employee,agoodnameforthisitemmaybeemployeeAge.Since
spacesareillegalinidentifiers,youcanusecapitallettersortheun-
derscoresymboltoseparatetheindividualwordsinaname.Cryptic
ormeaninglessidentifiersmakethecodedifficulttounderstandand
maintain.Whileidentifiersthataretooverboseorcomplicatedare
pronetotypingerrors.
Creating and using variables and constants
Toaprogrammer,avariableisastoragelocationthatcontainsadataitem
ofaspecifictype.Thestoragelocationisassignedanamesothatitcanbe
identified.Thecontentsofavariablecanbechangedanywhereinthepro-
gram.Therefore,avariablecanbevisualizedasalabeledbox,definedby
theprogrammer,forstoringadataobjectofaparticulartype. Figure4-1
shows the data items listed previously.
stateName
age
streetAddress
75
Minnesota
131 Calm Court
Figure 4-1 Variables as Labeled Boxes
In the course of a program we can re-assign values to all our variables,
as long as the new value is consistent with the original type. For example,
we can replace the value of the numeric constant named “age” with an-
other number, or the value of the variable named “stateName” with an-
other name. Constants , on the other hand, represent values that do not
change in the course of a program. For example, we can define a constant
to store the value of Pi, which is the ratio between the diameter and the
 
Search WWH ::




Custom Search