Java Reference
In-Depth Information
Method Call Operator
Themethodcalloperator— () —isusedtosignifythatamethod(discussedin Chapter
2 ) isbeingcalled.Furthermore,itidentifiesthenumber,order,andtypesofarguments
that are passed to the method, to be picked up by the method's parameters. Sys-
tem.out.println("Hello"); is an example.
Multiplicative Operators
The multiplicative operators consist of multiplication ( * ), division ( / ), and remainder
( % ). Multiplication returns the product of its operands (e.g., 6*4 returns 24), division
returns the quotient of dividing its left operand by its right operand (e.g., 6/4 returns
1),andremainderreturnstheremainderofdividingitsleftoperandbyitsrightoperand
(e.g., 6%4 returns 2).
Themultiplication,division,andremainderoperatorscanyieldvaluesthatoverflow
orunderflowthelimitsoftheresultingvalue'stype.Forexample,multiplyingtwolarge
positive32-bitintegervaluescanproduceavaluethatcannotberepresentedasa32-bit
integervalue.Theresultissaidtooverflow.Javadoesnotdetectoverflowsandunder-
flows.
Dividing a numeric value by 0 (via the division or remainder operator) also results
in interesting behavior. Dividing an integer value by integer 0 causes the operator to
throwan ArithmeticException object( Chapter3 coversexceptions).Dividinga
floating-point/double precision floating-point value by 0 causes the operator to return
+infinityor-infinity,dependingonwhetherthedividendispositiveornegative.Finally,
dividing floating-point 0 by 0 causes the operator to return NaN (Not a Number).
Object Creation Operator
Theobjectcreationoperator( new )createsanobjectfromaclassandalsocreatesanar-
ray from an initializer. These topics are discussed in Chapter 2 .
Relational Operators
Therelationaloperatorsconsistofrelationalgreaterthan( > ),relationalgreaterthanor
equalto( >= ),relationallessthan( < ),relationallessthanorequalto( <= ),andrelational
typechecking( instanceof ).Theformerfouroperatorscomparetheiroperandsand
returntrueiftheleftoperandis(respectively)greaterthan,greaterthanorequalto,less
than,orlessthanorequaltotherightoperand.Forexample,eachof 5.0 > 3 , 2 >=
2 , 16.1 < 303.3 , and 54.0 <= 54.0 evaluates to true.
Search WWH ::




Custom Search