java英语面试题大集合(网上搜索整理)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

1java英语面试题*Q1.HowcouldJavaclassesdirectprogrammessagestothesystemconsole,buterrormessages,saytoafile?.TheclassSystemhasavariableoutthatrepresentsthestandardoutput,andthevariableerrthatrepresentsthestandarderrordevice.Bydefault,theybothpointatthesystemconsole.Thishowthestandardoutputcouldbere-directed:Streamst=newStream(newFileOutputStream(output.txt));System.setErr(st);System.setOut(st);*Q2.What'sthedifferencebetweenaninterfaceandanabstractclass?A.Anabstractclassmaycontaincodeinmethodbodies,whichisnotallowedinaninterface.Withabstractclasses,youhavetoinherityourclassfromitandJavadoesnotallowmultipleinheritance.Ontheotherhand,youcanimplementmultipleinterfacesinyourclass.*Q3.Whywouldyouuseasynchronizedblockvs.synchronizedmethod?A.Synchronizedblocksplacelocksforshorterperiodsthansynchronizedmethods.*Q4.Explaintheusageofthekeywordtransient?A.Thiskeywordindicatesthatthevalueofthismembervariabledoesnothavetobeserializedwiththeobject.Whentheclasswillbede-serialized,thisvariablewillbeinitializedwithadefaultvalueofitsdatatype(i.e.zeroforintegers).*Q5.Howcanyouforcegarbagecollection?A.Youcan'tforceGC,butcouldrequestitbycallingSystem.gc().JVMdoesnotguaranteethatGCwillbestartedimmediately.*Q6.Howdoyouknowifanexplicitobjectcastingisneeded?A.Ifyouassignasuperclassobjecttoavariableofasubclass'sdatatype,youneedtodoexplicitcasting.Forexample:Objecta;Customerb;b=(Customer)a;Whenyouassignasubclasstoavariablehavingasupeclasstype,thecastingisperformedautomatically.*Q7.What'sthedifferencebetweenthemethodssleep()andwait()A.Thecodesleep(1000);putsthreadasideforexactlyonesecond.Thecodewait(1000),causesawaitofuptoonesecond.Athreadcouldstopwaitingearlierifitreceivesthenotify()ornotifyAll()call.Themethodwait()isdefinedintheclassObjectandthemethodsleep()isdefinedintheclassThread.*Q8.CanyouwriteaJavaclassthatcouldbeusedbothasanappletaswellasanapplication?A.Yes.Addamain()methodtotheapplet.*Q9.What'sthedifferencebetweenconstructorsandothermethods?A.Constructorsmusthavethesamenameastheclassandcannotreturnavalue.Theyareonly2calledoncewhileregularmethodscouldbecalledmanytimes.*Q10.CanyoucalloneconstructorfromanotherifaclasshasmultipleconstructorsA.Yes.Usethis()syntax.*Q11.ExplaintheusageofJavapackages.A.Thisisawaytoorganizefileswhenaprojectconsistsofmultiplemodules.Italsohelpsresolvenamingconflictswhendifferentpackageshaveclasseswiththesamenames.Packagesaccesslevelalsoallowsyoutoprotectdatafrombeingusedbythenon-authorizedclasses.*Q12.Ifaclassislocatedinapackage,whatdoyouneedtochangeintheOSenvironmenttobeabletouseit?A.YouneedtoaddadirectoryorajarfilethatcontainsthepackagedirectoriestotheCLASSPATHenvironmentvariable.Let'ssayaclassEmployeebelongstoapackagecom.xyz.hr;andislocatedinthefilec:\dev\com\xyz\hr\Employee.java.Inthiscase,you'dneedtoaddc:\devtothevariableCLASSPATH.Ifthisclasscontainsthemethodmain(),youcouldtestitfromacommandpromptwindowasfollows:c:\javacom.xyz.hr.Employee*Q13.What'sthedifferencebetweenJ2SDK1.5andJ2SDK5.0?A.There'snodifference,SunMicrosystemsjustre-brandedthisversion.*Q14.WhatwouldyouusetocomparetwoStringvariables-theoperator==orthemethodequals()?A.I'dusethemethodequals()tocomparethevaluesoftheStringsandthe==tocheckiftwovariablespointatthesameinstanceofaStringobject.*Q15.DoesitmatterinwhatordercatchstatementsforFileNotFoundExceptionandIOExceptiponarewritten?A.Yes,itdoes.TheFileNoFoundExceptionisinheritedfromtheIOException.Exception'ssubclasseshavetobecaughtfirst.Q16.Whatismoreadvisabletocreateathread,byimplementingaRunnableinterfaceorbyextendingThreadclass?(donatedinJune2005)A.Strategicallyspeaking,threadscreatedbyimplementingRunnableinterfacearemoreadvisable.Ifyoucreateathreadbyextendingathreadclass,youcannotextendanyotherclass.IfyoucreateathreadbyimplementingRunnableinterface,yousaveaspaceforyourclasstoextendanotherclassnoworinfuture.Q17.Anapplicationneedstoloadalibrarybeforeitstartstorun,howtocode?Oneoptionistouseastaticblocktoloadalibrarybeforeanythingiscalled.Forexample,classTest{static{System.loadLibrary(path-to-library-file);}3....}WhenyoucallnewTest(),thestaticblockwillbecalledfirstbeforeanyinitializationhappens.Notethatthestaticblockpositionmaymatter.Q18.WhatisthemaindifferencebetweenJavaplatformandotherplatforms?TheJavaplatformdiffersfrommostotherplatformsinthatit'sasoftware-onlyplatformthatrunsontopofotherhardware-basedplatforms.TheJavaplatformhastwocomponents:1.TheJavaVirtualMachine(JavaVM)2.TheJavaApplicationProgrammingInterface(JavaAPI)Q19.WhatistheJavaVirtualMachine?TheJavaVirtualMachineisasoftwarethatcanbeportedontovarioushardware-basedplatforms.Q20.WhatistheJavaAPI?TheJavaAPIisalargecollectionofready-madesoftwarecomponentsthatprovidemanyusefulcapabilities,suchasgraphicaluserinterface(GUI)widgets.Q21.Whatisthepackage?ThepackageisaJavanamespaceorpartofJavalibraries.TheJavaAPIisgroupedintolibrariesofrelatedclassesandinterfaces;theselibrariesareknownaspackages.Q22.Whatisnativecode?Thenativecodeiscodethatafteryoucompileit,thecompiledcoderunsonaspecifichardwareplatform.Q23.Canmain()methodbeoverloaded?Yes.themai

1 / 32
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功