java+英文面试题Word文档格式.docx

上传人:b****5 文档编号:20288074 上传时间:2023-01-21 格式:DOCX 页数:23 大小:40.83KB
下载 相关 举报
java+英文面试题Word文档格式.docx_第1页
第1页 / 共23页
java+英文面试题Word文档格式.docx_第2页
第2页 / 共23页
java+英文面试题Word文档格式.docx_第3页
第3页 / 共23页
java+英文面试题Word文档格式.docx_第4页
第4页 / 共23页
java+英文面试题Word文档格式.docx_第5页
第5页 / 共23页
点击查看更多>>
下载资源
资源描述

java+英文面试题Word文档格式.docx

《java+英文面试题Word文档格式.docx》由会员分享,可在线阅读,更多相关《java+英文面试题Word文档格式.docx(23页珍藏版)》请在冰豆网上搜索。

java+英文面试题Word文档格式.docx

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

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 小学教育 > 其它课程

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1