java+英文面试题.docx
- 文档编号:7187391
- 上传时间:2023-01-21
- 格式:DOCX
- 页数:23
- 大小:40.83KB
java+英文面试题.docx
《java+英文面试题.docx》由会员分享,可在线阅读,更多相关《java+英文面试题.docx(23页珍藏版)》请在冰豆网上搜索。
java+英文面试题
Question:
NamethecontainerswhichusesBorderLayoutastheirdefaultlayout?
Answer:
ContainerswhichusesBorderLayoutastheirdefaultare:
window,FrameandDialogclasses.
Question:
WhatdoyouunderstandbySynchronization?
Answer:
Synchronizationisaprocessofcontrollingtheaccessofsharedresourcesbythemultiplethreadsinsuchamannerthatonlyonethreadcanaccessoneresourceatatime.Innonsynchronizedmultithreadedapplication,itispossibleforonethreadtomodifyasharedobjectwhileanotherthreadisintheprocessofusingorupdatingtheobject'svalue.Synchronizationpreventssuchtypeofdatacorruption.
E.g.Synchronizingafunction:
publicsynchronizedvoidMethod1(){
//Appropriatemethod-relatedcode.
}
E.g.Synchronizingablockofcodeinsideafunction:
publicmyFunction(){
synchronized(this){
//Synchronizedcodehere.
}
}
Question:
WhatisCollectionAPI?
Answer:
TheCollectionAPIisasetofclassesandinterfacesthatsupportoperationoncollectionsofobjects.Theseclassesandinterfacesaremoreflexible,morepowerful,andmoreregularthanthevectors,arrays,andhashtablesifeffectivelyreplaces.
Exampleofclasses:
HashSet,HashMap,ArrayList,LinkedList,TreeSetandTreeMap.
Exampleofinterfaces:
Collection,Set,ListandMap.
Question:
IsIteratoraClassorInterface?
Whatisitsuse?
Answer:
IteratorisaninterfacewhichisusedtostepthroughtheelementsofaCollection.
Question:
Whatissimilarities/differencebetweenanAbstractclassandInterface?
Answer:
Differencesareasfollows:
∙Interfacesprovideaformofmultipleinheritance.Aclasscanextendonlyoneotherclass.
∙Interfacesarelimitedtopublicmethodsandconstantswithnoimplementation.Abstractclassescanhaveapartialimplementation,protectedparts,staticmethods,etc.
∙AClassmayimplementseveralinterfaces.Butincaseofabstractclass,aclassmayextendonlyoneabstractclass.
∙Interfacesareslowasitrequiresextraindirectiontotofindcorrespondingmethodinintheactualclass.Abstractclassesarefast.
Similarities:
∙NeitherAbstractclassesorInterfacecanbeinstantiated.
Question:
HowtodefineanAbstractclass?
Answer:
AclasscontainingabstractmethodiscalledAbstractclass.AnAbstractclasscan'tbeinstantiated.
ExampleofAbstractclass:
abstractclasstestAbstractClass{
protectedStringmyString;
publicStringgetMyString(){
returnmyString;
}
publicabstractstringanyAbstractFunction();
}
Question:
HowtodefineanInterface?
Answer:
InJavaInterfacedefinesthemethodsbutdoesnotimplementthem.Interfacecanincludeconstants.AclassthatimplementstheinterfacesisboundtoimplementallthemethodsdefinedinInterface.
EmapleofInterface:
publicinterfacesampleInterface{
publicvoidfunctionOne();
publiclongCONSTANT_ONE=1000;
}
Question:
ExplaintheuserdefinedExceptions?
Answer:
UserdefinedExceptionsaretheseparateExceptionclassesdefinedbytheuserforspecificpurposed.Anuserdefinedcancreatedbysimplysub-classingittotheExceptionclass.Thisallowscustomexceptionstobegenerated(usingthrow)andcaughtinthesamewayasnormalexceptions.
Example:
classmyCustomExceptionextendsException{
//Theclasssimplyhastoexisttobeanexception
}
Question:
ExplainthenewFeaturesofJDBC2.0CoreAPI?
Answer:
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.
Question:
Explaingarbagecollection?
Answer:
GarbagecollectionisoneofthemostimportantfeatureofJava.GarbagecollectionisalsocalledautomaticmemorymanagementasJVMautomaticallyremovestheunusedvariables/objects(valueisnull)fromthememory.Userprogramcann'tdirectlyfreetheobjectfrommemory,insteaditisthejobofthegarbagecollectortoautomaticallyfreetheobjectsthatarenolongerreferencedbyaprogram.Everyclassinheritsfinalize()methodfromjava.lang.Object,thefinalize()methodiscalledbygarbagecollectorwhenitdeterminesnomorereferencestotheobjectexists.InJava,itisgoodideatoexplicitlyassignnullintoavariablewhennomoreinuse.IJavaoncallingSystem.gc()andRuntime.gc(), JVMtriestorecycletheunusedobjects,butthereisnoguaranteewhenalltheobjectswillgarbagecollected.
Question:
Howyoucanforcethegarbagecollection?
Answer:
Garbagecollectionautomaticprocessandcan'tbeforced.
Question:
WhatisOOPS?
Answer:
OOPisthecommonabbreviationforObject-OrientedProgramming.
Question:
DescribetheprinciplesofOOPS.
Answer:
TherearethreemainprincipalsofoopswhicharecalledPolymorphism,InheritanceandEncapsulation.
Question:
ExplaintheEncapsulationprinciple.
Answer:
Encapsulationisaprocessofbindingorwrappingthedataandthecodesthatoperatesonthedataintoasingleentity.Thiskeepsthedatasafefromoutsideinterfaceandmisuse.Onewaytothinkaboutencapsulationisasaprotectivewrapperthatpreventscodeanddatafrombeingarbitrarilyaccessedbyothercodedefinedoutsidethewrapper.
Question:
ExplaintheInheritanceprinciple.
Answer:
Inheritanceistheprocessbywhichoneobjectacquiresthepropertiesofanotherobject.
Question:
ExplainthePolymorphismprinciple.
Answer:
ThemeaningofPolymorphismissomethinglikeonenamemanyforms.Polymorphismenablesoneentitytobeusedasasgeneralcategoryfordifferenttypesofactions.Thespecificactionisdeterminedbytheexactnatureofthesituation.Theconceptofpolymorphismcanbeexplainedas"oneinterface,multiplemethods".
Question:
ExplainthedifferentformsofPolymorphism.
Answer:
Fromapracticalprogrammingviewpoint,polymorphismexistsinthreedistinctformsinJava:
从一个实际编程的观点来看,多态存在于三种截然不同的形式,
∙Methodoverloading
∙Methodoverridingthroughinheritance
∙MethodoverridingthroughtheJavainterface
Question:
WhatareAccessSpecifiersavailableinJava?
Answer:
Accessspecifiersarekeywordsthatdeterminesthetypeofaccesstothememberofaclass.Theseare:
∙Public
∙Protected
∙Private
∙Defaults
Question:
DescribethewrapperclassesinJava.
Answer:
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
Question:
Readthefollowingprogram:
publicclasstest{
publicstaticvoidmain(String[]args){
intx=3;
inty=1;
if(x=y)
System.out.println("Notequal");
else
System.out.println("Equal");
}
}
Whatistheresult?
A.Theoutputis揈qual?
br> B.Theoutputin揘otEqual?
br> C.Anerrorat"if(x=y)"causescompilationtofall.
D.Theprogramexecutesbutnooutputisshowonconsole.
Answer:
C
Question:
whatistheclassvariables?
什么是类变量?
Answer:
Whenwecreateanumberofobjectsofthesameclass,theneachobjectwillshareacommoncopyofvariables.Thatmeansthatthereisonlyonecopyperclass,nomatterhowmanyobjectsarecreatedfromit.Classvariablesorstaticvariablesaredeclaredwiththestatickeywordinaclass,butminditthatitshouldbedeclaredoutsideoutsideaclass.Thesevariablesarestoredinstaticmemory.Classvariablesaremostlyusedforconstants,variablethatneverchangeitsinitialvalue.Staticvariablesarealwayscalledbytheclassname.Thisvariableiscreatedwhentheprogramstartsi.e.itiscreatedbeforetheinstanceiscreatedofclassbyusingnewoperatorandgetsdestroyedwhentheprogramsstops.Thescopeoftheclassvariableissameainstancevariable.Theclassvariablecanbedefinedanywhereatclasslevelwiththekeywordstatic.Itinitialvalueissameasinstancevariable.Whentheclassvariableisdefinedasintthenit'sinitialvalueisbydefaultzero,whendeclaredbooleanitsdefaultvalueisfalseandnullforobjectreferences.Classvariablesareassociatedwiththeclass,ratherthanwithanyobject.
Question:
Whatisthedifferencebetweentheinstanceofandgetclass,thesetwoaresameornot?
Answer:
instanceofisaoperator,notafunctionwhilegetClassisamethodofjava.lang.Objectclass.Consideraconditionwhereweuse
if(o.getClass().getName().equals("java.lang.Math")){}
Thismethodonlychecksiftheclassnamewehavepassedisequaltojava.lang.Math.Theclassjava.lang.MathisloadedbythebootstrapClassLoader.Thisclassisanabstractclass.Thisclassloaderisresponsibleforloadingclasses.E
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java 英文 试题