您的位置:首页 > 理论基础 > 计算机网络

在Linux中实现https访问站点

2012-08-22 13:00 453 查看
1)Thetokenizerisagreedytokenizer.Itgrabsasmanycharactersasitcantobuildupthenexttoken,notcaringifthiscreatesaninvalidseuenceoftokens.
publicclassTest{ publicstaticvoidmain(String[]args){ inti=1; inta=i+++i;//equalsto:i+++i System.out.println(a); } }

2)Everytype(primitiveorreference)hasanassociatedinstanceofclassClassthatrepresentsthattype.Theseinstancesareoftenreferredtoastheclassobjectforagiventype.Youcannametheclassobjectforatypedirectlybyfollowingthetypenamewith".class",asin
String.class
java.lang.String.class
java.util.Iterator.class
boolean.class
SinceclassClassisgeneric,theactualtypeoftheclassliteralforareferencetypeTisClass<T>,whileforprimitivetypesitisClass<W>whereWisthewrapperclassfor
thatprimitivetype.Butnote,forexample,thatboolean.classandBoolean.classaretwodifferentobjectsoftypeClass<Boolean>.
Example:

publicclassClassObject{ publicstaticvoidmain(String[]args){ System.out.println(java.lang.String.class.toString()); } }
Output:
classjava.lang.String

3)Youcandefertheinitializationofafinalfieldorlocalvariable.Suchafinalvariableiscalledablankfinal.Ablankfinalfieldmustbeinitializedwithinaninitializationblockorconstructor(ifit'saninstancefield)whileablankfinallocalvariable,likeanylocalvariable,mustbeinitializedbeforeitisused.
Thecompilerwillverifythatallstaticfinalfieldsareinitializedbytheendofanystaticinitializerblocks,andthatnon-staticfinalfieldsareinitializedbytheendofallconstructionpathsforanobject.Acompile-timeerrorwilloccurifthecompilercannotdeterminethatthishappens.
4)Anarrayobject’slengthisfixedatitscreationandcannotbechanged.Butanewarrayofadifferentsizecouldbeassignedtothearrayvariableatanytime.

int[]ia=newint[3];
intia[]=newint[3];
theprevioustwostatementsareequivalent,however,theformeroneispreferable.
Theimportantthingtorememberisthatthemodifiersapplytothearrayvariablenottotheelementsofthearraythevariablereferences.
5)MultidimensionalArray:

float[][]mat=newfloat[4][4];


Thefirst(left-most)dimensionofanarraymustbespecifiedwhenthearrayiscreated.Otherdimensionscanbeleftunspecified,tobefilledinlater.

float[][]mat=newfloat[4][];
for(inty=0;y<mat.length;y++)
mat[y]=newfloat[4];

6)ArraysareimplicitextensionsofObject.GivenaclassX,classesYandZthatextendX,andarraysofeach,theclasshierarchylookssomethinglikethis:





Thisclassrelationshipallowspolymorphismforarrays.YoucanassignanarraytoavariableoftypeObjectandcastitback.AnarrayofobjectsoftypeYisusablewhereveranarrayofobjectsofitssupertypeXisrequired.Thisseemsnaturalbutcanrequirearuntimecheckthatissometimesunexpected.AnarrayofXcancontaineitherYorZreferences,butanarrayofYcannotcontainreferencestoXorZobjects.ThefollowingcodewouldgenerateanArrayStoreExceptionatruntimeoneitherofitsfinaltwolines,whichviolatethisrule:

Y[]yArray=newY[3];//aYarray
X[]xArray=yArray;//valid:YisassignabletoX
xArray[0]=newY();
xArray[2]=newX();//INVALID:can'tstoreXinY[]
xArray[1]=newZ();//INVALID:can'tstoreZinY[]


Likeanyotherobject,arraysarecreatedandaresubjecttonormalgarbagecollectionmechanisms.TheyinheritallthemethodsofObjectandadditionallyimplementtheCloneableinterfaceandtheSerializableinterface.
7)
Toavoidconfusion,hidingisnotpermittedinnestedscopeswithinacodeblock.Thismeansthatalocalvariableinamethodcannothavethesamenameasaparameterofthatmethod;thataforloopvariablecannothavethesamenameasalocalvariableorparameter;andthatoncethereisalocalvariablecalled,say,über,youcannotcreateanew,differentvariablewiththenameüberinanestedblock.
Example1:

{
intüber=0;
{
intüber=2;//INVALID:alreadydefined
//...
}
}


Example2:

voidprint(intval){
for(inti=0;i<100;++i){
intval=100;//invalid:Duplicatelocalvariableval
}
}
Example3:

voidprint(){
intval=1;
for(inti=0;i<100;++i){
intval=100;//invalid:Duplicatelocalvariableval
}
}
Example4:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: