Java 面试题集.docx

上传人:b****8 文档编号:30057325 上传时间:2023-08-04 格式:DOCX 页数:35 大小:34.43KB
下载 相关 举报
Java 面试题集.docx_第1页
第1页 / 共35页
Java 面试题集.docx_第2页
第2页 / 共35页
Java 面试题集.docx_第3页
第3页 / 共35页
Java 面试题集.docx_第4页
第4页 / 共35页
Java 面试题集.docx_第5页
第5页 / 共35页
点击查看更多>>
下载资源
资源描述

Java 面试题集.docx

《Java 面试题集.docx》由会员分享,可在线阅读,更多相关《Java 面试题集.docx(35页珍藏版)》请在冰豆网上搜索。

Java 面试题集.docx

Java面试题集

JavaInterviewQuestions

Question:

WhatisthedifferencebetweenanInterfaceandanAbstractclass?

 Question:

WhatisthepurposeofgarbagecollectioninJava,andwhenisitused?

 

Question:

 

Describesynchronizationinrespecttomultithreading.

Question:

 

Explaindifferentwayofusingthread?

 

Question:

 

Whatarepassbyreferenceandpassbyvalue?

Question:

 

WhatisHashMapandMap?

Question:

 

DifferencebetweenHashMapandHashTable?

Question:

DifferencebetweenVectorandArrayList?

Question:

 

DifferencebetweenSwingandAwt?

Question:

 

Whatisthedifferencebetweenaconstructorandamethod?

Question:

 

WhatisanIterator?

Question:

 

Statethesignificanceofpublic,private,protected,defaultmodifiersbothsinglyandincombinationandstatetheeffectofpackagerelationshipsondeclareditemsqualifiedbythesemodifiers.

Question:

Whatisanabstractclass?

Question:

Whatisstaticinjava?

Question:

Whatisfinal?

Q:

WhatisthedifferencebetweenanInterfaceandanAbstractclass?

A:

Anabstractclasscanhaveinstancemethodsthatimplementadefaultbehavior.AnInterfacecanonlydeclareconstantsandinstancemethods,butcannotimplementdefaultbehaviorandallmethodsareimplicitlyabstract.Aninterfacehasallpublicmembersandnoimplementation.Anabstractclassisaclasswhichmayhavetheusualflavorsofclassmembers(private,protected,etc.),buthassomeabstractmethods.

.

 

TOP

Q:

WhatisthepurposeofgarbagecollectioninJava,andwhenisitused?

A:

Thepurposeofgarbagecollectionistoidentifyanddiscardobjectsthatarenolongerneededbyaprogramsothattheirresourcescanbereclaimedandreused.AJavaobjectissubjecttogarbagecollectionwhenitbecomesunreachabletotheprograminwhichitisused.

 

TOP

Q:

Describesynchronizationinrespecttomultithreading.

A:

Withrespecttomultithreading,synchronizationisthecapabilitytocontroltheaccessofmultiplethreadstosharedresources.Withoutsynchonization,itispossibleforonethreadtomodifyasharedvariablewhileanotherthreadisintheprocessofusingorupdatingsamesharedvariable.Thisusuallyleadstosignificanterrors. 

 

TOP

Q:

Explaindifferentwayofusingthread?

A:

ThethreadcouldbeimplementedbyusingrunnableinterfaceorbyinheritingfromtheThreadclass.Theformerismoreadvantageous,'causewhenyouaregoingformultipleinheritance..theonlyinterfacecanhelp.

 

TOP

Q:

Whatarepassbyreferenceandpassbyvalue?

A:

PassByReferencemeans thepassingtheaddressitselfratherthanpassingthevalue.PassbyValuemeans passing acopyofthevaluetobepassed. 

 

TOP

Q:

WhatisHashMapandMap?

A:

MapisInterfaceandHashmapisclassthatimplementsthat.

 

TOP

Q:

DifferencebetweenHashMapandHashTable?

A:

TheHashMapclassisroughlyequivalenttoHashtable,exceptthatitisunsynchronizedandpermitsnulls.(HashMapallowsnullvaluesaskeyandvaluewhereasHashtabledoesntallow).HashMapdoesnotguaranteethattheorderofthemapwillremainconstantovertime.HashMapisunsynchronizedandHashtableissynchronized.

 

TOP

Q:

DifferencebetweenVectorandArrayList?

A:

Vectorissynchronizedwhereasarraylistisnot.

 

TOP

Q:

DifferencebetweenSwingandAwt?

A:

AWTareheavy-weightcomponenets.Swingsarelight-weightcomponents.HenceswingworksfasterthanAWT.

 

TOP

Q:

Whatisthedifferencebetweenaconstructorandamethod?

A:

Aconstructorisamemberfunctionofaclassthatisusedtocreateobjectsofthatclass.Ithasthesamenameastheclassitself,hasnoreturntype,andisinvokedusingthenewoperator.

Amethodisanordinarymemberfunctionofaclass.Ithasitsownname,areturntype(whichmaybevoid),andisinvokedusingthedotoperator.

 

TOP

Q:

WhatisanIterator?

A:

Someofthecollectionclassesprovidetraversaloftheircontentsviaajava.util.Iteratorinterface.Thisinterfaceallowsyoutowalkthroughacollectionofobjects,operatingoneachobjectinturn.RememberwhenusingIteratorsthattheycontainasnapshotofthecollectionatthetimetheIteratorwasobtained;generallyitisnotadvisabletomodifythecollectionitselfwhiletraversinganIterator.

 

TOP

Q:

Statethesignificanceofpublic,private,protected,defaultmodifiersbothsinglyandincombinationandstatetheeffectofpackagerelationshipsondeclareditemsqualifiedbythesemodifiers.

A:

public:

