Java Reference
In-Depth Information
minglanguagetheparttotheleftofthe=signiscalledthe lvalues (shortfor
left value) and the one to the right is called the rvalues (short for right
value).Therefore,anlvalueisanexpressionthatcanbeusedtotheleftof
the=sign.InaJavaassignmentstatementthelvaluemustrepresentasingle
storagelocation.Inotherwords,theelementtotheleftofthe=signmustbe
a variable. In this manner, if x and y are variables, the expression
x=2*y;
is a valid one. However, the expression
y+2=x;
isnotvalidsinceinthiscasethelvalueisnotasinglestoragelocationbutan
expressioninitself.Bythesametoken,anexpressionwithoutanrvalueis
illegal in Java, for example:
y=;
An assignment expression without an lvalue is also illegal, such as
=x;
Arithmetic Operators
Javaarithmeticoperatorsareusedtoperformsimplecalculations.Someof
theJavaarithmeticoperatorscoincidewiththefamiliarmathematicalsym-
bols.Suchisthecasewiththe+and-operatorswhichindicateadditionand
subtraction. But not all conventional mathematical symbols are available
in a computer keyboard. Others are ambiguous or incompatible with the
rulesoftheJavalanguage.Forexample,theconventionalsymbolfordivi-
sion( รท )isnotastandardkeyboardcharacter.Usingtheletter x asasymbol
formultiplicationisimpossible,sincethelanguageisunabletodifferenti-
ate between the mathematical operator and the alphanumeric character.
ForthesereasonsJavausesthe/symboltoindicatedivisionandthe*toin-
dicatemultiplication. Table7-1 liststheJavaarithmeticoperators.
Table 7-1
Java Arithmetic Operators
OPERATOR
ACTION
+
addition
-
subtraction
*
multiplication
/
division
%
remainder
 
Search WWH ::




Custom Search