7/31/2019 Cs506 Helping Material
1/26
SearchMuhammadYousufSignOutVirtualUniversityofPakistanNetworkofVirtualUniversityofPakistanStudents!HomeMyPageChat++MailCommunityNewTrendsExploreCoolStuffStudyZoneVUServicesDownloadsHelpCornersEntertainmentBlogsForumGroupsVideosPhotosLeaders
FAQ&RulesContactUs
AddNew
Helpingmaterialforpaperscs506PostedbyMuhammadAkhtaronFebruary7,2012at11:00pminCS506WebDesignandDevelopmentBacktoCS506WebDesignandDevelopmentDiscussionsHelpingmaterialforpaperscs506******plz**seeattachedfile....
PromoteShareTwitterViews:317Attachments:javanjsp.doc,409KB?ReplytoThisRepliestoThisDiscussionPermalinkReplybyM.TariqMalikonFebruary8,2012at9:42pmQ:ExplainthelifecyclemethodsofaServlet.A:Thejavax.servlet.Servletinterfacedefinesthethreemethodsknownaslife-cyclemethod.publicvoidinit(ServletConfigconfig)throwsServletException
publicvoidservice(ServletRequestreq,ServletResponseres)throwsServletException,IOExceptionpublicvoiddestroy()Firsttheservletisconstructed,theninitializedwihtheinit()method.Anyrequestfromclientarehandledinitiallybytheservice()methodbeforedelegatingtothedoXxx()methodsinthecaseofHttpServlet.
Theservletisremovedfromservice,destroyedwiththedestroy()method,thengarbagecollectedandfinalized.
7/31/2019 Cs506 Helping Material
2/26
Q:WhatisthedifferencebetweenthegetRequestDispatcher(Stringpath)methodofjavax.servlet.ServletRequestinterfaceandjavax.servlet.ServletContextinterface?A:ThegetRequestDispatcher(Stringpath)methodofjavax.servlet.ServletRequestinterfaceacceptsparameterthepathtotheresourcetobeincludedorforwardedto,whichcanberelativetotherequestofthecallingservlet.Ifthepathbeginswitha"/"itisinterpretedasrelativetothecurrentcontextroot.
ThegetRequestDispatcher(Stringpath)methodofjavax.servlet.ServletContextinterfacecannotacceptsrelativepaths.Allpathmustsartwitha"/"andareinterpretedasrelativetocurentcontextroot.Q:Explainthedirectorystructureofawebapplication.A:Thedirectorystructureofawebapplicationconsistsoftwoparts.AprivatedirectorycalledWEB-INFApublicresourcedirectorywhichcontainspublicresourcefolder.
WEB-INFfolderconsistsof1.web.xml2.classesdirectory3.libdirectoryQ:Whatarethecommonmechanismsusedforsessiontracking?A:CookiesSSLsessionsURL-rewriting
TOPQ:ExplainServletContext.A:ServletContextinterfaceisawindowforaservlettoviewit'senvironment.Aservletcanusethisinterfacetogetinformationsuchasinitializationparametersforthewebapplicationorservletcontainer'sversion.EverywebapplicationhasoneandonlyoneServletContextandisaccessibletoallactiveresourceofthatapplication.
TOPQ:Whatispreinitializationofaservlet?A:Acontainerdoesnotinitializetheservletsasssoonasitstartsup,itinitializesaservletwhenitreceivesarequestforthatservletfirsttime.Thisiscalledlazyloading.Theservletspecificationdefinestheelement,whichcanbespecifiedinthedeploymentdescriptortomaketheservletcon
7/31/2019 Cs506 Helping Material
3/26
tainerloadandinitializetheservletassoonasitstartsup.Theprocessofloadingaservletbeforeanyrequestcomesiniscalledpreloadingorpreinitializingaservlet.Q:WhatisthedifferencebetweenDifferencebetweendoGet()anddoPost()?A:AdoGet()methodislimitedwith2kofdatatobesent,anddoPost()methoddoesn'thavethislimitation.ArequeststringfordoGet()lookslikethefollowing:http://www.allapplabs.com/svt1?p1=v1&p2=v2&...&pN=vNdoPost()methodcalldoesn'tneedalongtexttailafteraservletnameinarequest.Allparametersarestoredinarequestitself,notinarequeststring,andit'simpossibletoguessthedatatransmittedtoaservletonlylookingatarequeststring.Q:WhatisthedifferencebetweenHttpServletandGenericServlet?A:AGenericServlethasaservice()methodaimedtohandlerequests.HttpServletextendsGenericServletandaddssupportfordoGet(),doPost(),doHead()methods(HTTP1.0)plusdoPut(),doOptions(),doDelete(),doTrace()methods(HTTP1.1).Boththeseclassesareabstract.Q:WhatisthedifferencebetweenServletContextandServletConfig?A:
ServletContext:Definesasetofmethodsthataservletusestocommunicatewithitsservletcontainer,forexample,togettheMIMEtypeofafile,dispatchrequests,orwritetoalogfile.TheServletContextobjectiscontainedwithintheServletConfigobject,whichtheWebserverprovidestheservletwhentheservletisinitialized
ServletConfig:Theobjectcreatedafteraservletisinstantiatedanditsdefaultconstructorisread.Itiscreatedtopassinitializationinformationtotheservlet.Q:
Whatisaoutputcomment?A:Acommentthatissenttotheclientintheviewablepagesource.TheJSPenginehandlesanoutputcommentasuninterpretedHTMLtext,returningthecommentintheHTMLoutputsenttotheclient.YoucanseethecommentbyviewingthepagesourcefromyourWebbrowser.JSPSyntax
Example1
Displaysinthepagesource:?ReplyMessagePermalinkReplybyM.TariqMalikonFebruary8,2012at9:43pmQ:WhatisaHiddenComment?A:AcommentsthatdocumentstheJSPpagebutisnotsenttotheclient.TheJSPen
7/31/2019 Cs506 Helping Material
4/26
gineignoresahiddencomment,anddoesnotprocessanycodewithinhiddencommenttags.Ahiddencommentisnotsenttotheclient,eitherinthedisplayedJSPpageortheHTMLpagesource.Thehiddencommentisusefulwhenyouwanttohideor"commentout"partofyourJSPpage.Youcanuseanycharactersinthebodyofthecommentexcepttheclosing--%>combination.Ifyouneedtouse--%>inyourcomment,youcanescapeitbytyping--%\>.JSPSyntaxExamplesAHiddenCommentTOPQ:WhatisaExpression?A:Anexpressiontagcontainsascriptinglanguageexpressionthatisevaluated,co
nvertedtoaString,andinsertedwheretheexpressionappearsintheJSPfile.BecausethevalueofanexpressionisconvertedtoaString,youcanuseanexpressionwithintextinaJSPfile.LikeYoucannotuseasemicolontoendanexpressionTOPQ:WhatisaDeclaration?A:AdeclarationdeclaresoneormorevariablesormethodsforuselaterintheJSP
sourcefile.Adeclarationmustcontainatleastonecompletedeclarativestatement.Youcandeclareanynumberofvariablesormethodswithinonedeclarationtag,aslongastheyareseparatedbysemicolons.ThedeclarationmustbevalidinthescriptinglanguageusedintheJSPfile.
TOPQ:
WhatisaScriptlet?A:Ascriptletcancontainanynumberoflanguagestatements,variableormethoddeclarations,orexpressionsthatarevalidinthepagescriptinglanguage.Withinscriptlettags,youcan1.Declarevariablesormethodstouselaterinthefile(seealsoDeclaration).
2.Writeexpressionsvalidinthepagescriptinglanguage(seealsoExpression).
3.UseanyoftheJSPimplicitobjectsoranyobjectdeclaredwitha
7/31/2019 Cs506 Helping Material
5/26
>tag.Youmustwriteplaintext,HTML-encodedtext,orotherJSPtagsoutsidethescriptlet.Scriptletsareexecutedatrequesttime,whentheJSPengineprocessestheclientrequest.Ifthescriptletproducesoutput,theoutputisstoredintheoutobject,fromwhichyoucandisplayit.Q:Whatareimplicitobjects?Listthem?A:CertainobjectsthatareavailablefortheuseinJSPdocumentswithoutbeingdeclaredfirst.TheseobjectsareparsedbytheJSPengineandinsertedintothegeneratedservlet.TheimplicitobjectsrelistedbelowrequestresponsepageContextsessionapplicationoutconfigpageexception
TOPQ:DifferencebetweenforwardandsendRedirect?A:Whenyouinvokeaforwardrequest,therequestissenttoanotherresourceontheserver,withouttheclientbeinginformedthatadifferentresourceisgoingtoprocesstherequest.Thisprocessoccurscompletlywithinthewebcontainer.WhenasendRedirtectmethodisinvoked,itcausesthewebcontainertoreturntothebrowserindicatingthatanewURLshouldberequested.Becausethebrowserissuesacompletlynewrequestanyobjectthatarestoredasrequestattributesbeforetheredirectoccurswillbelost.Thisextraroundtriparedirectisslo
werthanforward.Q:Whatarethedifferentscopevaliuesforthe?A:Thedifferentscopevaluesforare1.page2.request3.session4.application
Q:Explainthelife-cyclemehtodsinJSP?A:THegeneratedservletclassforaJSPpageimplementstheHttpJspPageinterfaceofthejavax.servlet.jsppackage.HteHttpJspPageinterfaceextendstheJspPageinterfacewhichinturnextendstheServletinterfaceofthejavax.servletpackage.thegeneratedservletclassthusimplementsallthemethodsofthethesethreeinterfaces.TheJspPageinterfacedeclaresonlytwomehtods-jspInit()andjs
7/31/2019 Cs506 Helping Material
6/26
pDestroy()thatmustbeimplementedbyallJSPpagesregardlessoftheclient-serverprotocol.HowevertheJSPspecificationhasprovidedtheHttpJspPageinterfaecspecificallyfortheJSppagesservingHTTPrequests.Thisinterfacedeclaresonemethod_jspService().ThejspInit()-ThecontainercallsthejspInit()toinitializeteservletinstance.Itiscalledbeforeanyothermethod,andiscalledonlyonceforaservletinstance.The_jspservice()-Thecontainercallsthe_jspservice()foreachrequest,passingittherequestandtheresponseobjects.ThejspDestroy()-Thecontainercallsthiswhenitdecidestaketheinstanceoutofservice.Itisthelastmethodcalledntheservletinstance.?ReplyMessagePermalinkReplybyM.TariqMalikonFebruary8,2012at9:43pmQ:HowdoIpreventtheoutputofmyJSPorServletpagesfrombeingcachedbythebrowser?A:YouwillneedtosettheappropriateHTTPheaderattributestopreventthedynamiccontentoutputbytheJSPpagefrombeingcachedbythebrowser.JustexecutethefollowingscriptletatthebeginningofyourJSPpagestopreventthemfrombeingcachedatthebrowser.Youneedboththestatementstotakecareofsomeoftheolderbrowserversions.Q:HowdoesJSPhandlerun-timeexceptions?A:YoucanusetheerrorPageattributeofthepagedirectivetohaveuncaughtrun-timeexceptionsautomaticallyforwardedtoanerrorprocessingpage.Forexample:redirectsthebrowsertotheJSPpageerror.jspifanuncaughtexceptionisencounteredduringrequestprocessing.Withinerror.jsp,ifyouindicatethatitisanerror-processingpage,viathedirective:Throwableobjectdescribingtheexceptionmay
beaccessedwithintheerrorpageviatheexceptionimplicitobject.Note:YoumustalwaysusearelativeURLasthevaluefortheerrorPageattribute.Q:HowcanIimplementathread-safeJSPpage?WhataretheadvantagesandDisadvantagesofusingit?A:YoucanmakeyourJSPsthread-safebyhavingthemimplementtheSingleThreadModelinterface.ThisisdonebyaddingthedirectivewithinyourJSPpage.Withthis,insteadofasingleinstanceoftheservletgeneratedforyourJSPpageloadedinmemory,youwillhaveNinstancesoftheservletloadedandinitialized,withtheservicemethodofeachinstanceeffectivelysynchronized.Youcantypicallycontrolthenumberofinstances(N)thatareinstantiatedforallservletsimplementingSingleThreadModelthroughtheadmin
screenforyourJSPengine.Moreimportantly,avoidusingthetagforvariables.Ifyoudousethistag,thenyoushouldsetisThreadSafetotrue,asmentionedabove.Otherwise,allrequeststothatpagewillaccessthosevariables,causinganastyracecondition.SingleThreadModelisnotrecommendedfornormaluse.Therearemanypitfalls,includingtheexampleaboveofnotbeingabletouse.Youshouldtryreallyhardtomakethemthread-safetheoldfashionedway:bymakingthemthread-safe.
7/31/2019 Cs506 Helping Material
7/26
Q:HowdoIuseascriptlettoinitializeanewlyinstantiatedbean?A:Ajsp:useBeanactionmayoptionallyhaveabody.Ifthebodyisspecified,itscontentswillbeautomaticallyinvokedwhenthespecifiedbeanisinstantiated.Typically,thebodywillcontainscriptletsorjsp:setPropertytagstoinitializethenewlyinstantiatedbean,althoughyouarenotrestrictedtousingthosealone.ThefollowingexampleshowsthetodaypropertyoftheFoobeaninitializedtothecurrentdatewhenitisinstantiated.Notethathere,wemakeuseofaJSPexpressionwithinthejsp:setPropertyaction.
Q:
HowcanIpreventtheword"null"fromappearinginmyHTMLinputtextfieldswhenIpopulatethemwitharesultsetthathasnullvalues?A:Youcouldmakeasimplewrapperfunction,likethenuseitinsideyourJSPform,like[ReceivedfromSumitDhamija]
TOPQ:What'sabetterapproachforenablingthread-safeservletsandJSPs?SingleThreadModelInterfaceorSynchronization?A:AlthoughtheSingleThreadModeltechniqueiseasytouse,andworkswellforlowvolumesites,itdoesnotscalewell.Ifyouanticipateyouruserstoincreaseinthefuture,youmaybebetteroffimplementingexplicitsynchronizationforyourshareddata.Thekeyhowever,istoeffectivelyminimizetheamountofcodethatissynchronziedsothatyoutakemaximumadvantageofmultithreading.Also,notethatSingleThreadModelisprettyresourceintensivefromtheserver\'sperspective.Themostseriousissuehoweveriswhenthenumberofconcurrentr
equestsexhausttheservletinstancepool.Inthatcase,alltheunservicedrequestsarequeueduntilsomethingbecomesfree-whichresultsinpoorperformance.Sincetheusageisnon-deterministic,itmaynothelpmuchevenifyoudidaddmorememoryandincreasedthesizeoftheinstancepool.[ReceivedfromSumitDhamija]TOPQ:HowcanIenablesessiontrackingforJSPpagesifthebrowserhasdisabledcook
7/31/2019 Cs506 Helping Material
8/26
ies?A:Weknowthatsessiontrackingusescookiesbydefaulttoassociateasessionidentifierwithauniqueuser.Ifthebrowserdoesnotsupportcookies,orifcookiesaredisabled,youcanstillenablesessiontrackingusingURLrewriting.URLrewritingessentiallyincludesthesessionIDwithinthelinkitselfasaname/valuepair.However,forthistobeeffective,youneedtoappendthesessionIDforeachandeverylinkthatispartofyourservletresponse.AddingthesessionIDtoalinkisgreatlysimplifiedbymeansofofacoupleofmethods:response.encodeURL()associatesasessionIDwithagivenURL,andifyouareusingredirection,response.encodeRedirectURL()canbeusedbygivingtheredirectedURLasinput.BothencodeURL()andencodeRedirectedURL()firstdeterminewhethercookiesaresupportedbythebrowser;ifso,theinputURLisreturnedunchangedsincethesessionIDwillbepersistedasacookie.
Considerthefollowingexample,inwhichtwoJSPfiles,sayhello1.jspandhello2.jsp,interactwitheachother.Basically,wecreateanewsessionwithinhello1.jspandplaceanobjectwithinthissession.Theusercanthentraversetohello2.jspbyclickingonthelinkpresentwithinthepage.Withinhello2.jsp,wesimplyextracttheobjectthatwasearlierplacedinthesessionanddisplayitscontents.NoticethatweinvoketheencodeURL()withinhello1.jsponthelinkusedtoinvokehello2.jsp;ifcookiesaredisabled,thesessionIDisautomaticallyappendedtotheURL,allowinghello2.jsptostillretrievethesessionobject.Trythisexamplefirstwithcookiesenabled.Thendisablecookiesupport,resta
rtthebrower,andtryagain.Eachtimeyoushouldseethemaintenanceofthesessionacrosspages.Donotethattogetthisexampletoworkwithcookiesdisabledatthebrowser,yourJSPenginehastosupportURLrewriting.hello1.jsphello2.jsphello2.jsp
TOPQ:Whatisthedifferenceb/wvariabledeclaredinsideadeclarationpartandvariabledeclaredinscripletpart?A:Variabledeclaredinsidedeclarationpartistreatedasaglobalvariable.thatmeansafterconvertionjspfileintoservletthatvariablewillbeinoutsideof
servicemethodoritwillbedeclaredasinstancevariable.Andthescopeisavailabletocompletejspandtocompleteintheconvertedservletclass.whereasifudeclareavariableinsideascripletthatvariablewillbedeclaredinsideaservicemethodandthescopeiswithintheservicemethod.Q:IsthereawaytoexecuteaJSPfromthecomandlineorfrommyownapplication?A:ThereisalittletoolcalledJSPExecutorthatallowsyoutodojustthat.Thedevelopers(HendrikSchreiber&PeterRossbach)aimwasnottowriteafullblownservletengine,buttoprovidemeanstouseJSPf
7/31/2019 Cs506 Helping Material
9/26
orgeneratingsourcecodeorreports.ThereforemostHTTP-specificfeatures(headers,sessions,etc)arenotimplemented,i.e.noreponselineorheaderisgenerated.NeverthelessyoucanuseittoprecompileJSPforyourwebsite.?ReplyMessagePermalinkReplybyM.TariqMalikonFebruary8,2012at9:44pmQ:WhatisthedifferencebetweenanInterfaceandanAbstractclass?A:Anabstractclasscanhaveinstancemethodsthatimplementadefaultbehavior.AnInterfacecanonlydeclareconstantsandinstancemethods,butcannotimplementdefaultbehaviorandallmethodsareimplicitlyabstract.Aninterfacehasallpublicmembersandnoimplementation.Anabstractclassisaclasswhichmayhavetheusualflavorsofclassmembers(private,protected,etc.),buthassomeabstractmethods..TOPQ:WhatisthepurposeofgarbagecollectioninJava,andwhenisitused?A:Thepurposeofgarbagecollectionistoidentifyanddiscardobjectsthatarenolongerneededbyaprogramsothattheirresourcescanbereclaimedandreused.
AJavaobjectissubjecttogarbagecollectionwhenitbecomesunreachabletotheprograminwhichitisused.TOPQ:Describesynchronizationinrespecttomultithreading.A:Withrespecttomultithreading,synchronizationisthecapabilitytocontroltheaccessofmultiplethreadstosharedresources.Withoutsynchonization,itispossibleforonethreadtomodifyasharedvariablewhileanotherthreadisintheprocessofusingorupdatingsamesharedvariable.Thisusuallyleadstosignificanterrors.
TOPQ:Explaindifferentwayofusingthread?A:ThethreadcouldbeimplementedbyusingrunnableinterfaceorbyinheritingfromtheThreadclass.Theformerismoreadvantageous,'causewhenyouaregoingformultipleinheritance..theonlyinterfacecanhelp.TOPQ:
Whatarepassbyreferenceandpassbyvalue?A:PassByReferencemeansthepassingtheaddressitselfratherthanpassingthevalue.PassbyValuemeanspassingacopyofthevaluetobepassed.TOPQ:WhatisHashMapandMap?A:
7/31/2019 Cs506 Helping Material
10/26
MapisInterfaceandHashmapisclassthatimplementsthat.TOPQ:DifferencebetweenHashMapandHashTable?A:TheHashMapclassisroughlyequivalenttoHashtable,exceptthatitisunsynchronizedandpermitsnulls.(HashMapallowsnullvaluesaskeyandvaluewhereasHashtabledoesntallow).HashMapdoesnotguaranteethattheorderofthemapwillremainconstantovertime.HashMapisunsynchronizedandHashtableissynchronized.TOPQ:DifferencebetweenVectorandArrayList?A:Vectorissynchronizedwhereasarraylistisnot.TOPQ:DifferencebetweenSwingandAwt?
A:AWTareheavy-weightcomponenets.Swingsarelight-weightcomponents.HenceswingworksfasterthanAWT.TOPQ:Whatisthedifferencebetweenaconstructorandamethod?A:Aconstructorisamemberfunctionofaclassthatisusedtocreateobjectsofthatclass.Ithasthesamenameastheclassitself,hasnoreturntype,andisinvokedusingthenewoperator.Amethodisanordinarymemberfunctionofaclass.Ithasitsownname,aretur
ntype(whichmaybevoid),andisinvokedusingthedotoperator.TOPQ:WhatisanIterator?A:Someofthecollectionclassesprovidetraversaloftheircontentsviaajava.util.Iteratorinterface.Thisinterfaceallowsyoutowalkthroughacollectionofobjects,operatingoneachobjectinturn.RememberwhenusingIteratorsthattheycontainasnapshotofthecollectionatthetimetheIteratorwasobtained;generallyitisnotadvisabletomodifythecollectionitselfwhiletraversinganIterator.
TOPQ:Statethesignificanceofpublic,private,protected,defaultmodifiersbothsinglyandincombinationandstatetheeffectofpackagerelationshipsondeclareditemsqualifiedbythesemodifiers.A:public:Publicclassisvisibleinotherpackages,fieldisvisibleeverywhere(classmustbepublictoo)
7/31/2019 Cs506 Helping Material
11/26
private:Privatevariablesormethodsmaybeusedonlybyaninstanceofthesameclassthatdeclaresthevariableormethod,Aprivatefeaturemayonlybeaccessedbytheclassthatownsthefeature.protected:Isavailabletoallclassesinthesamepackageandalsoavailabletoallsubclassesoftheclassthatownstheprotectedfeature.Thisaccessisprovidedeventosubclassesthatresideinadifferentpackagefromtheclassthatownstheprotectedfeature.default:Whatyougetbydefaultie,withoutanyaccessmodifier(ie,publicprivateorprotected).Itmeansthatitisvisibletoallwithinaparticularpackage.TOPQ: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.
TOPQ:Whatisfinal?A:Afinalclasscan'tbeextendedie.,finalclassmaynotbesubclassed.Afinalmethodcan'tbeoverriddenwhenitsclassisinherited.Youcan'tchangevalueofafinalvariable(isaconstant).:Aretheimportscheckedforvalidityatcompiletime?e.g.willthecodecontaininganimportsuchasjava.lang.ABCDcompile?A:Yestheimportsarecheckedforthesemanticvalidityatcompiletime.Thecode
containingabovelineofimportwillnotcompile.Itwillthrowanerrorsaying,cannotresolvesymbolsymbol:classABCDlocation:packageioimportjava.io.ABCD;Q:Doesimportingapackageimportsthesubpackagesaswell?e.g.Doesimportingcom.MyTest.*alsoimportcom.MyTest.UnitTests.*?A:Noyouwillhavetoimportthesubpackagesexplicitly.Importingcom.MyTest.*wi
7/31/2019 Cs506 Helping Material
12/26
llimportclassesinthepackageMyTestonly.Itwillnotimportanyclassinanyofit'ssubpackage.Q:Whatisthedifferencebetweendeclaringavariableanddefiningavariable?A:Indeclarationwejustmentionthetypeofthevariableandit'sname.Wedonotinitializeit.Butdefiningmeansdeclaration+initialization.e.gStrings;isjustadeclarationwhileStrings=newString("abcd");OrStrings="abcd";arebothdefinitions.[ReceivedfromSandeshSadhale]TOPQ:Whatisthedefaultvalueofanobjectreferencedeclaredasaninstancevariable?A:nullunlesswedefineitexplicitly.[ReceivedfromSandeshSadhale]TOPQ:Canatoplevelclassbeprivateorprotected?
A:No.Atoplevelclasscannotbeprivateorprotected.Itcanhaveeither"public"ornomodifier.Ifitdoesnothaveamodifieritissupposedtohaveadefaultaccess.Ifatoplevelclassisdeclaredasprivatethecompilerwillcomplainthatthe"modifierprivateisnotallowedhere".Thismeansthatatoplevelclasscannotbeprivate.Sameisthecasewithprotected.[ReceivedfromSandeshSadhale]TOPQ:WhattypeofparameterpassingdoesJavasupport?A:
InJavatheargumentsarealwayspassedbyvalue.[UpdatefromEkiandJyothishVenu]TOPQ:Primitivedatatypesarepassedbyreferenceorpassbyvalue?A:Primitivedatatypesarepassedbyvalue.[ReceivedfromSandeshSadhale]TOP
Q:Objectsarepassedbyvalueorbyreference?A:Javaonlysupportspassbyvalue.Withobjects,theobjectreferenceitselfispassedbyvalueandsoboththeoriginalreferenceandparametercopybothrefertothesameobject.[UpdatefromEkiandJyothishVenu]TOP
7/31/2019 Cs506 Helping Material
13/26
Q:Whatisserialization?A:Serializationisamechanismbywhichyoucansavethestateofanobjectbyconvertingittoabytestream.[ReceivedfromSandeshSadhale]TOPQ:HowdoIserializeanobjecttoafile?A:TheclasswhoseinstancesaretobeserializedshouldimplementaninterfaceSerializable.ThenyoupasstheinstancetotheObjectOutputStreamwhichisconnectedtoafileoutputstream.Thiswillsavetheobjecttoafile.[ReceivedfromSandeshSadhale]TOP?ReplyMessagePermalinkReplybyM.TariqMalikonFebruary8,2012at9:44pmQ:WhichmethodsofSerializableinterfaceshouldIimplement?A:
Theserializableinterfaceisanemptyinterface,itdoesnotcontainanymethods.Sowedonotimplementanymethods.[ReceivedfromSandeshSadhale]TOPQ:HowcanIcustomizetheseralizationprocess?i.e.howcanonehaveacontrolovertheserializationprocess?A:Yesitispossibletohavecontroloverserializationprocess.TheclassshouldimplementExternalizableinterface.ThisinterfacecontainstwomethodsnamelyreadExternalandwriteExternal.Youshouldimplementthesemethodsandwritethe
logicforcustomizingtheserializationprocess.[ReceivedfromSandeshSadhale]TOPQ:Whatisthecommonusageofserialization?A:Wheneveranobjectistobesentoverthenetwork,objectsneedtobeserialized.Moreoverifthestateofanobjectistobesaved,objectsneedtobeserilazed.[ReceivedfromSandeshSadhale]
TOPQ:WhatisExternalizableinterface?A:ExternalizableisaninterfacewhichcontainstwomethodsreadExternalandwriteExternal.Thesemethodsgiveyouacontrolovertheserializationmechanism.Thusifyourclassimplementsthisinterface,youcancustomizetheserializationprocessbyimplementingthesemethods.
7/31/2019 Cs506 Helping Material
14/26
[ReceivedfromSandeshSadhale]TOPQ:Whenyouserializeanobject,whathappenstotheobjectreferencesincludedintheobject?A:Theserializationmechanismgeneratesanobjectgraphforserialization.Thusitdetermineswhethertheincludedobjectreferencesareserializableornot.Thisisarecursiveprocess.Thuswhenanobjectisserialized,alltheincludedobjectsarealsoserializedalongwiththeoriginalobect.[ReceivedfromSandeshSadhale]TOPQ:Whatoneshouldtakecareofwhileserializingtheobject?A:Oneshouldmakesurethatalltheincludedobjectsarealsoserializable.IfanyoftheobjectsisnotserializablethenitthrowsaNotSerializableException.[ReceivedfromSandeshSadhale]TOP
Q:Whathappenstothestaticfieldsofaclassduringserialization?A:Therearethreeexceptionsinwhichserializationdoesnotnecessarilyreadandwritetothestream.Theseare1.Serializationignoresstaticfields,becausetheyarenotpartofayparticularstatestate.2.Baseclassfieldsareonlyhendledifthebaseclassitselfisserializable.3.Transientfields.[ReceivedfromSandeshSadhaleModifiedafterP.JohnDavidcomments.]TOP:
DoesJavaprovideanyconstructtofindoutthesizeofanobject?A:NothereisnotsizeofoperatorinJava.SothereisnotdirectwaytodeterminethesizeofanobjectdirectlyinJava.[ReceivedfromSandeshSadhale]TOPQ:Giveasimplestwaytofindoutthetimeamethodtakesforexecutionwithoutusinganyprofilingtool?A:Readthesystemtimejustbeforethemethodisinvokedandimmediatelyaftermet
hodreturns.Takethetimedifference,whichwillgiveyouthetimetakenbyamethodforexecution.Toputitincode...longstart=System.currentTimeMillis();method();longend=System.currentTimeMillis();System.out.println("Timetakenforexecutionis"+(end-start));Rememberthatifthetimetakenforexecutionistoosmall,itmightshowthatitistakingzeromillisecondsforexecution.Tryitonamethodwhichisbigenough,inthesensetheonewhichisdoingconsiderableamoutofprocessing.
7/31/2019 Cs506 Helping Material
15/26
[ReceivedfromSandeshSadhale]TOPQ:Whatarewrapperclasses?A:Javaprovidesspecializedclassescorrespondingtoeachoftheprimitivedatatypes.Thesearecalledwrapperclasses.Theyaree.g.Integer,Character,Doubleetc.[ReceivedfromSandeshSadhale]TOPQ:Whydoweneedwrapperclasses?A:Itissometimeseasiertodealwithprimitivesasobjects.Moreovermostofthecollectionclassesstoreobjectsandnotprimitivedatatypes.Andalsothewrapperclassesprovidemanyutilitymethodsalso.Becauseoftheseresonsweneedwrapperclasses.Andsincewecreateinstancesoftheseclasseswecanstoretheminanyofthecollectionclassesandpassthemaroundasacollection.Alsowecanpassthemaroundasmethodparameterswhereamethodexpectsanobject.
[ReceivedfromSandeshSadhale]TOPQ:Whatarecheckedexceptions?A:CheckedexceptionarethosewhichtheJavacompilerforcesyoutocatch.e.g.IOExceptionarecheckedExceptions.[ReceivedfromSandeshSadhale]TOPQ:
Whatareruntimeexceptions?A:Runtimeexceptionsarethoseexceptionsthatarethrownatruntimebecauseofeitherwronginputdataorbecauseofwrongbusinesslogicetc.Thesearenotcheckedbythecompileratcompiletime.[ReceivedfromSandeshSadhale]TOPQ:Whatisthedifferencebetweenerrorandanexception?A:Anerrorisanirrecoverableconditionoccurringatruntime.SuchasOutOfMemory
error.TheseJVMerrorsandyoucannotrepairthematruntime.Whileexceptionsareconditionsthatoccurbecauseofbadinputetc.e.g.FileNotFoundExceptionwillbethrownifthespecifiedfiledoesnotexist.OraNullPointerExceptionwilltakeplaceifyoutryusinganullreference.Inmostofthecasesitispossibletorecoverfromanexception(probablybygivinguserafeedbackforenteringpropervaluesetc.).[ReceivedfromSandeshSadhale]TOP
7/31/2019 Cs506 Helping Material
16/26
Q:Howtocreatecustomexceptions?A:YourclassshouldextendclassException,orsomemorespecifictypethereof.[ReceivedfromSandeshSadhale]TOPQ:IfIwantanobjectofmyclasstobethrownasanexceptionobject,whatshouldIdo?A:TheclassshouldextendfromExceptionclass.Oryoucanextendyourclassfromsomemorepreciseexceptiontypealso.[ReceivedfromSandeshSadhale]TOPQ:IfmyclassalreadyextendsfromsomeotherclasswhatshouldIdoifIwantaninstanceofmyclasstobethrownasanexceptionobject?A:Onecannotdoanytihnginthisscenarion.BecauseJavadoesnotallowmultipleinheritanceanddoesnotprovideanyexceptioninterfaceaswell.
[ReceivedfromSandeshSadhale]TOPQ:Howdoesanexceptionpermeatethroughthecode?A:AnunhandledexceptionmovesupthemethodstackinsearchofamatchingWhenanexceptionisthrownfromacodewhichiswrappedinatryblockfollowedbyoneormorecatchblocks,asearchismadeformatchingcatchblock.Ifamatchingtypeisfoundthenthatblockwillbeinvoked.Ifamatchingtypeisnotfoundthentheexceptionmovesupthemethodstackandreachesthecallermethod.Sameprocedureisrepeatedifthecallermethodisincludedinatrycatchblock.Thi
sprocesscontinuesuntilacatchblockhandlingtheappropriatetypeofexceptionisfound.Ifitdoesnotfindsuchablockthenfinallytheprogramterminates.Q:Whatarethedifferentwaystohandleexceptions?A:Therearetwowaystohandleexceptions,1.Bywrappingthedesiredcodeinatryblockfollowedbyacatchblocktocatchtheexceptions.and2.Listthedesiredexceptionsinthethrowsclauseofthemethodandletthecallerofthemethodhadlethoseexceptions.Q:Whatisthebasicdifferencebetweenthe2approachestoexceptionhandling.
1>trycatchblockand2>specifyingthecandidateexceptionsinthethrowsclause?Whenshouldyouusewhichapproach?A:Inthefirstapproachasaprogrammerofthemethod,youurselfaredealingwiththeexception.Thisisfineifyouareinabestpositiontodecideshouldbedoneincaseofanexception.Whereasifitisnottheresponsibilityofthemethodtodealwithit'sownexceptions,thendonotusethisapproach.Inthiscaseusethesecondapproach.Inthesecondapproachweareforcingthecallerofthemethodtocatchtheexceptions,thatthemethodislikelytothrow.Thisisof
7/31/2019 Cs506 Helping Material
17/26
tentheapproachlibrarycreatorsuse.Theylisttheexceptioninthethrowsclauseandwemustcatchthem.Youwillfindthesameapproachthroughoutthejavalibrariesweuse.Q:Isitnecessarythateachtryblockmustbefollowedbyacatchblock?A:Itisnotnecessarythateachtryblockmustbefollowedbyacatchblock.ItshouldbefollowedbyeitheracatchblockORafinallyblock.Andwhateverexceptionsarelikelytobethrownshouldbedeclaredinthethrowsclauseofthemethod.Q:IfIwritereturnattheendofthetryblock,willthefinallyblockstillexecute?A:Yesevenifyouwritereturnasthelaststatementinthetryblockandnoexceptionoccurs,thefinallyblockwillexecute.Thefinallyblockwillexecuteandthenthecontrolreturn.TQ:IfIwriteSystem.exit(0);attheendofthetryblock,willthefinallyblockstillexecute?
A:NointhiscasethefinallyblockwillnotexecutebecausewhenyousaySystem.exit(0);thecontrolimmediatelygoesoutoftheprogram,andthusfinallyneverexecutes.Q:IsEmpty.javafileavalidsourcefile?A:Yes,anempty.javafileisaperfectlyvalidsourcefile.[ReceivedfromSandeshSadhale]TOPQ:
Cana.javafilecontainmorethanonejavaclasses?A:Yes,a.javafilecontainmorethanonejavaclasses,providedatthemostoneofthemisapublicclass.[ReceivedfromSandeshSadhale]TOPQ:IsStringaprimitivedatatypeinJava?A:NoStringisnotaprimitivedatatypeinJava,eventhoughitisoneofthemostextensivelyusedobject.StringsinJavaareinstancesofStringclassdefined
injava.langpackage.[ReceivedfromSandeshSadhale]TOPQ:IsmainakeywordinJava?A:No,mainisnotakeywordinJava.
7/31/2019 Cs506 Helping Material
18/26
[ReceivedfromSandeshSadhale]TOPQ:IsnextakeywordinJava?A:No,nextisnotakeyword.[ReceivedfromSandeshSadhale]TOPQ:IsdeleteakeywordinJava?A:No,deleteisnotakeywordinJava.JavadoesnotmakeuseofexplicitdestructorsthewayC++does.[ReceivedfromSandeshSadhale]TOPQ:IsexitakeywordinJava?A:No.ToexitaprogramexplicitlyyouuseexitmethodinSystemobject.
[ReceivedfromSandeshSadhale]TOPQ:WhathappensifyoudontinitializeaninstancevariableofanyoftheprimitivetypesinJava?A:Javabydefaultinitializesittothedefaultvalueforthatprimitivetype.Thusanintwillbeinitializedto0,abooleanwillbeinitializedtofalse.[ReceivedfromSandeshSadhale]TOP
Q:Whatwillbetheinitialvalueofanobjectreferencewhichisdefinedasaninstancevariable?A:TheobjectreferencesareallinitializedtonullinJava.Howeverinordertodoanythingusefulwiththesereferences,youmustsetthemtoavalidobject,elseyouwillgetNullPointerExceptionseverywhereyoutrytousesuchdefaultinitializedreferences.[ReceivedfromSandeshSadhale]TOP
Q:WhatarethedifferentscopesforJavavariables?A:ThescopeofaJavavariableisdeterminedbythecontextinwhichthevariableisdeclared.Thusajavavariablecanhaveoneofthethreescopesatanygivenpointintime.1.Instance:-Thesearetypicalobjectlevelvariables,theyareinitializedtodefaultvaluesatthetimeofcreationofobject,andremainaccessibleaslongastheobjectaccessible.2.Local:-Thesearethevariablesthataredefinedwithinamethod.Theyrema
7/31/2019 Cs506 Helping Material
19/26
inaccessbileonlyduringthecourseofmethodexcecution.Whenthemethodfinishesexecution,thesevariablesfalloutofscope.3.Static:-Thesearetheclasslevelvariables.TheyareinitializedwhentheclassisloadedinJVMforthefirsttimeandremainthereaslongastheclassremainsloaded.Theyarenottiedtoanyparticularobjectinstance.[ReceivedfromSandeshSadhale]TOPQ:Whatisthedefaultvalueofthelocalvariables?A:Thelocalvariablesarenotinitializedtoanydefaultvalue,neitherprimitivesnorobjectreferences.Ifyoutrytousethesevariableswithoutinitializingthemexplicitly,thejavacompilerwillnotcompilethecode.Itwillcomplainabtthelocalvaraiblenotbeinginitilized..[ReceivedfromSandeshSadhale]TOPQ:Howmanyobjectsarecreatedinthefollowingpieceofcode?MyClassc1,c2,c3;c1=newMyClass();
c3=newMyClass();A:Only2objectsarecreated,c1andc3.Thereferencec2isonlydeclaredandnotinitialized.[ReceivedfromSandeshSadhale]TOPQ:CanapublicclassMyClassbedefinedinasourcefilenamedYourClass.java?A:Nothesourcefilename,ifitcontainsapublicclass,mustbethesameasthepublicclassnameitselfwitha.javaextension.
[ReceivedfromSandeshSadhale]TOPQ:Canmainmethodbedeclaredfinal?A:Yes,themainmethodcanbedeclaredfinal,inadditiontobeingpublicstatic.[ReceivedfromSandeshSadhale]TOPQ:
Whatwillbetheoutputofthefollowingstatement?System.out.println("1"+3);A:Itwillprint13.[ReceivedfromSandeshSadhale]TOPQ:Whatwillbethedefaultvaluesofalltheelementsofanarraydefinedasanin
7/31/2019 Cs506 Helping Material
20/26
stancevariable?A:Ifthearrayisanarrayofprimitivetypes,thenalltheelementsofthearraywillbeinitializedtothedefaultvaluecorrespondingtothatprimitivetype.e.g.Alltheelementsofanarrayofintwillbeinitializedto0,whilethatofbooleantypewillbeinitializedtofalse.Whereasifthearrayisanarrayofreferences(ofanytype),alltheelementswillbeinitializedtonull.Cananunreachableobjectbecomereachableagain?A:Anunreachableobjectmaybecomereachableagain.Thiscanhappenwhentheobject'sfinalize()methodisinvokedandtheobjectperformsanoperationwhichcausesittobecomeaccessibletoreachableobjects.[ReceivedfromPRajesh]TOP?ReplyMessagePermalinkReplybyM.TariqMalikonFebruary8,2012at9:45pmQ:Whatmethodmustbeimplementedbyallthreads?A:Alltasksmustimplementtherun()method,whethertheyareasubclassofThreadorimplementtheRunnableinterface.
[ReceivedfromPRajesh]TOPQ:Whataresynchronizedmethodsandsynchronizedstatements?A:Synchronizedmethodsaremethodsthatareusedtocontrolaccesstoanobject.Athreadonlyexecutesasynchronizedmethodafterithasacquiredthelockforthemethod'sobjectorclass.Synchronizedstatementsaresimilartosynchronizedmethods.Asynchronizedstatementcanonlybeexecutedafterathreadhasacquiredthelockfortheobjectorclassreferencedinthesynchronizedstatement.
[ReceivedfromPRajesh]TOPQ:WhatisExternalizable?A:ExternalizableisanInterfacethatextendsSerializableInterface.AndsendsdataintoStreamsinCompressedFormat.Ithastwomethods,writeExternal(ObjectOuputout)andreadExternal(ObjectInputin)[ReceivedfromVenkateswaraManam]TOP
Q:WhatmodifiersareallowedformethodsinanInterface?A:Onlypublicandabstractmodifiersareallowedformethodsininterfaces.[ReceivedfromPRajesh]TOPQ:Whataresomealternativestoinheritance?
7/31/2019 Cs506 Helping Material
21/26
A:Delegationisanalternativetoinheritance.Delegationmeansthatyouincludeaninstanceofanotherclassasaninstancevariable,andforwardmessagestotheinstance.Itisoftensaferthaninheritancebecauseitforcesyoutothinkabouteachmessageyouforward,becausetheinstanceisofaknownclass,ratherthananewclass,andbecauseitdoesn'tforceyoutoacceptallthemethodsofthesuperclass:youcanprovideonlythemethodsthatreallymakesense.Ontheotherhand,itmakesyouwritemorecode,anditishardertore-use(becauseitisnotasubclass).[ReceivedfromPRajesh]TOPQ:Whatdoesitmeanthatamethodorfieldis"static"?A:Staticvariablesandmethodsareinstantiatedonlyonceperclass.Inotherwordstheyareclassvariables,notinstancevariables.Ifyouchangethevalueofastaticvariableinaparticularobject,thevalueofthatvariablechangesforallinstancesofthatclass.Staticmethodscanbereferencedwiththenameoftheclassratherthanthenameofaparticularobjectoftheclass(thoughthatworkstoo).That'showlibrarymethodslikeSystem.out.println()workoutisastaticfieldinthejava.lang.Systemclass.
[ReceivedfromPRajesh]TOPQ:Whatisthedifferencebetweenpreemptiveschedulingandtimeslicing?A:Underpreemptivescheduling,thehighestprioritytaskexecutesuntilitentersthewaitingordeadstatesorahigherprioritytaskcomesintoexistence.Undertimeslicing,ataskexecutesforapredefinedsliceoftimeandthenreentersthepoolofreadytasks.Theschedulerthendetermineswhichtaskshouldexecutenext,basedonpriorityandotherfactors.
[ReceivedfromPRajesh]TOPQ:Whatisthecatchordeclareruleformethoddeclarations?A:Ifacheckedexceptionmaybethrownwithinthebodyofamethod,themethodmusteithercatchtheexceptionordeclareitinitsthrowsclause.[ReceivedfromPRajesh]TOPHowareObserverandObservableused?
A:ObjectsthatsubclasstheObservableclassmaintainalistofobservers.WhenanObservableobjectisupdateditinvokestheupdate()methodofeachofitsobserverstonotifytheobserversthatithaschangedstate.TheObserverinterfaceisimplementedbyobjectsthatobserveObservableobjects.[ReceivedfromVenkateswaraManam]TOPQ:
7/31/2019 Cs506 Helping Material
22/26
Whatissynchronizationandwhyisitimportant?A:Withrespecttomultithreading,synchronizationisthecapabilitytocontroltheaccessofmultiplethreadstosharedresources.Withoutsynchronization,itispossibleforonethreadtomodifyasharedobjectwhileanotherthreadisintheprocessofusingorupdatingthatobject'svalue.Thisoftenleadstosignificanterrors.[ReceivedfromVenkateswaraManam]TOPQ:HowdoesJavahandleintegeroverflowsandunderflows?A:Itusesthoseloworderbytesoftheresultthatcanfitintothesizeofthetypeallowedbytheoperation.[ReceivedfromVenkateswaraManam]TOPQ:Doesgarbagecollectionguaranteethataprogramwillnotrunoutofmemory?A:Garbagecollectiondoesnotguaranteethataprogramwillnotrunoutofmemory.
Itispossibleforprogramstouseupmemoryresourcesfasterthantheyaregarbagecollected.Itisalsopossibleforprogramstocreateobjectsthatarenotsubjecttogarbagecollection.[ReceivedfromVenkateswaraManam]TOPQ:Whatisthedifferencebetweenpreemptiveschedulingandtimeslicing?A:Underpreemptivescheduling,thehighestprioritytaskexecutesuntilitentersthewaitingordeadstatesorahigherprioritytaskcomesintoexistence.Under
timeslicing,ataskexecutesforapredefinedsliceoftimeandthenreentersthepoolofreadytasks.Theschedulerthendetermineswhichtaskshouldexecutenext,basedonpriorityandotherfactors.[ReceivedfromVenkateswaraManam]TOPQ:Whenathreadiscreatedandstarted,whatisitsinitialstate?A:Athreadisinthereadystateafterithasbeencreatedandstarted.[ReceivedfromVenkateswaraManam]
TOPQ:Whatisthepurposeoffinalization?A:Thepurposeoffinalizationistogiveanunreachableobjecttheopportunitytoperformanycleanupprocessingbeforetheobjectisgarbagecollected.[ReceivedfromVenkateswaraManam]TOP
7/31/2019 Cs506 Helping Material
23/26
Q:WhatistheLocaleclass?A:TheLocaleclassisusedtotailorprogramoutputtotheconventionsofaparticulargeographic,political,orculturalregion.[ReceivedfromVenkateswaraManam]TOPQ:Whatisthedifferencebetweenawhilestatementandadostatement?A:Awhilestatementchecksatthebeginningofalooptoseewhetherthenextloopiterationshouldoccur.Adostatementchecksattheendofalooptoseewhetherthenextiterationofaloopshouldoccur.Thedostatementwillalwaysexecutethebodyofaloopatleastonce.[ReceivedfromVenkateswaraManam]TOPQ:Whatisthedifferencebetweenstaticandnon-staticvariables?A:
Astaticvariableisassociatedwiththeclassasawholeratherthanwithspecificinstancesofaclass.Non-staticvariablestakeonuniquevalueswitheachobjectinstance.[ReceivedfromVenkateswaraManam]TOPQ:Howarethis()andsuper()usedwithconstructors?A:This()isusedtoinvokeaconstructorofthesameclass.super()isusedtoinvokeasuperclassconstructor.
[ReceivedfromVenkateswaraManam]TOPQ:Whataresynchronizedmethodsandsynchronizedstatements?A:Synchronizedmethodsaremethodsthatareusedtocontrolaccesstoanobject.Athreadonlyexecutesasynchronizedmethodafterithasacquiredthelockforthemethod'sobjectorclass.Synchronizedstatementsaresimilartosynchronizedmethods.Asynchronizedstatementcanonlybeexecutedafterathreadhasacquiredthelockfortheobjectorclassreferencedinthesynchronizedstatement.[ReceivedfromVenkateswaraManam]
TOPQ:Whatisdaemonthreadandwhichmethodisusedtocreatethedaemonthread?A:Daemonthreadisalowprioritythreadwhichrunsintermittentlyinthebackgrounddoingthegarbagecollectionoperationforthejavaruntimesystem.setDaemonmethodisusedtocreateadaemonthread.[ReceivedfromShipraKamra]
7/31/2019 Cs506 Helping Material
24/26
TOPQ:Canappletscommunicatewitheachother?A:Atthispointintimeappletsmaycommunicatewithotherappletsrunninginthesamevirtualmachine.Iftheappletsareofthesameclass,theycancommunicateviasharedstaticvariables.Iftheappletsareofdifferentclasses,theneachwillneedareferencetothesameclasswithstaticvariables.Inanycasethebasicideaistopasstheinformationbackandforththroughastaticvariable.
AnappletcanalsogetreferencestoallotherappletsonthesamepageusingthegetApplets()methodofjava.applet.AppletContext.Onceyougetthereferencetoanapplet,youcancommunicatewithitbyusingitspublicmembers.
ItisconceivabletohaveappletsindifferentvirtualmachinesthattalktoaserversomewhereontheInternetandstoreanydatathatneedstobeserializedthere.Then,whenanotherappletneedsthisdata,itcouldconnecttothissameserver.Implementingthisisnon-trivial.[ReceivedfromKrishnaKumar]TOPQ:
WhatarethestepsintheJDBCconnection?A:WhilemakingaJDBCconnectionwegothroughthefollowingsteps:
Step1:Registerthedatabasedriverbyusing:Class.forName(\"driverclasssforthatspecificdatabase\");Step2:Nowcreateadatabaseconnectionusing:Connectioncon=DriverManager.getConnection(url,username,password);Step3:NowCreateaqueryusing:Statementstmt=Connection.Statement(\"select*fromTABLENAME\");Step4:Exceutethequery:stmt.exceuteUpdate();
[ReceivedfromShriPrakashKunwar]TOPQ:Howdoesatrystatementdeterminewhichcatchclauseshouldbeusedtohandleanexception?A:Whenanexceptionisthrownwithinthebodyofatrystatement,thecatchclausesofthetrystatementareexaminedintheorderinwhichtheyappear.Thefirstcatchclausethatiscapableofhandlingtheexceptionisexecuted.Theremainingcatchclausesareignored.?Reply
MessageRSSMuhammadYousufSignOutInboxMyCommentWallFriendsInviteSettingsUniversityServices
7/31/2019 Cs506 Helping Material
25/26
+VUOrientation
+StudentsHandbook
+OpenCourseware
+VULMSLoginHere
+VUOfficialSite
+VUEmail
+Handouts/Books
+VUContentLibrary
+VUBookShop
+VUTVChannels
+VUContactsList
+VURadio
+CampusCareerPortal
+VUAlumni
+Vu-BytesMagazine
+VUSports
+HECDigitalLibrary
+VULectureVideosTopMembersToday1
SanaSunny?2AbdulRehmanAnsari????3+FaheemSaqib+4++1dDyz@r@++5+oOAamirOo+RSSViewAllInfo+VUStudentsTeam
+BecomeaTeamMember+ModeratorsGroup+ReportanIssue+OnlineSafety+Disclaimer+AdvertisewithUs+SiteFAQ&RulesCreatedBy:M.TariqMalik
DesignedBy:Amel
7/31/2019 Cs506 Helping Material
26/26
ChiefAdmin:BlackMist
Management:Moderators
+AwardsBadgesLists
FollowUsonGoogle+
LikeOurFacebookPage2012CreatedbyM.TariqMalik.Badges|ReportanIssue|TermsofService
Mail:[email protected](67)MainChatRoom100+
Readmore:Helpingmaterialforpaperscs506-VirtualUniversityofPakistanhttp://vustudents.ning.com/group/cs506webdesignanddevelopment/forum/topics/helping-material-for-papers-cs506#ixzz1vFurpqCy