Java英文面试题经典docx.docx
- 文档编号:13472578
- 上传时间:2023-06-14
- 格式:DOCX
- 页数:26
- 大小:53.33KB
Java英文面试题经典docx.docx
《Java英文面试题经典docx.docx》由会员分享,可在线阅读,更多相关《Java英文面试题经典docx.docx(26页珍藏版)》请在冰点文库上搜索。
Java英文面试题经典docx
Java-英文面试题-经典
英文Java面试题
Question:
Whatistransientvariable?
Answer:
Transientvariablecan'tbeserialize.ForexampleifavariableisdeclaredastransientinaSerializableclassandtheclassiswrittentoanObjectStream,thevalueofthevariablecan'tbewrittentothestreaminsteadwhentheclassisretrievedfromtheObjectStreamthevalueofthevariablebecomesnull.
Question:
NamethecontainerswhichusesBorderLayoutastheirdefaultlayout?
Answer:
ContainerswhichusesBorderLayoutastheirdefaultare:
window,FrameandDialogclasses.
Question:
WhatdoyouunderstandbySynchronization?
Answer:
Synchronizationisaprocessofcontrollingtheaccessofsharedresources
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.
Interfacesareslowasitrequiresextraindirectiontofindcorrespondingmethodintheactualclass.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
Custommappingofuser-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:
PrimitiveWrapper
booleanjava.lang.Boolean
bytejava.lang.Byte
charjava.lang.Character
doublejava.lang.Double
floatjava.lang.Float
intjava.lang.Integer
longjava.lang.Long
shortjava.lang.Short
voidjava.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.Theoutputisequal?
br>B.TheoutputinnotEqual?
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.EveryClassobjectcontainsareferencetotheClassLoaderthatdefines.getClass()methodreturnstheruntimeclassofanobject.Itfetchesthejavainstanceofthegivenfullyqualifiedtypename.Thecodewehavewrittenisnotnecessary,becauseweshouldnotcomparegetClass.getName().ThereasonbehinditisthatifthetwodifferentclassloadersloadthesameclassbutfortheJVM,itwillconsiderbothclassesasdifferentclassesso,wecan'tcompare
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 英文 试题 经典 docx