仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 4309|回复: 19
打印 上一主题 下一主题

[学习教程] JAVA网页设计Operators and Assignments(2)

[复制链接]
分手快乐 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-18 11:55:33 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
主要缺点就是:速度比较慢,没有C和C++快Objective2)
Determinetheresultofapplyingthebooleanequals(Object)methodtoobjectsofanycombinationoftheclassesjava.lang.Stringjava.lang.Booleanandjava.lang.Object.

Theequalsmethodcanbeconsideredtoperformadeepcomparisonofthevalueofanobject,whereasthe==operatorperformsashallowcomparison.Theequalsmethodcompareswhatanobjectpointstoratherthanthepointeritself(ifwecanadmitthatJavahaspointers).

TheequalsmethodappliedtoaString,howeverthatStringwascreated,performsacharacterbycharactercomparison.

Objective3)
Inanexpressioninvolvingtheoperators&|&&||andvariablesofknownvaluesstatewhichoperandsareevaluatedandthevalueoftheexpression.

Objective4)
Determinetheeffectuponobjectsandprimitivevaluesofpassingvariablesintomethodsandperformingassignmentsorothermodifyingoperationsinthatmethod.

UnaryNumericPromotion
Contexts:
・Operandoftheunaryarithmeticoperators+andC
・Operandoftheunaryintegerbit-wisecomplementoperator~
・Duringarraycreation,forexamplenewint[x],wherethedimensionexpressionxmustevaluatetoanintvalue.
・Indexingarrayelements,forexampletable[‘a’],wheretheindexexpressionmustevaluatetoanintvalue.
・Individualoperandsoftheshiftoperators.

Binarynumericpromotion
Contexts:
・Operandsofarithmeticoperators*,/,%,+andC
・Operandsofrelationaloperators<,<=,>and>=
・NumericOperandsofequalityoperators==and!=
・IntegerOperandsofbit-wiseoperators&,^and|

ConversionofPrimitives
1.3typesofconversionCassignmentconversion,methodcallconversionandarithmeticpromotion
2.booleanmaynotbeconvertedto/fromanynon-booleantype.
3.Wideningconversionsaccepted.Narrowingconversionsrejected.
4.byte,shortcan’tbeconvertedtocharandviceversa.
5.Arithmeticpromotion
5.1Unaryoperators
・iftheoperandisbyte,shortorchar{
convertittoint;
}
else{
donothing;noconversionneeded;
}
5.2Binaryoperators
・ifoneoperandisdouble{
alldouble;converttheotheroperandtodouble;
}
elseifoneoperandisfloat{
allfloat;converttheotheroperandtofloat;
}
elseifoneoperandislong{
alllong;converttheotheroperandtolong;
}
else{
allint;convertalltoint;
}
6.Whenassigningaliteralvaluetoavariable,therangeofthevariable’sdatatypeischeckedagainstthevalueoftheliteralandassignmentisallowedorcompilerwillproduceanerror.
charc=3;//thiswillcompile,eventhoughanumericliteralisbydefaultanintsincetherangeofcharwillacceptthevalue
inta=3;
chard=a;//thiswon’tcompile,sincewe’reassigninganinttochar
chare=-1;//thisalsowon’tcompile,sincethevalueisnotintherangeofchar
floatf=1.3;//thiswon’tcompile,eventhoughthevalueiswithinfloatrange.Hererangeisnotimportant,butprecisionis.1.3isbydefaultadouble,soaspecificcastorf=1.3fwillwork.
floatf=1/3;//thiswillcompile,sinceRHSevaluatestoanint.
floatf=1.0/3.0;//thiswon’tcompile,sinceRHSevaluatestoadouble.
7.Alsowhenassigningafinalvariabletoavariable,evenifthefinalvariable’sdatatypeiswiderthanthevariable,ifthevalueiswithintherangeofthevariableanimplicitconversionisdone.
byteb;
finalinta=10;
b=a;//Legal,sincevalueof‘a’isdeterminableandwithinrangeofb
finalintx=a;
b=x;//Legal,sincevalueof‘x’isdeterminableandwithinrangeofb
inty;
finalintz=y;
b=z;//Illegal,sincevalueof‘z’isnotdeterminable

8.Methodcallconversionsalwayslookfortheexactdatatypeorawideroneinthemethodsignatures.Theywillnotdonarrowingconversionstoresolvemethods,insteadwewillgetacompileerror.

Hereisthefigureofallowableprimitiveconversion.

byteàshortàintàlongàfloatàdouble
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-4 11:55

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表