java+英文面试题Word文档格式.docx
《java+英文面试题Word文档格式.docx》由会员分享,可在线阅读,更多相关《java+英文面试题Word文档格式.docx(23页珍藏版)》请在冰豆网上搜索。
E.g.Synchronizingablockofcodeinsideafunction:
publicmyFunction(){
synchronized(this){
//Synchronizedcodehere.
}
WhatisCollectionAPI?
TheCollectionAPIisasetofclassesandinterfacesthatsupportoperationoncollectionsofobjects.Theseclassesandinterfacesaremoreflexible,morepowerful,andmoreregularthanthevectors,arrays,andhashtablesifeffectivelyreplaces.
Exampleofclasses:
HashSet,HashMap,ArrayList,LinkedList,TreeSetandTreeMap.
Exampleofinterfaces:
Collection,Set,ListandMap.
IsIteratoraClassorInterface?
Whatisitsuse?
IteratorisaninterfacewhichisusedtostepthroughtheelementsofaCollection.
Whatissimilarities/differencebetweenanAbstractclassandInterface?
Differencesareasfollows:
∙Interfacesprovideaformofmultipleinheritance.Aclasscanextendonlyoneotherclass.
∙Interfacesarelimitedtopublicmethodsandconstantswithnoimplementation.Abstractclassescanhaveapartialimplementation,protectedparts,staticmethods,etc.
∙AClassmayimplementseveralinterfaces.Butincaseofabstractclass,aclassmayextendonlyoneabstractclass.
∙Interfacesareslowasitrequiresextraindirectiontotofindcorrespondingmethodinintheactualclass.Abstractclassesarefast.
Similarities:
∙NeitherAbstractclassesorInterfacecanbeinstantiated.
HowtodefineanAbstractclass?
AclasscontainingabstractmethodiscalledAbstractclass.AnAbstractclasscan'
tbeinstantiated.
ExampleofAbstractclass:
abstractclasstestAbstractClass{
protectedStringmyString;
publicStringgetMyString(){
returnmyString;
}
publicabstractstringanyAbstractFunction();
HowtodefineanInterface?
InJavaInterfacedefinesthemethodsbutdoesnotimplementthem.Interfacecanincludeconstants.AclassthatimplementstheinterfacesisboundtoimplementallthemethodsdefinedinInterface.
EmapleofInterface:
publicinterfacesampleInterface{
publicvoidfunctionOne();
publiclongCONSTANT_ONE=1000;
ExplaintheuserdefinedExceptions?
UserdefinedExceptionsaretheseparateExceptionclassesdefinedbytheuserforspecificpurposed.Anuserdefinedcancreatedbysimplysub-classingittotheExceptionclass.Thisallowscustomexceptionstobegenerated(usingthrow)andcaughtinthesamewayasnormalexceptions.
Example:
classmyCustomExceptionextendsException{
//Theclasssimplyhastoexisttobeanexception
}
ExplainthenewFeaturesofJDBC2.0CoreAPI?
TheJDBC2.0APIincludesthecompleteJDBCAPI,whichincludesbothcoreandOptionalPackageAPI,andprovidesinductrial-strengthdatabasecomputingcapabilities.
NewFeaturesinJDBC2.0CoreAPI:
∙Scrollableresultsets-usingnewmethodsintheResultSetinterfaceallowsprogrammaticallymovethetoparticularrowortoapositionrelativetoitscurrentposition
∙JDBC2.0CoreAPIprovidestheBatchUpdatesfunctionalitytothejavaapplications.
∙JavaapplicationscannowusetheResultSet.updateXXXmethods.
∙Newdatatypes-interfacesmappingtheSQL3datatypes
∙Custom
mappingofuser-definedtypes(UTDs)
∙Miscellaneousfeatures,includingperformancehints,theuseofcharacterstreams,fullprecisionforjava.math.BigDecimalvalues,additionalsecurity,andsupportfortimezonesindate,time,andtimestampvalues.
Explaingarbagecollection?
GarbagecollectionisoneofthemostimportantfeatureofJava.GarbagecollectionisalsocalledautomaticmemorymanagementasJVMautomaticallyremovestheunusedvariables/objects(valueisnull)fromthememory.Userprogramcann'
tdirectlyfreetheobjectfrommemory,insteaditisthejobofthegarbagecollectortoautomaticallyfreetheobjectsthatarenolongerreferencedbyaprogram.Everyclassinheritsfinalize()methodfromjava.lang.Object,thefinalize()methodiscalledbygarbagecollectorwhenitdeterminesnomorereferencestotheobjectexists.InJava,itisgoodideatoexplicitlyassignnullintoavariablewhennomoreinuse.IJavaoncallingSystem.gc()andRuntime.gc(),
JVMtriestorecycletheunusedobjects,butthereisnoguaranteewhenalltheobjectswillgarbagecollected.
Howyoucanforcethegarbagecollection?
Garbagecollectionautomaticprocessandcan'
tbeforced.
WhatisOOPS?
OOPisthecommonabbreviationforObject-OrientedProgramming.
DescribetheprinciplesofOOPS.
TherearethreemainprincipalsofoopswhicharecalledPolymorphism,InheritanceandEncapsulation.
ExplaintheEncapsulationprinciple.
Encapsulationisaprocessofbindingorwrappingthedataandthecodesthatoperatesonthedataintoasingleentity.Thiskeepsthedatasafefromoutsideinterfaceandmisuse.Onewaytothinkaboutencapsulationisasaprotectivewrapperthatpreventscodeanddatafrombeingarbitrarilyaccessedbyothercodedefinedoutsidethewrapper.
ExplaintheInheritanceprinciple.
Inheritanceistheprocessbywhichoneobjectacquiresthepropertiesofanotherobject.
ExplainthePolymorphismprinciple.
ThemeaningofPolymorphismissomethinglikeonenamemanyforms.Polymorphismenablesoneentitytobeusedasasgeneralcategoryfordifferenttypesofactions.Thespecificactionisdeterminedbytheexactnatureofthesituation.Theconceptofpolymorphismcanbeexplainedas"
oneinterface,multiplemethods"
.
ExplainthedifferentformsofPolymorphism.
Fromapracticalprogrammingviewpoint,polymorphismexistsinthreedistinctformsinJava:
从一个实际编程的观点来看,多态存在于三种截然不同的形式,
∙Methodoverloading
∙Methodoverridingthroughinheritance
∙MethodoverridingthroughtheJavainterface
WhatareAccessSpecifiersavailableinJava?
Accessspecifiersarekeywordsthatdeterminesthetypeofaccesstothememberofaclass.Theseare:
∙Public
∙Protected
∙Private
∙Defaults
DescribethewrapperclassesinJava.
Wrapperclassiswrapperaroundaprimitivedatatype.Aninstanceofawrapperclasscontains,orwraps,aprimitivevalueofthecorrespondingtype.
Followingtableliststheprimitivetypesandthecorrespondingwrapperclasses:
Primitive
Wrapper
boolean
java.lang.Boolean
byte
java.lang.Byte
char
java.lang.Character
double
java.lang.Double
float
java.lang.Float
int
java.lang.Integer
long
java.lang.Long
short
java.lang.Short
void
java.lang.Void
Readthefollowingprogram:
publicclasstest{
publicstaticvoidmain(String[]args){
intx=3;
inty=1;
if(x=y)
System.out.println("
Notequal"
);
else
Equal"
Whatistheresult?
A.Theoutputis揈qual?
br>
B.Theoutputin揘otEqual?
C.Anerrorat"
if(x=y)"
causescompilationtofall.
D.Theprogramexecutesbutnooutputisshowonconsole.
C
whatistheclassvariables?
什么是类变量?
Whenwecreateanumberofobjectsofthesameclass,theneachobjectwillshareacommoncopyofvariables.Thatmeansthatthereisonlyonecopyperclass,nomatterhowmanyobjectsarecreatedfromit.Classvariablesorstaticvariablesaredeclaredwiththestatickeywordinaclass,butminditthatitshouldbedeclaredoutsideoutsideaclass.Thesevariablesarestoredinstaticmemory.Classvariablesaremostlyusedforconstants,variablethatneverchangeitsinitialvalue.Staticvariablesarealwayscalledbytheclassname.Thisvariableiscreatedwhentheprogramstartsi.e.itiscreatedbeforetheinstanceiscreatedofclassbyusingnewoperatorandgetsdestroyedwhentheprogramsstops.Thescopeoftheclassvariableissameainstancevariable.Theclassvariablecanbedefinedanywhereatclasslevelwiththekeywordstatic.Itinitialvalueissameasinstancevariable.Whentheclassvariableisdefinedasintthenit'
sinitialvalueisbydefaultzero,whendeclaredbooleanitsdefaultvalueisfalseandnullforobjectreferences.Classvariablesareassociatedwiththeclass,ratherthanwithanyobject.
Whatisthedifferencebetweentheinstanceofandgetclass,thesetwoaresameornot?
instanceofisaoperator,notafunctionwhilegetClassisamethodofjava.lang.Objectclass.Consideraconditionwhereweuse
if(o.getClass().getName().equals("
java.lang.Math"
)){}
Thismethodonlychecksiftheclassnamewehavepassedisequaltojava.lang.Math.Theclassjava.lang.MathisloadedbythebootstrapClassLoader.Thisclassisanabstractclass.Thisclassloaderisresponsibleforloadingclasses.E