Publicclassisvisibleinotherpackages,fieldisvisibleeverywhere(classmustbepublictoo)

private:

Privatevariablesormethodsmaybeusedonlybyaninstanceofthesameclassthatdeclaresthevariableormethod,Aprivatefeaturemayonlybeaccessedbytheclassthatownsthefeature.

protected:

Isavailabletoallclassesinthesamepackageandalsoavailabletoallsubclassesoftheclassthatownstheprotectedfeature.Thisaccessisprovidedeventosubclassesthatresideinadifferentpackagefromtheclassthatownstheprotectedfeature.

default:

Whatyougetbydefaultie,withoutanyaccessmodifier(ie,publicprivateorprotected).Itmeansthatitisvisibletoallwithinaparticularpackage.

 

TOP

Q:

Whatisanabstractclass?

A:

Abstractclassmustbeextended/subclassed(tobeuseful).Itservesasatemplate.Aclassthatisabstractmaynotbeinstantiated(ie,youmaynotcallitsconstructor),abstractclassmaycontainstaticdata.Anyclasswithanabstractmethodisautomaticallyabstractitself,andmustbedeclaredassuch.

Aclassmaybedeclaredabstractevenifithasnoabstractmethods.Thispreventsitfrombeinginstantiated.

 

TOP

Q:

Whatisstaticinjava?

A:

Staticmeansoneperclass,notoneforeachobjectnomatterhowmanyinstanceofaclassmightexist.Thismeansthatyoucanusethemwithoutcreatinganinstanceofaclass.Staticmethodsareimplicitlyfinal,becauseoverridingisdonebasedonthetypeoftheobject,andstaticmethodsareattachedtoaclass,notanobject.Astaticmethodinasuperclasscanbeshadowedbyanotherstaticmethodinasubclass,aslongastheoriginalmethodwasnotdeclaredfinal.However,youcan'toverrideastaticmethodwithanonstaticmethod.Inotherwords,youcan'tchangeastaticmethodintoaninstancemethodinasubclass.

 

TOP

Q:

Whatisfinal?

A:

Afinalclasscan'tbeextendedie.,finalclassmaynotbesubclassed.Afinalmethodcan'tbeoverriddenwhenitsclassisinherited.Youcan'tchangevalueofafinalvariable(isaconstant).

Question:

Whatifthemainmethodisdeclaredasprivate?

Question:

Whatifthestaticmodifierisremovedfromthesignatureofthemainmethod?

 

Question:

WhatifIwritestaticpublicvoidinsteadofpublicstaticvoid?

Question:

WhatifIdonotprovidetheStringarrayastheargumenttothemethod?

 

Question:

WhatisthefirstargumentoftheStringarrayinmainmethod?

Question:

IfIdonotprovideanyargumentsonthecommandline,thentheStringarrayofMainmethodwillbeemptyornull?

Question:

Howcanoneprovethatthearrayisnotnullbutemptyusingonelineofcode?

Question:

WhatenvironmentvariablesdoIneedtosetonmymachineinordertobeabletorunJavaprograms?

Question:

Cananapplicationhavemultipleclasseshavingmainmethod?

Question:

CanIhavemultiplemainmethodsinthesameclass?

Question:

DoIneedtoimportjava.langpackageanytime?

Why?

Question:

CanIimportsamepackage/classtwice?

WilltheJVMloadthepackagetwiceatruntime?

Question:

WhatareCheckedandUnCheckedException?

Question:

WhatisOverriding?

Question:

Whataredifferenttypesofinnerclasses?

Q:

Whatifthemainmethodisdeclaredasprivate?

A:

Theprogramcompilesproperlybutatruntimeitwillgive"Mainmethodnotpublic."message.

 

[ReceivedfromSandeshSadhale]

TOP

Q:

Whatifthestaticmodifierisremovedfromthesignatureofthemainmethod?

A:

Programcompiles.Butatruntimethrowsanerror"NoSuchMethodError".

 

[ReceivedfromSandeshSadhale]

TOP

Q:

WhatifIwritestaticpublicvoidinsteadofpublicstaticvoid?

A:

Programcompilesandrunsproperly.

 

[ReceivedfromSandeshSadhale]

TOP

Q:

WhatifIdonotprovidetheStringarrayastheargumenttothemethod?

A:

Programcompilesbutthrowsaruntimeerror"NoSuchMethodError".

 

[ReceivedfromSandeshSadhale]

TOP

Q:

WhatisthefirstargumentoftheStringarrayinmainmethod?

A:

TheStringarrayisempty.Itdoesnothaveanyelement.ThisisunlikeC/C++wherethefirstelementbydefaultistheprogramname.

 

[ReceivedfromSandeshSadhale]

TOP

Q:

IfIdonotprovideanyargumentsonthecommandline,thentheStringarrayofMainmethodwillbeemptyornull?

A:

Itisempty.Butnotnull.

 

[ReceivedfromSandeshSadhale]

TOP

Q:

Howcanoneprovethatthearrayisnotnullbutemptyusingonelineofcode?

A:

Printargs.length.Itwillprint0.Thatmeansitisempty.ButifitwouldhavebeennullthenitwouldhavethrownaNullPointerExceptiononattemptingtoprintargs.length.

 

[ReceivedfromSandeshSadhale]

TOP

Q:

WhatenvironmentvariablesdoIneedtosetonmymachineinordertobeabletorunJavaprograms?

A:

CLASSPATHandPATHarethetwovariables.

 

[ReceivedfromSandeshSadhale]

TOP

Q:

Cananapplicationhavemultipleclasseshavingmainmethod?

A:

Yesitispossible.Whilestartingtheapplicationwementiontheclassnametoberun.TheJVMwilllookfortheMainmethodonlyintheclas

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

当前位置:首页 > 解决方案 > 工作计划

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

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