仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 3209|回复: 19

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

[复制链接]
灵魂腐蚀 该用户已被删除
发表于 2015-1-18 11:55:33 | 显示全部楼层 |阅读模式

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

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

x
最初被命名为Oak,目标设定在家用电器等小型系统的编程语言,来解决诸如电视机、电话、闹钟、烤面包机等家用电器的控制和通讯问题。5)OperatorsandAssignments
Objective1)
Determinetheresultofapplyinganyoperatorincludingassignmentoperatorsandinstanceoftooperandsofanytypeclassscopeoraccessibilityoranycombinationofthese.
1.Unaryoperators.
1.1IncrementandDecrementoperators++--
Wehavepostfixandprefixnotation.Inpost-fixnotationvalueofthevariable/expressionismodifiedafterthevalueistakenfortheexecutionofstatement.Inprefixnotation,valueofthevariable/expressionismodifiedbeforethevalueistakenfortheexecutionofstatement.

x=5;y=0;y=x++;Resultwillbex=6,y=5
x=5;y=0;y=++x;Resultwillbex=6,y=6

Implicitnarrowingconversionisdone,whenappliedtobyte,shortorchar.

1.2Unaryminusandunaryplus+-
+hasnoeffectthantostresspositivity.
-negatesanexpression’svalue.(2’scomplementforintegralexpressions)
1.3Negation!
Invertsthevalueofabooleanexpression.
1.4Complement~
Invertsthebitpatternofanintegralexpression.(1’scomplementC0sto1sand1sto0s)
(~i=-i-1)
Cannotbeappliedtonon-integraltypes.
1.5Cast()
Persuadescompilertoallowcertainassignments.Extensivecheckingisdoneatcompileandruntimetoensuretype-safety.

2.Arithmeticoperators-*,/,%,+,-
・Canbeappliedtoallnumerictypes.
・Canbeappliedtoonlythenumerictypes,except‘+’CitcanbeappliedtoStringsaswell.
・Allarithmeticoperationsaredoneatleastwith‘int’.(Iftypesaresmaller,promotionhappens.Resultwillbeofatypeatleastaswideasthewidetypeofoperands)
・Accuracyislostsilentlywhenarithmeticoverflow/erroroccurs.Resultisanonsensevalue.
・Integerdivisionor%byzerothrowsArithmeticException.
・Floatingpointarithmeticalwayslosesprecision.Thefollowingcodefragmentreturnsfalse.
floatf=1.0F/3.0F;
if(A*3.0F==1.0F)returntrue;
elsereturnfalse;
・%-signoftheresultentirelydeterminedbysignofLHS
・FloatingpointcalculationscanproduceNaN(squarerootofanegativeno.or%byzero)orInfinity/-Infinity(divisionbyzero).FloatandDoublewrapperclasseshavenamedconstantsforNaNandinfinities.
・NaN’sarenon-ordinalforcomparisons.X==Float.NaNwon’twork.UseFloat.IsNaN(x)andDouble.IsNaN(x).Butequalsmethodonwrapperobjects(DoubleorFloat)withNaNvaluescomparesNan’scorrectly.
・Infinitiesareordinal.X==Double.POSITIVE_INFINITYwillgiveexpectedresult.
・+alsoperformsStringconcatenation(whenanyoperandinanexpressionisaString).Thelanguageitselfoverloadsthisoperator.toString()methodofnon-Stringobjectoperandsarecalledtoperformconcatenation.Incaseofprimitives,awrapperobjectiscreatedwiththeprimitivevalueandtoStringmethodofthatobjectiscalled.(“Vel”+3willwork.)
・Beawareofassociativitywhenmultipleoperandsareinvolved.
System.out.println(1+2+“3”);//Prints33
System.out.println(“1”+2+3);//Prints123

