Java英文面试题经典.docx
《Java英文面试题经典.docx》由会员分享,可在线阅读,更多相关《Java英文面试题经典.docx(20页珍藏版)》请在冰豆网上搜索。
![Java英文面试题经典.docx](https://file1.bdocx.com/fileroot1/2022-10/20/98f81b10-2b83-4822-ba3e-49665ea02a11/98f81b10-2b83-4822-ba3e-49665ea02a111.gif)
Java英文面试题经典
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.