Java Reference
In-Depth Information
TheJavaStringclasscontainsseveralmethodstomanipulateandcon-
vertstrings.Thesearediscussedlaterinthisbook.
Programmersnote:
Atthetimeitisdeclaredavariableassumescertainspecificattrib-
utes.Oneoftheseattributesiscalledthe scope .Avariable'sscopeis
thepartofaprogramoverwhichitisrecognized.ThescopeofaJava
variableisdeterminedbytheclosestsetofrostersymbols,{and},that
containthevariable.Thevariablecanbeusedonlyinthepartofthe
codethatislocatedwithintheserosters.Bystrictlyenforcingthevari-
ablescoperules,Javamakesitdifficulttomisusevariables.
Java constants
Javaconstantsarevariablesdefinedwiththe final and static keywords.
Javahasstrictrulesforthedeclarationofconstants.Thelanguagedoesnot
allowconstantsinsideaparticularmethod.Instead,constantsmustbede-
finedattheclasslevel.Forthisreasontheyaresometimescalled classcon-
stants .Ifanapplicationrequiresalocalconstantallitcandoisdefinea
variableanduseitasifitwereaconstant.Thefollowingstatementdeclares
aconstant:
staticfinaldoublePI=3.141592653589793;
Manyprogrammersuseallupper-caselettersforconstantnames,asin
thecaseoftheconstantPIlistedabove.Thisstylemakesiteasytoiden -
tifyvariablesandconstantsinthecodelisting.
Classification of Java Data
In Table4-1 weseethatJavaprimitivedatatypesareclassifiedintothree
categories: numeric types, character types (also called alphanumeric
data), and boolean types. Each of these data types serves a special purpose
in a Java program. Before you can start serious Java programming you must
first have a clear notion of the three categories of Java data and of the spe-
cific types in each one of them.
Numeric data
Many Java programs must do number-crunching operations. Numeric data
is used to perform mathematical operations and calculations.
Search WWH ::




Custom Search