3.Shiftoperators-<<,>>,>>>
・<<performsasignedleftshift.0bitsarebroughtinfromtheright.Signbit(MSB)ispreserved.(?)Valuebecomesoldvalue*2^xwherexisnoofbitsshifted.
・>>performsasignedrightshift.Signbitisbroughtinfromtheleft.(0ifpositive,1ifnegative.Valuebecomesoldvalue/2^xwherexisnoofbitsshifted.Alsocalledarithmeticrightshift.
・>>>performsanunsignedlogicalrightshift.0bitsarebroughtinfromtheleft.ThisoperatorexistssinceJavadoesn’tprovideanunsigneddatatype(exceptchar).>>>changesthesignofanegativenumbertobepositive.Sodon’tuseitwithnegativenumbers,ifyouwanttopreservethesign.Alsodon’tuseitwithtypessmallerthanint.(Sincetypessmallerthanintarepromotedtoanintbeforeanyshiftoperationandtheresultiscastdownagain,sotheendresultisunpredictable.)
・Shiftoperatorscanbeappliedtoonlyintegraltypes.
・-1>>1isC1,not0.
・1<<31willbecometheminimumvaluethatanintcanrepresent.
・Negativenumbersarerepresentedintwo’scomplementnotation.(Takeone’scomplementandadd1togettwo’scomplement)
・Shiftoperatorsnevershiftmorethanthenumberofbitsthetypeofresultcanhave.(i.e.int32,long64)RHSoperandisreducedtoRHS%xwherexisnoofbitsintypeofresult.
intx;
x==x>>32//ture
x=x>>33;//Hereactuallywhathappensisx>>1
・ifrightsideisnegative,forint,uselow5bits;forlong,uselow6bits.

4.ComparisonoperatorsCallreturnbooleantype.
4.1Ordinalcomparisons-<,<=,>,>=
・Onlyoperateonnumerictypes.Testtherelativevalueofthenumericoperands.
・Arithmeticpromotionsapply.charcanbecomparedtofloat.
4.2ObjecttypecomparisonCinstanceof
・Teststheclassofanobjectatruntime.Checkingisdoneatcompileandruntimesameasthecastoperator.
・ReturnstrueiftheobjectdenotedbyLHSreferencecanbecasttoRHStype.
・LHSshouldbeanobjectreferenceexpression,variableoranarrayreference.
・RHSshouldbeaclass(abstractclassesarefine),aninterfaceoranarraytype,castabletoLHSobjectreference.CompilererrorifLHS&RHSareunrelated.
・Can’tusejava.lang.ClassoritsStringnameasRHS.(?)
・ReturnstrueifLHSisaclassorsubclassofRHSclass
・ReturnstrueifLHSimplementsRHSinterface.
・ReturnstrueifLHSisanarrayreferenceandoftypeRHS.
・xinstanceofComponent[]Clegal.
・xinstanceof[]Cillegal.Can’ttestfor‘anyarrayofanytype’
・ReturnsfalseifLHSisnull,noexceptionsarethrown.
・IfxinstanceofYisnotallowedbycompiler,thenYy=(Y)xisnotavalidcastexpression.IfxinstanceofYisallowedandreturnsfalse,theabovecastisvalidbutthrowsaClassCastExceptionatruntime.IfxinstanceofYreturnstrue,theabovecastisvalidandrunsfine.
4.3Equalitycomparisons-==,!=
・Forprimitivesit’sastraightforwardvaluecomparison.(promotionsapply)
・Forobjectreferences,thisdoesn’tmakemuchsense.Useequalsmethodformeaningfulcomparisons.(Makesurethattheclassimplementsequalsinameaningfulway,likeforX.equals(Y)tobetrue,YinstanceofXmustbetrueaswell)
・ForStringliterals,==willreturntrue,thisisbecauseofcompileroptimization.
5.Bit-wiseoperators-&,^,|
・Operateonnumericandbooleanoperands.
・&-ANDoperator,bothbitsmustbe1toproduce1.
・|-ORoperator,anyonebitcanbe1toproduce1.
・^-XORoperator,anyonebitcanbe1,butnotboth,toproduce1.
・Incaseofbooleanstrueis1,falseis0.
・Order:AND,XOR,OR.
・Can’tcastanyothertypetoboolean.

6.Short-circuitlogicaloperators-&&,||
・Operateonlyonbooleantypes.
・RHSmightnotbeevaluated(hencethenameshort-circuit),iftheresultcanbedeterminedonlybylookingatLHS.
・false&&Xisalwaysfalse.
・true||Xisalwaystrue.
・RHSisevaluatedonlyiftheresultisnotcertainfromtheLHS.

7.Ternaryoperator
・Formata=x?b:c;
・xshouldbeabooleanexpression.
・Basedonx,eitherborcisevaluated.Bothareneverevaluated.
・bwillbeassignedtoaifxistrue,elsecisassignedtoa.
・bandcshouldbeassignmentcompatibletoa.
・bandcaremadeidenticalduringtheoperationaccordingtopromotions.

8.Assignmentoperators.
・Simpleassignment=.
・op=calculateandassignoperators(extendedassignmentoperators)
・*=,/=,%=,+=,-=
・x+=ymeansx=x+y.Butxisevaluatedonlyonce.Beaware.
・Assignmentofreferencevariablescopiesthereferencevalue,nottheobjectbody.
・Assignmenthasvalue,valueofLHSafterassignment.Soa=b=c=0islegal.c=0isexecutedfirst,andthevalueoftheassignment(0)assignedtob,thenthevalueofthatassignment(again0)isassignedtoa.
・Extendedassignmentoperatorsdoanimplicitcast.(Usefulwhenappliedtobyte,shortorchar)
byteb=10;
b=b+10;//Won’tcompile,explicitcastreqdsincetheexpressionevaluatestoanint
b+=10;//OK,+=doesanimplicitcastfrominttobyte

9.General
・InJava,Nooverfloworunderflowofintegershappens.i.e.Thevalueswraparound.Adding1tothemaximumintvalueresultsintheminimumvalue.
・Alwayskeepinmindthatoperandsareevaluatedfromlefttoright,andtheoperationsareexecutedintheorderofprecedenceandassociativity.
・UnaryPostfixoperatorsandallbinaryoperators(exceptassignmentoperators)havelefttorightassoiciativity.
・Allunaryoperators(exceptpostfixoperators),assignmentoperators,ternaryoperator,objectcreationandcastoperatorshaverighttoleftassoiciativity.
・Inspectthefollowingcode.
publicclassPrecedence{
finalpublicstaticvoidmain(Stringargs[]){
inti=0;
i=i++;
i=i++;
i=i++;
System.out.println(i);//prints0,since=operatorhasthelowestprecedence.

intarray[]=newint[5];
intindex=0;
array[index]=index=3;//1stelementgetassignedto3,notthe4thelement

for(intc=0;c<array.length;c++)
System.out.println(array[c]);
System.out.println("indexis"+index);//prints3
}
}

TypeofOperatorsOperatorsAssociativity
Postfixoperators[].(parameters)++--LefttoRight
PrefixUnaryoperators++--+-~!RighttoLeft
Objectcreationandcastnew(type)RighttoLeft
Multiplication/Division/Modulus*/%LefttoRight
Addition/Subtraction+-LefttoRight
Shift>>>>><<LefttoRight
Relational<<=>>=instanceofLefttoRight
Equality==!=LefttoRight
Bit-wise/BooleanAND&LefttoRight
Bit-wise/BooleanXOR^LefttoRight
Bit-wise/BooleanOR|LefttoRight
LogicalAND(Short-circuitorConditional)&&LefttoRight
LogicalOR(Short-circuitorConditional)||LefttoRight
Ternary?:RighttoLeft
Assignment=+=-=*=/=%=<<=>>=>>>=&=^=|=RighttoLeft





到时我们不用学struts,不用学spring,不用学Hibernate,只要能把jsf学会了,完全可以替代所有的框架,包括AJAX,都知道AJAX并不是新技术,虽说我没深入学习jsf但我认为jsf应该已经能通过其它技术替代AJAX,实现无缝刷新。
蒙在股里 该用户已被删除
发表于 2015-1-21 17:04:09 | 显示全部楼层
Java 编程语言的风格十分接近C、C++语言。
精灵巫婆 该用户已被删除
发表于 2015-1-24 05:58:36 | 显示全部楼层
一直感觉JAVA很大,很杂,找不到学习方向,前两天在网上找到了这篇文章,感觉不错,给没有方向的我指了一个方向,先不管对不对,做下来再说。
不帅 该用户已被删除
发表于 2015-1-26 20:10:51 | 显示全部楼层
接着就是EJB了,EJB就是Enterprise JavaBean, 看名字好象它是Javabean,可是它和Javabean还是有区别的。它是一个体系结构,你可以搭建更安全、更稳定的企业应用。它的大量代码已由中间件(也就是我们常听到的 Weblogic,Websphere这些J2EE服务器)完成了,所以我们要做的程序代码量很少,大部分工作都在设计和配置中间件上。
飘灵儿 该用户已被删除
发表于 2015-2-4 19:53:26 | 显示全部楼层
J2SE开发桌面应用软件比起 VC,VB,DEPHI这些传统开发语言来说,优势好象并不明显。J2ME对于初学者来说,好象又有点深奥,而且一般开发者很难有开发环境。
深爱那片海 该用户已被删除
发表于 2015-2-5 14:06:24 | 显示全部楼层
《JAVA语言程序设计》或《JAVA从入门到精通》这两本书开始学,等你编程有感觉的时候也可以回看一下。《JAVA读书笔记》这本书,因为讲的代码很多,也很容易看懂,涉及到面也到位。是你学习技术巩固的好书,学完后就看看《JAVA编程思想》这本书,找找一个自己写的代码跟书上的代码有什么不一样。
灵魂腐蚀 该用户已被删除
 楼主| 发表于 2015-2-12 02:23:52 | 显示全部楼层
应用在电视机、电话、闹钟、烤面包机等家用电器的控制和通信。由于这些智能化家电的市场需求没有预期的高,Sun公司放弃了该项计划。随着1990年代互联网的发展
乐观 该用户已被删除
发表于 2015-2-17 21:03:49 | 显示全部楼层
Sun公司看见Oak在互联网上应用的前景,于是改造了Oak,于1995年5月以Java的名称正式发布。Java伴随着互联网的迅猛发展而发展,逐渐成为重要的网络编程语言。
谁可相欹 该用户已被删除
发表于 2015-3-1 04:23:43 | 显示全部楼层
Java是一个纯的面向对象的程序设计语言,它继承了 C++语言面向对象技术的核心。Java舍弃了C ++语言中容易引起错误的指针(以引用取代)、运算符重载(operator overloading)
因胸联盟 该用户已被删除
发表于 2015-3-1 09:36:29 | 显示全部楼层
Jive的资料在很多网站上都有,大家可以找来研究一下。相信你读完代码后,会有脱胎换骨的感觉。遗憾的是Jive从2.5以后就不再无条件的开放源代码,同时有licence限制。不过幸好还有中国一流的Java程序员关注它,外国人不开源了,中国人就不能开源吗?这里向大家推荐一个汉化的Jive版本—J道。Jive(J道版)是由中国Java界大名 鼎鼎的banq在Jive 2.1版本基础上改编而成, 全中文,增加了一些实用功能,如贴图,用户头像和用户资料查询等,而且有一个开发团队在不断升级。你可以访问banq的网站
海妖 该用户已被删除
发表于 2015-3-10 13:07:12 | 显示全部楼层
我大二,Java也只学了一年,觉得还是看thinking in java好,有能力的话看英文原版(中文版翻的不怎么好),还能提高英文文档阅读能力。
再现理想 该用户已被删除
发表于 2015-3-16 06:33:33 | 显示全部楼层
是一种简化的C++语言 是一种安全的语言,具有阻绝计算机病毒传输的功能
兰色精灵 该用户已被删除
发表于 2015-3-22 20:28:00 | 显示全部楼层
我大二,Java也只学了一年,觉得还是看thinking in java好,有能力的话看英文原版(中文版翻的不怎么好),还能提高英文文档阅读能力。
再见西城 该用户已被删除
发表于 2015-4-16 00:10:22 | 显示全部楼层
一般学编程语言都是从C语开始学的,我也不例外,但还是可能不学过程语言而直接学面向对象语言的,你是刚接触语言,还是从C开始学比较好,基础会很深点,如果你直接学习JAVA也能上手,一般大家在学语言的时候都记一些语言的关键词,常有的包和接口等。再去做逻辑代码的编写,以后的学习过程都是从逻辑代码编写中提升的,所以这方面都是经验积累的。你要开始学习就从
变相怪杰 该用户已被删除
发表于 2015-4-21 15:51:58 | 显示全部楼层
自从Sun推出Java以来,就力图使之无所不包,所以Java发展到现在,按应用来分主要分为三大块:J2SE,J2ME和J2EE,这也就是Sun ONE(Open Net Environment)体系。J2SE就是Java2的标准版,主要用于桌面应用软件的编程;J2ME主要应用于嵌入是系统开发,如手机和PDA的编程;J2EE是Java2的企业版,主要用于分布式的网络程序的开发,如电子商务网站和ERP系统。
发表于 2015-6-10 15:40:46 | 显示全部楼层
是一种突破用户端机器环境和CPU
小魔女 该用户已被删除
发表于 2015-6-14 11:44:37 | 显示全部楼层
一般学编程语言都是从C语开始学的,我也不例外,但还是可能不学过程语言而直接学面向对象语言的,你是刚接触语言,还是从C开始学比较好,基础会很深点,如果你直接学习JAVA也能上手,一般大家在学语言的时候都记一些语言的关键词,常有的包和接口等。再去做逻辑代码的编写,以后的学习过程都是从逻辑代码编写中提升的,所以这方面都是经验积累的。你要开始学习就从
飘飘悠悠 该用户已被删除
发表于 2015-7-26 12:20:37 | 显示全部楼层
关于设计模式的资料,还是向大家推荐banq的网站 [url]http://www.jdon.com/[/url],他把GOF的23种模式以通俗易懂的方式诠释出来,纯Java描述,真是经典中的经典。
山那边是海 该用户已被删除
发表于 2015-7-28 17:52:12 | 显示全部楼层
Java自面世后就非常流行,发展迅速,对C++语言形成了有力冲击。Java 技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于个人PC、数据中心、游戏控制台
若相依 该用户已被删除
发表于 2015-9-27 11:17:50 | 显示全部楼层
自从Sun推出Java以来,就力图使之无所不包,所以Java发展到现在,按应用来分主要分为三大块:J2SE,J2ME和J2EE,这也就是Sun ONE(Open Net Environment)体系。J2SE就是Java2的标准版,主要用于桌面应用软件的编程;J2ME主要应用于嵌入是系统开发,如手机和PDA的编程;J2EE是Java2的企业版,主要用于分布式的网络程序的开发,如电子商务网站和ERP系统。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-3-29 08:50

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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