Sie sind auf Seite 1von 13

Master list of Java interview questions 115 questions

By admin | July 18, 2005 115 questions total, not for the weak. Covers everythin from !asi"s to J#BC "onne"tivity, $%& and J'(. 1. What is the difference between procedural and object-oriented programs?) a* +n ,ro"edural ,ro ram, ,ro rammin lo i" follows "ertain ,ro"edures and the instru"tions are e-e"uted one after another. +n ..( ,ro ram, unit of ,ro ram is o!/e"t, whi"h is nothin !ut "om!ination of data and "ode. !* +n ,ro"edural ,ro ram, data is e-,osed to the whole ,ro ram whereas in ..(s ,ro ram, it is a""essi!le with in the o!/e"t and whi"h in turn assures the se"urity of the "ode. 2. What are Encapsulation !nheritance and "ol#morphism?) 0n"a,sulation is the me"hanism that !inds to ether "ode and data it mani,ulates and kee,s !oth safe from outside interferen"e and misuse. +nheritan"e is the ,ro"ess !y whi"h one o!/e"t a"quires the ,ro,erties of another o!/e"t. (olymor,hism is the feature that allows one interfa"e to !e used for eneral "lass a"tions. 1. What is the difference between $ssignment and !nitiali%ation? ) $ssi nment "an !e done as many times as desired whereas initiali2ation "an !e done only on"e. 3. What is &&"s?) .!/e"t oriented ,ro rammin or ani2es a ,ro ram around its data, i. e. , o!/e"ts and a set of well defined interfa"es to that data. $n o!/e"t) oriented ,ro ram "an !e "hara"teri2ed as data "ontrollin a""ess to "ode. 5. What are 'lass 'onstructor and "rimitive data t#pes?) Class is a tem,late for multi,le o!/e"ts with similar features and it is a !lue ,rint for o!/e"ts. +t defines a ty,e of o!/e"t a""ordin to the data the o!/e"t "an hold and the o,erations the o!/e"t "an ,erform. Constru"tor is a s,e"ial kind of method that determines how an o!/e"t is initiali2ed when "reated. (rimitive data ty,es are 8 ty,es and they are4 !yte, short, int, lon , float, dou!le, !oolean, "har. 5. What is an &bject and how do #ou allocate memor# to it?) .!/e"t is an instan"e of a "lass and it is a software unit that "om!ines a stru"tured set of data with a set of o,erations for ins,e"tin and mani,ulatin that data. %hen an o!/e"t is "reated usin new o,erator, memory is allo"ated to it. 6. What is the difference between constructor and method?) Constru"tor will !e automati"ally invoked when an o!/e"t is "reated whereas method has to !e "alled e-,li"itly. 8. What are methods and how are the# defined?) 7ethods are fun"tions that o,erate on instan"es of "lasses in whi"h they are defined. .!/e"ts "an "ommuni"ate with ea"h other usin methods and "an "all methods in other "lasses. 7ethod definition has four ,arts. &hey are name of the method, ty,e of o!/e"t or ,rimitive ty,e the method returns, a list of ,arameters and the !ody of

the method. $ method8s si nature is a "om!ination of the first three ,arts mentioned a!ove. 9. What is the use of bin and lib in J()?) Bin "ontains all tools su"h as /ava", a,,letviewer, awt tool, et"., whereas li! "ontains $(+ and all ,a"ka es. 10. What is casting?) Castin is used to "onvert the value of one ty,e to another. 11. *ow man# wa#s can an argument be passed to a subroutine and e+plain them?) $n ar ument "an !e ,assed in two ways. &hey are ,assin !y value and ,assin !y referen"e. (assin !y value4 &his method "o,ies the value of an ar ument into the formal ,arameter of the su!routine. (assin !y referen"e4 +n this method, a referen"e to an ar ument :not the value of the ar ument* is ,assed to the ,arameter. 12. What is the difference between an argument and a parameter?) %hile definin method, varia!les ,assed in the method are "alled ,arameters. %hile usin those methods, values ,assed to those varia!les are "alled ar uments. 11. What are different t#pes of access modifiers?) ,u!li"4 $ny thin de"lared as ,u!li" "an !e a""essed from anywhere. ,rivate4 $ny thin de"lared as ,rivate "an8t !e seen outside of its "lass. ,rote"ted4 $ny thin de"lared as ,rote"ted "an !e a""essed !y "lasses in the same ,a"ka e and su!"lasses in the other ,a"ka es. default modifier 4 Can !e a""essed only to "lasses in the same ,a"ka e. 13. What is final finali%e,- and finall#?) final 4 final keyword "an !e used for "lass, method and varia!les. $ final "lass "annot !e su!"lassed and it ,revents other ,ro rammers from su!"lassin a se"ure "lass to invoke inse"ure methods. $ final method "an8t !e overridden. $ final varia!le "an8t "han e from its initiali2ed value. finali2e:* 4 finali2e:* method is used /ust !efore an o!/e"t is destroyed and "an !e "alled /ust ,rior to ar!a e "olle"tion. finally 4 finally, a key word used in e-"e,tion handlin , "reates a !lo"k of "ode that will !e e-e"uted after a try;"at"h !lo"k has "om,leted and !efore the "ode followin the try;"at"h !lo"k. &he finally !lo"k will e-e"ute whether or not an e-"e,tion is thrown. <or e-am,le, if a method o,ens a file u,on e-it, then you will not want the "ode that "loses the file to !e !y,assed !y the e-"e,tion)handlin me"hanism. &his finally keyword is desi ned to address this "ontin en"y. 15. What is ./!'&(E?) =ni"ode is used for internal re,resentation of "hara"ters and strin s and it uses 15 !its to re,resent ea"h other. 15. What is 0arbage 'ollection and how to call it e+plicitl#?) %hen an o!/e"t is no lon er referred to !y any varia!le, /ava automati"ally re"laims memory used !y that o!/e"t. &his is known as ar!a e "olle"tion. 'ystem. ":* method may !e used to "all it e-,li"itly. 16. What is finali%e,- method?) finali2e :* method is used /ust !efore an o!/e"t is destroyed and "an !e "alled /ust ,rior to ar!a e "olle"tion. 18. What are 1ransient and 2olatile Modifiers?) &ransient4 &he transient modifier a,,lies to varia!les only and it is not stored as ,art of its o!/e"t8s (ersistent state. &ransient varia!les are not seriali2ed. >olatile4 >olatile modifier a,,lies to varia!les only and it tells the "om,iler that the varia!le modified !y volatile "an !e "han ed une-,e"tedly !y other ,arts of the ,ro ram. 19. What is method overloading and method overriding?) 7ethod overloadin 4 %hen a method in a "lass havin the same method name with different ar uments

is said to !e method overloadin . 7ethod overridin 4 %hen a method in a "lass havin the same method name with same ar uments is said to !e method overridin . 20. What is difference between overloading and overriding?) a* +n overloadin , there is a relationshi, !etween methods availa!le in the same "lass whereas in overridin , there is relationshi, !etween a su,er"lass method and su!"lass method. !* .verloadin does not !lo"k inheritan"e from the su,er"lass whereas overridin !lo"ks inheritan"e from the su,er"lass. "* +n overloadin , se,arate methods share the same name whereas in overridin , su!"lass method re,la"es the su,er"lass. d* .verloadin must have different method si natures whereas overridin must have same si nature. 21. What is meant b# !nheritance and what are its advantages?) +nheritan"e is the ,ro"ess of inheritin all the features from a "lass. &he advanta es of inheritan"e are reusa!ility of "ode and a""essi!ility of varia!les and methods of the su,er "lass !y su!"lasses. 22. What is the difference between this,- and super,-?) this:* "an !e used to invoke a "onstru"tor of the same "lass whereas su,er:* "an !e used to invoke a su,er "lass "onstru"tor. 21. What is the difference between superclass and subclass?) $ su,er "lass is a "lass that is inherited whereas su! "lass is a "lass that does the inheritin . 23. What modifiers ma# be used with top-level class?) ,u!li", a!stra"t and final "an !e used for to,)level "lass. 25. What are inner class and anon#mous class?) +nner "lass 4 "lasses defined in other "lasses, in"ludin those defined in methods are "alled inner "lasses. $n inner "lass "an have any a""essi!ility in"ludin ,rivate. $nonymous "lass 4 $nonymous "lass is a "lass defined inside a method without a name and is instantiated and de"lared in the same ,la"e and "annot have e-,li"it "onstru"tors. 25. What is a pac3age?) $ ,a"ka e is a "olle"tion of "lasses and interfa"es that ,rovides a hi h)level layer of a""ess ,rote"tion and name s,a"e mana ement. 26. What is a reflection pac3age?) /ava. lan . refle"t ,a"ka e has the a!ility to analy2e itself in runtime. 28. What is interface and its use?) +nterfa"e is similar to a "lass whi"h may "ontain method8s si nature only !ut not !odies and it is a formal set of method and "onstant de"larations that must !e defined !y the "lass that im,lements it. +nterfa"es are useful for4 a*#e"larin methods that one or more "lasses are e-,e"ted to im,lement !*Ca,turin similarities !etween unrelated "lasses without for"in a "lass relationshi,. "*#eterminin an o!/e"t8s ,ro rammin interfa"e without revealin the a"tual !ody of the "lass. 29. What is an abstract class?) $n a!stra"t "lass is a "lass desi ned with im,lementation a,s for su!"lasses to fill in and is deli!erately in"om,lete. 10. What is the difference between !nteger and int?) a* +nte er is a "lass defined in the /ava. lan ,a"ka e, whereas int is a ,rimitive data ty,e defined in the Java lan ua e itself. Java does not automati"ally "onvert from one to the other. !* +nte er "an !e used as an ar ument for a method that requires an o!/e"t, whereas int "an !e used for "al"ulations.

11. What is a cloneable interface and how man# methods does it contain?) +t is not havin any method !e"ause it is a &$??0# or 7$@A0@ interfa"e. 12. What is the difference between abstract class and interface?) a* $ll the methods de"lared inside an interfa"e are a!stra"t whereas a!stra"t "lass must have at least one a!stra"t method and others may !e "on"rete or a!stra"t. !* +n a!stra"t "lass, key word a!stra"t must !e used for the methods whereas interfa"e we need not use that keyword for the methods. "* $!stra"t "lass must have su!"lasses whereas interfa"e "an8t have su!"lasses. 11. 'an #ou have an inner class inside a method and what variables can #ou access?) Bes, we "an have an inner "lass inside a method and final varia!les "an !e a""essed. 13. What is the difference between 4tring and 4tring 5uffer?) a* 'trin o!/e"ts are "onstants and immuta!le whereas 'trin Buffer o!/e"ts are not. !* 'trin "lass su,,orts "onstant strin s whereas 'trin Buffer "lass su,,orts rowa!le and modifia!le strin s. 15. What is the difference between $rra# and vector?) $rray is a set of related data ty,e and stati" whereas ve"tor is a rowa!le array of o!/e"ts and dynami". 15. What is the difference between e+ception and error?) &he e-"e,tion "lass defines mild error "onditions that your ,ro ram en"ounters. 0-"e,tions "an o""ur when tryin to o,en the file, whi"h does not e-ist, the network "onne"tion is disru,ted, o,erands !ein mani,ulated are out of ,res"ri!ed ran es, the "lass file you are interested in loadin is missin . &he error "lass defines serious error "onditions that you should not attem,t to re"over from. +n most "ases it is advisa!le to let the ,ro ram terminate when su"h an error is en"ountered. 16. What is the difference between process and thread?) (ro"ess is a ,ro ram in e-e"ution whereas thread is a se,arate ,ath of e-e"ution in a ,ro ram. 18. What is multithreading and what are the methods for inter-thread communication and what is the class in which these methods are defined?) 7ultithreadin is the me"hanism in whi"h more than one thread run inde,endent of ea"h other within the ,ro"ess. wait :*, notify :* and notify$ll:* methods "an !e used for inter)thread "ommuni"ation and these methods are in .!/e"t "lass. wait:* 4 %hen a thread e-e"utes a "all to wait:* method, it surrenders the o!/e"t lo"k and enters into a waitin state. notify:* or notify$ll:* 4 &o remove a thread from the waitin state, some other thread must make a "all to notify:* or notify$ll:* method on the same o!/e"t. 19. What is the class and interface in java to create thread and which is the most advantageous method?) &hread "lass and @unna!le interfa"e "an !e used to "reate threads and usin @unna!le interfa"e is the most advanta eous method to "reate threads !e"ause we need not e-tend thread "lass here. 30. What are the states associated in the thread?) &hread "ontains ready, runnin , waitin and dead states. 31. What is s#nchroni%ation?) 'yn"hroni2ation is the me"hanism that ensures that only one thread is a""essed the resour"es at a time. 32. When #ou will s#nchroni%e a piece of #our code?) %hen you e-,e"t your "ode will !e a""essed !y different threads and these threads may "han e a ,arti"ular data "ausin data "orru,tion.

31. What is deadloc3?) %hen two threads are waitin ea"h other and "an8t ,re"ede the ,ro ram is said to !e deadlo"k. 33. What is daemon thread and which method is used to create the daemon thread?) #aemon thread is a low ,riority thread whi"h runs intermittently in the !a"k round doin the ar!a e "olle"tion o,eration for the /ava runtime system. set#aemon method is used to "reate a daemon thread. 35. $re there an# global variables in Java which can be accessed b# other part of #our program?) Co, it is not the main method in whi"h you define varia!les. ?lo!al varia!les is not ,ossi!le !e"ause "on"e,t of en"a,sulation is eliminated here. 35. What is an applet?) $,,let is a dynami" and intera"tive ,ro ram that runs inside a we! ,a e dis,layed !y a /ava "a,a!le !rowser. 36. What is the difference between applications and applets?) a*$,,li"ation must !e run on lo"al ma"hine whereas a,,let needs no e-,li"it installation on lo"al ma"hine. !*$,,li"ation must !e run e-,li"itly within a /ava)"om,ati!le virtual ma"hine whereas a,,let loads and runs itself automati"ally in a /ava)ena!led !rowser. d*$,,li"ation starts e-e"ution with its main method whereas a,,let starts e-e"ution with its init method. e*$,,li"ation "an run with or without ra,hi"al user interfa"e whereas a,,let must run within a ra,hi"al user interfa"e. 38. *ow does applet recogni%e the height and width?) =sin et(arameters:* method. 39. When do #ou use codebase in applet?) %hen the a,,let "lass file is not in the same dire"tory, "ode!ase is used. 50. What is the lifec#cle of an applet?) init:* method ) Can !e "alled when an a,,let is first loaded start:* method ) Can !e "alled ea"h time an a,,let is started. ,aint:* method ) Can !e "alled when the a,,let is minimi2ed or ma-imi2ed. sto,:* method ) Can !e used when the !rowser moves off the a,,let8s ,a e. destroy:* method ) Can !e "alled when the !rowser is finished with the a,,let. 51. *ow do #ou set securit# in applets?) usin set'e"urity7ana er:* method 52. What is an event and what are the models available for event handling?) $n event is an event o!/e"t that des"ri!es a state of "han e in a sour"e. +n other words, event o""urs when an a"tion is enerated, like ,ressin !utton, "li"kin mouse, sele"tin a list, et". &here are two ty,es of models for handlin events and they are4 a* event)inheritan"e model and !* event)dele ation model 51. What are the advantages of the model over the event-inheritance model?) &he event)dele ation model has two advanta es over the event)inheritan"e model. &hey are4 a*+t ena!les event handlin !y o!/e"ts other than the ones that enerate the events. &his allows a "lean se,aration !etween a "om,onent8s desi n and its use. !*+t ,erforms mu"h !etter in a,,li"ations where many events are enerated. &his ,erforman"e im,rovement is due to the fa"t that the event)dele ation model does not have to !e re,eatedly ,ro"ess unhandled events as is the "ase of the event)inheritan"e. 53. What is source and listener?) sour"e 4 $ sour"e is an o!/e"t that enerates an event. &his o""urs when the internal state of that o!/e"t "han es in some way. listener 4 $ listener is an o!/e"t that is notified when an event o""urs. +t has two ma/or requirements. <irst, it must have !een re istered with one or more sour"es

to re"eive notifi"ations a!out s,e"ifi" ty,es of events. 'e"ond, it must im,lement methods to re"eive and ,ro"ess these notifi"ations. 55. What is adapter class?) $n ada,ter "lass ,rovides an em,ty im,lementation of all methods in an event listener interfa"e. $da,ter "lasses are useful when you want to re"eive and ,ro"ess only some of the events that are handled !y a ,arti"ular event listener interfa"e. Bou "an define a new "lass to a"t listener !y e-tendin one of the ada,ter "lasses and im,lementin only those events in whi"h you are interested. <or e-am,le, the 7ouse7otion$da,ter "lass has two methods, mouse#ra ed:*and mouse7oved:*. &he si natures of these em,ty are e-a"tly as defined in the 7ouse7otionDistener interfa"e. +f you are interested in only mouse dra events, then you "ould sim,ly e-tend 7ouse7otion$da,ter and im,lement mouse#ra ed:* . 55. What is meant b# controls and what are different t#pes of controls in $W1?) Controls are "om,onents that allow a user to intera"t with your a,,li"ation and the $%& su,,orts the followin ty,es of "ontrols4 Da!els, (ush Buttons, Che"k Bo-es, Choi"e Dists, Dists, '"roll!ars, &e-t Com,onents. &hese "ontrols are su!"lasses of Com,onent. 56. What is the difference between choice and list?) $ Choi"e is dis,layed in a "om,a"t form that requires you to ,ull it down to see the list of availa!le "hoi"es and only one item may !e sele"ted from a "hoi"e. $ Dist may !e dis,layed in su"h a way that several list items are visi!le and it su,,orts the sele"tion of one or more list items. 58. What is the difference between scrollbar and scrollpane?) $ '"roll!ar is a Com,onent, !ut not a Container whereas '"roll,ane is a Conatiner and handles its own events and ,erform its own s"rollin . 59. What is a la#out manager and what are different t#pes of la#out managers available in java $W1?) $ layout mana er is an o!/e"t that is used to or ani2e "om,onents in a "ontainer. &he different layouts are availa!le are <lowDayout, BorderDayout, CardDayout, ?ridDayout and ?ridBa Dayout. 50. *ow are the elements of different la#outs organi%ed?) <lowDayout4 &he elements of a <lowDayout are or ani2ed in a to, to !ottom, left to ri ht fashion. BorderDayout4 &he elements of a BorderDayout are or ani2ed at the !orders :Corth, 'outh, 0ast and %est* and the "enter of a "ontainer. CardDayout4 &he elements of a CardDayout are sta"ked, on to, of the other, like a de"k of "ards. ?ridDayout4 &he elements of a ?ridDayout are of equal si2e and are laid out usin the square of a rid. ?ridBa Dayout4 &he elements of a ?ridBa Dayout are or ani2ed a""ordin to a rid. Eowever, the elements are of different si2e and may o""u,y more than one row or "olumn of the rid. +n addition, the rows and "olumns may have different si2es. 51. Which containers use a 5order la#out as their default la#out?) %indow, <rame and #ialo "lasses use a BorderDayout as their layout. 52. Which containers use a 6low la#out as their default la#out?) (anel and $,,let "lasses use the <lowDayout as their default layout. 51. What are wrapper classes?) %ra,,er "lasses are "lasses that allow ,rimitive ty,es to !e a""essed as o!/e"ts.

53. What are 2ector *ashtable 7in3ed7ist and Enumeration?) >e"tor 4 &he >e"tor "lass ,rovides the "a,a!ility to im,lement a rowa!le array of o!/e"ts. Eashta!le 4 &he Eashta!le "lass im,lements a Eashta!le data stru"ture. $ Eashta!le inde-es and stores o!/e"ts in a di"tionary usin hash "odes as the o!/e"t8s keys. Eash "odes are inte er values that identify o!/e"ts. DinkedDist4 @emovin or insertin elements in the middle of an array "an !e done usin DinkedDist. $ DinkedDist stores ea"h o!/e"t in a se,arate link whereas an array stores o!/e"t referen"es in "onse"utive lo"ations. 0numeration4 $n o!/e"t that im,lements the 0numeration interfa"e enerates a series of elements, one at a time. +t has two methods, namely has7ore0lements:* and ne-t0lement:*. Eas7ore0lemnts:* tests if this enumeration has more elements and ne-t0lement method returns su""essive elements of the series. 55. What is the difference between set and list?) 'et stores elements in an unordered way !ut does not "ontain du,li"ate elements, whereas list stores elements in an ordered way !ut may "ontain du,li"ate elements. 55. What is a stream and what are the t#pes of 4treams and classes of the 4treams?) $ 'tream is an a!stra"tion that either ,rodu"es or "onsumes information. &here are two ty,es of 'treams and they are4 Byte 'treams4 (rovide a "onvenient means for handlin in,ut and out,ut of !ytes. Chara"ter 'treams4 (rovide a "onvenient means for handlin in,ut F out,ut of "hara"ters. Byte 'treams "lasses4 $re defined !y usin two a!stra"t "lasses, namely +n,ut'tream and .ut,ut'tream. Chara"ter 'treams "lasses4 $re defined !y usin two a!stra"t "lasses, namely @eader and %riter. 56. What is the difference between 8eader9Writer and !nput4tream9&utput 4tream?) &he @eader;%riter "lass is "hara"ter)oriented and the +n,ut'tream;.ut,ut'tream "lass is !yte)oriented. 58. What is an !9& filter?) $n +;. filter is an o!/e"t that reads from one stream and writes to another, usually alterin the data in some way as it is ,assed from one stream to another. 59. What is seriali%ation and deseriali%ation?) 'eriali2ation is the ,ro"ess of writin the state of an o!/e"t to a !yte stream. #eseriali2ation is the ,ro"ess of restorin these o!/e"ts. 60. What is J(5'?) J#BC is a set of Java $(+ for e-e"utin 'GD statements. &his $(+ "onsists of a set of "lasses and interfa"es to ena!le ,ro rams to write ,ure Java #ata!ase a,,li"ations. 61. What are drivers available?) a* J#BC).#BC Brid e driver !* Cative $(+ (artly)Java driver "* J#BC)Cet (ure Java driver d* Cative)(roto"ol (ure Java driver 62. What is the difference between J(5' and &(5'?) a* .B#C is for 7i"rosoft and J#BC is for Java a,,li"ations. !* .#BC "an8t !e dire"tly used with Java !e"ause it uses a C interfa"e. "* .#BC makes use of ,ointers whi"h have !een removed totally from Java. d* .#BC mi-es sim,le and advan"ed features to ether and has "om,le- o,tions for sim,le queries. But J#BC is desi ned to kee, thin s sim,le while allowin advan"ed "a,a!ilities when required. e* .#BC requires manual installation of the .#BC driver mana er and driver on all "lient ma"hines. J#BC drivers are written in Java and J#BC "ode is automati"ally

installa!le, se"ure, and ,orta!le on all ,latforms. f* J#BC $(+ is a natural Java interfa"e and is !uilt on .#BC. J#BC retains some of the !asi" features of .#BC. 61. What are the t#pes of J(5' (river Models and e+plain them?) &here are two ty,es of J#BC #river 7odels and they are4 a* &wo tier model and !* &hree tier model &wo tier model4 +n this model, Java a,,li"ations intera"t dire"tly with the data!ase. $ J#BC driver is required to "ommuni"ate with the ,arti"ular data!ase mana ement system that is !ein a""essed. 'GD statements are sent to the data!ase and the results are iven to user. &his model is referred to as "lient;server "onfi uration where user is the "lient and the ma"hine that has the data!ase is "alled as the server. &hree tier model4 $ middle tier is introdu"ed in this model. &he fun"tions of this model are4 a* Colle"tion of 'GD statements from the "lient and handin it over to the data!ase, !* @e"eivin results from data!ase to the "lient and "* 7aintainin "ontrol over a""essin and u,datin of the a!ove. 63. What are the steps involved for ma3ing a connection with a database or how do #ou connect to a database?a* Doadin the driver 4 &o load the driver, Class. forCame:* method is used. Class. forCame:Hsun. /d!". od!". Jd!".d!"#riverH*I %hen the driver is loaded, it re isters itself with the /ava. sql. #river7ana er "lass as an availa!le data!ase driver. !* 7akin a "onne"tion with data!ase4 &o o,en a "onne"tion to a iven data!ase, #river7ana er. etConne"tion:* method is used. Conne"tion "on J #river7ana er. etConne"tion :H/d!"4od!"4somed!H, KuserH, K,asswordH*I "* 0-e"utin 'GD statements 4 &o e-e"ute a 'GD query, /ava. sql. statements "lass is used. "reate'tatement:* method of Conne"tion to o!tain a new 'tatement o!/e"t. 'tatement stmt J "on. "reate'tatement:*I $ query that returns data "an !e e-e"uted usin the e-e"uteGuery:* method of 'tatement. &his method e-e"utes the statement and returns a /ava. sql. @esult'et that en"a,sulates the retrieved data4 @esult'et rs J stmt. e-e"uteGuery:H'0D0C& L <@.7 some ta!leH*I d* (ro"ess the results 4 @esult'et returns one row at a time. Ce-t:* method of @esult'et o!/e"t "an !e "alled to move to the ne-t row. &he et'trin :* and et.!/e"t:* methods are used for retrievin "olumn values4 while:rs. ne-t:** M 'trin event J rs. et'trin :HeventH*I .!/e"t "ount J :+nte er* rs. et.!/e"t:H"ountH*I 65. What t#pe of driver did #ou use in project?) J#BC).#BC Brid e driver :is a driver that uses native:C lan ua e* li!raries and makes "alls to an e-istin .#BC driver to a""ess a data!ase en ine*. 65. What are the t#pes of statements in J(5'?) 'tatement4 to !e used "reate'tatement:* method for e-e"utin sin le 'GD statement (re,ared'tatement N &o !e used ,re,ared'tatement:* method for e-e"utin same 'GD statement over and over. Calla!le'tatement N &o !e used ,re,areCall:* method for multi,le 'GD statements over and over. 66. What is stored procedure?) 'tored ,ro"edure is a rou, of 'GD statements that forms a lo i"al unit and ,erforms a ,arti"ular task. 'tored (ro"edures are used to en"a,sulate a set of o,erations or queries to e-e"ute on data!ase. 'tored ,ro"edures "an !e "om,iled and e-e"uted with different ,arameters and results and may have any "om!ination of in,ut;out,ut ,arameters.

68. *ow to create and call stored procedures?) &o "reate stored ,ro"edures4 Create ,ro"edure ,ro"edurename :s,e"ify in, out and in out ,arameters* B0?+C $ny multi,le 'GD statementI 0C#I &o "all stored ,ro"edures4 Calla!le'tatement "smt J "on. ,re,areCall:HM"all ,ro"edure name:O,O*PH*I "smt. re ister.ut(arameter:"olumn no. , data ty,e*I "smt. set+nt:"olumn no. , "olumn name* "smt. e-e"ute:*I 69. What is servlet?) 'ervlets are modules that e-tend request;res,onse)oriented servers, su"h as /ava)ena!led we! servers. <or e-am,le, a servlet mi ht !e res,onsi!le for takin data in an E&7D order)entry form and a,,lyin the !usiness lo i" used to u,date a "om,any8s order data!ase. 80. What are the classes and interfaces for servlets?) &here are two ,a"ka es in servlets and they are /ava-. servlet and 81. What is the difference between an applet and a servlet?) a* 'ervlets are to servers what a,,lets are to !rowsers. !* $,,lets must have ra,hi"al user interfa"es whereas servlets have no ra,hi"al user interfa"es. 82. What is the difference between do"ost and do0et methods?) a* do?et:* method is used to et information, while do(ost:* method is used for ,ostin information. !* do?et:* requests "an8t send lar e amount of information and is limited to 230)255 "hara"ters. Eowever, do(ost:*requests ,asses all of its data, of unlimited len th. "* $ do?et:* request is a,,ended to the request =@D in a query strin and this allows the e-"han e is visi!le to the "lient, whereas a do(ost:* request ,asses dire"tly over the so"ket "onne"tion as ,art of its E&&( request !ody and the e-"han e are invisi!le to the "lient. 81. What is the life c#cle of a servlet?) 0a"h 'ervlet has the same life "y"le4 a* $ server loads and initiali2es the servlet !y init :* method. !* &he servlet handles 2ero or more "lient8s requests throu h servi"e:* method. "* &he server removes the servlet throu h destroy:* method. 83. Who is loading the init,- method of servlet?) %e! server 85. What are the different servers available for developing and deplo#ing 4ervlets?) a* Java %e! 'erver !* J@un * $,a"he 'erver h* Cets"a,e +nformation 'erver i* %e! Do i" 85. *ow man# wa#s can we trac3 client and what are the#?) &he servlet $(+ ,rovides two ways to tra"k "lient state and they are4 a* =sin 'ession tra"kin and !* =sin Cookies. 86. What is session trac3ing and how do #ou trac3 a user session in servlets?) 'ession tra"kin is a me"hanism that servlets use to maintain state a!out a series requests from the same user a"ross some ,eriod of time. &he methods used for session tra"kin are4 a* =ser $uthenti"ation ) o""urs when a we! server restri"ts a""ess to some of its resour"es to only those "lients that lo in usin a re"o ni2ed username and ,assword. !* Eidden form fields ) fields are added to an E&7D form that are not dis,layed in the "lient8s !rowser. %hen the form "ontainin the fields is su!mitted, the fields are sent !a"k to the server. "* =@D rewritin ) every =@D that the user "li"ks on is dynami"ally modified or rewritten to in"lude e-tra information. &he e-tra information "an !e in the form of e-tra ,ath information, added ,arameters or some "ustom, server)s,e"ifi" =@D "han e. d* Cookies ) a !it of information that is sent !y a we! server to a !rowser and whi"h "an later !e

read !a"k from that !rowser. e* Ett,'ession) ,la"es a limit on the num!er of sessions that "an e-ist in memory. &his limit is set in the session. ma-residents ,ro,erty. 88. What is 4erver-4ide !ncludes ,44!-?) 'erver)'ide +n"ludes allows em!eddin servlets within E&7D ,a es usin a s,e"ial servlet ta . +n many servlets that su,,ort servlets, a ,a e "an !e ,ro"essed !y the server to in"lude out,ut from servlets at "ertain ,oints inside the E&7D ,a e. &his is a""om,lished usin a s,e"ial internal ''+CCD=#0, whi"h ,ro"esses the servlet ta s. ''+CCD=#0 servlet will !e invoked whenever a file with an. shtml e-tension is requested. 'o E&7D files that in"lude server)side in"ludes must !e stored with an . shtml e-tension. 89. What are coo3ies and how will #ou use them?) Cookies are a me"hanism that a servlet uses to have a "lient hold a small amount of state)information asso"iated with the user. a* Create a "ookie with the Cookie "onstru"tor4 ,u!li" Cookie:'trin name, 'trin value* !* $ servlet "an send a "ookie to the "lient !y ,assin a Cookie o!/e"t to the addCookie:* method of Ett,'ervlet@es,onse4 ,u!li" void Ett,'ervlet@es,onse. addCookie:Cookie "ookie* "* $ servlet retrieves "ookies !y "allin the etCookies:* method of Ett,'ervlet@equest4 ,u!li" CookieQ R Ett,'ervlet@equest. etCookie:*. 90. !s it possible to communicate from an applet to servlet and how man# wa#s and how?) Bes, there are three ways to "ommuni"ate from an a,,let to servlet and they are4 a* E&&( Communi"ation:&e-t)!ased and o!/e"t)!ased* !* 'o"ket Communi"ation "* @7+ Communi"ation 91. What is connection pooling?) %ith servlets, o,enin a data!ase "onne"tion is a ma/or !ottlene"k !e"ause we are "reatin and tearin down a new "onne"tion for every ,a e request and the time taken to "reate "onne"tion will !e more. Creatin a "onne"tion ,ool is an ideal a,,roa"h for a "om,li"ated servlet. %ith a "onne"tion ,ool, we "an du,li"ate only the resour"es we need to du,li"ate rather than the entire servlet. $ "onne"tion ,ool "an also intelli ently mana e the si2e of the ,ool and make sure ea"h "onne"tion remains valid. $ num!er of "onne"tion ,ool ,a"ka es are "urrently availa!le. 'ome like #!Conne"tionBroker are freely availa!le from Java 0-"han e %orks !y "reatin an o!/e"t that dis,enses "onne"tions and "onne"tion +ds on request. &he Conne"tion(ool "lass maintains a Easta!le, usin Conne"tion o!/e"ts as keys and Boolean values as stored values. &he Boolean value indi"ates whether a "onne"tion is in use or not. $ ,ro ram "alls etConne"tion:* method of the Conne"tion(ool for ettin Conne"tion o!/e"t it "an useI it "alls returnConne"tion:* to ive the "onne"tion !a"k to the ,ool. 92. Wh# should we go for interservlet communication?) 'ervlets runnin to ether in the same server "ommuni"ate with ea"h other in several ways. &he three ma/or reasons to use interservlet "ommuni"ation are4 a* #ire"t servlet mani,ulation ) allows to ain a""ess to the other "urrently loaded servlets and ,erform "ertain tasks :throu h the 'ervletConte-t o!/e"t* !* 'ervlet reuse ) allows the servlet to reuse the ,u!li" methods of another servlet. "* 'ervlet "olla!oration ) requires to "ommuni"ate with ea"h other !y sharin s,e"ifi" information :throu h method invo"ation*

91. !s it possible to call servlet with parameters in the .87?) Bes. Bou "an "all a servlet with ,arameters in the synta- as :O(aram1 J --- || m2 J yyy*. 93. What is 4ervlet chaining?) 'ervlet "hainin is a te"hnique in whi"h two or more servlets "an "oo,erate in servi"in a sin le request. +n servlet "hainin , one servlet8s out,ut is ,i,ed to the ne-t servlet8s in,ut. &his ,ro"ess "ontinues until the last servlet is rea"hed. +ts out,ut is then sent !a"k to the "lient. 95. *ow do servlets handle multiple simultaneous requests?) &he server has multi,le threads that are availa!le to handle requests. %hen a request "omes in, it is assi ned to a thread, whi"h "alls a servi"e method :for e-am,le4 do?et:*, do(ost:* and servi"e:** of the servlet. <or this reason, a sin le servlet o!/e"t "an have its servi"e methods "alled !y many threads at on"e. 95. What is the difference between 1'"9!" and .("?) &C(;+( is a two)way "ommuni"ation !etween the "lient and the server and it is a relia!le and there is a "onfirmation re ardin rea"hin the messa e to the destination. +t is like a ,hone "all. =#( is a one)way "ommuni"ation only !etween the "lient and the server and it is not a relia!le and there is no "onfirmation re ardin rea"hin the messa e to the destination. +t is like a ,ostal mail. 96. What is !net address?) 0very "om,uter "onne"ted to a network has an +( address. $n +( address is a num!er that uniquely identifies ea"h "om,uter on the Cet. $n +( address is a 12)!it num!er. 98. What is (omain /aming 4ervice,(/4-?) +t is very diffi"ult to remem!er a set of num!ers:+( address* to "onne"t to the +nternet. &he #omain Camin 'ervi"e:#C'* is used to over"ome this ,ro!lem. +t ma,s one ,arti"ular +( address to a strin of "hara"ters. <or e-am,le, www. mas"om. "om im,lies "om is the domain name reserved for =' "ommer"ial sites, mos"om is the name of the "om,any and www is the name of the s,e"ifi" "om,uter, whi"h is mas"om8s server. 99. What is .87?) =@D stands for =niform @esour"e Do"ator and it ,oints to resour"e files on the +nternet. =@D has four "om,onents4 htt,4;;www. address. "om480;inde-.html, where htt, ) ,roto"ol name, address ) +( address or host name, 80 ) ,ort num!er and inde-.html ) file ,ath. 100. What is 8M! and steps involved in developing an 8M! object?) @emote 7ethod +nvo"ation :@7+* allows /ava o!/e"t that e-e"utes on one ma"hine and to invoke the method of a Java o!/e"t to e-e"ute on another ma"hine. &he ste,s involved in develo,in an @7+ o!/e"t are4 a* #efine the interfa"es !* +m,lementin these interfa"es "* Com,ile the interfa"es and their im,lementations with the /ava "om,iler d* Com,ile the server im,lementation with @7+ "om,iler e* @un the @7+ re istry f* @un the a,,li"ation 101. What is 8M! architecture?) @7+ ar"hite"ture "onsists of four layers and ea"h layer ,erforms s,e"ifi" fun"tions4 a* $,,li"ation layer ) "ontains the a"tual o!/e"t definition. !* (ro-y layer ) "onsists of stu! and skeleton. "* @emote @eferen"e layer ) ets the stream of !ytes from the trans,ort layer and sends it to the ,ro-y layer. d* &rans,ortation layer ) res,onsi!le for handlin the a"tual ma"hine)to)ma"hine "ommuni"ation.

102. what is .nicast8emote&bject?) $ll remote o!/e"ts must e-tend =ni"ast@emote.!/e"t, whi"h ,rovides fun"tionality that is needed to make o!/e"ts availa!le from remote ma"hines. 101. E+plain the methods rebind,- and loo3up,- in /aming class?) re!ind:* of the Camin "lass:found in /ava. rmi* is used to u,date the @7+ re istry on the server ma"hine. Camin . re!ind:H$dd'everH, $dd'erver+m,l*I looku,:* of the Camin "lass a""e,ts one ar ument, the rmi =@D and returns a referen"e to an o!/e"t of ty,e $dd'erver+m,l. 103. What is a Java 5ean?) $ Java Bean is a software "om,onent that has !een desi ned to !e reusa!le in a variety of different environments. 105. What is a Jar file?) Jar file allows to effi"iently de,loyin a set of "lasses and their asso"iated resour"es. &he elements in a /ar file are "om,ressed, whi"h makes downloadin a Jar file mu"h faster than se,arately downloadin several un"om,ressed files. &he ,a"ka e /ava. util. 2i, "ontains "lasses that read and write /ar files. 105. What is 5()?) B#A, Bean #evelo,ment Ait is a tool that ena!les to "reate, "onfi ure and "onne"t a set of set of Beans and it "an !e used to test Beans without writin a "ode. 106. What is J4"?) J'( is a dynami" s"ri,tin "a,a!ility for we! ,a es that allows Java as well as a few s,e"ial ta s to !e em!edded into a we! file :E&7D;S7D, et"*. &he suffi- traditionally ends with ./s, to indi"ate to the we! server that the file is a J'( files. J'( is a server side te"hnolo y ) you "an8t do any "lient side validation with it. &he advanta es are4 a* &he J'( assists in makin the E&7D more fun"tional. 'ervlets on the other hand allow out,uttin of E&7D !ut it is a tedious ,ro"ess. !* +t is easy to make a "han e and then let the J'( "a,a!ility of the we! server you are usin deal with "om,ilin it into a servlet and runnin it. 108. What are J4" scripting elements?) J'( s"ri,tin elements lets to insert Java "ode into the servlet that will !e enerated from the "urrent J'( ,a e. &here are three forms4 a* 0-,ressions of the form TUJ e-,ression UV that are evaluated and inserted into the out,ut, !* '"ri,tlets of the formthat are inserted into the servlet8s servi"e method, and "* #e"larations of the form TUW Code UVthat are inserted into the !ody of the servlet "lass, outside of any e-istin methods. 109. What are J4" (irectives?) $ J'( dire"tive affe"ts the overall stru"ture of the servlet "lass. +t usually has the followin form4TUX dire"tive attri!uteJHvalueH UV Eowever, you "an also "om!ine multi,le attri!ute settin s for a sin le dire"tive, as follows4TUX dire"tive attri!ute1JHvalue1Y attri!ute 2JHvalue2Y . . . attri!uteC JHvalueCH UV &here are two main ty,es of dire"tive4 ,a e, whi"h lets to do thin s like im,ort "lasses, "ustomi2e the servlet su,er"lass, and the likeI and in"lude, whi"h lets to insert a file into the servlet "lass at the time the J'( file is translated into a servlet 110. What are "redefined variables or implicit objects?) &o sim,lify "ode in J'( e-,ressions and s"ri,tlets, we "an use ei ht automati"ally defined varia!les, sometimes "alled im,li"it o!/e"ts. &hey are request, res,onse, out, session, a,,li"ation, "onfi , ,a eConte-t, and ,a e.

111. What are J4" $'1!&/4?) J'( a"tions use "onstru"ts in S7D synta- to "ontrol the !ehavior of the servlet en ine. Bou "an dynami"ally insert a file, reuse JavaBeans "om,onents, forward the user to another ,a e, or enerate E&7D for the Java ,lu in. $vaila!le a"tions in"lude4 /s,4in"lude ) +n"lude a file at the time the ,a e is requested. /s,4useBean ) <ind or instantiate a JavaBean. /s,4set(ro,erty ) 'et the ,ro,erty of a JavaBean. /s,4 et(ro,erty ) +nsert the ,ro,erty of a JavaBean into the out,ut. /s,4forward ) <orward the requester to a new,a e. Js,4 ,lu in ) ?enerate !rowser)s,e"ifi" "ode that makes an .BJ0C& or 07B0# 112. *ow do #ou pass data ,including Java5eans- to a J4" from a servlet?) :1* @equest Difetime4 =sin this te"hnique to ,ass !eans, a request dis,at"her :usin either Kin"ludeH or forwardH* "an !e "alled. &his !ean will disa,,ear after ,ro"essin this request has !een "om,leted. 'ervlet4 request. set$ttri!ute:HtheBeanH, myBean*I @equest#is,at"her rd J et'ervletConte-t:*. et@equest#is,at"her:Hthe,a e. /s,H*I rd. forward:request, res,onse*I J'( ($?04T/s,4 useBean idJHtheBeanH s"o,eJHrequestH "lassJH. . . . . H ;V:2* 'ession Difetime4 =sin this te"hnique to ,ass !eans that are relevant to a ,arti"ular session :su"h as in individual user lo in* over a num!er of requests. &his !ean will disa,,ear when the session is invalidated or it times out, or when you remove it. 'ervlet4 Ett,'ession session J request. et'ession:true*I session. ,ut>alue:HtheBeanH, myBean*I ;L Bou "an do a request dis,at"her here, or /ust let the !ean !e visi!le on the ne-t request L; J'( (a e4T/s,4useBean idJHtheBeanH s"o,eJHsessionH "lassJH. . . H ;V 1* $,,li"ation Difetime4 =sin this te"hnique to ,ass !eans that are relevant to all servlets and J'( ,a es in a ,arti"ular a,,, for all users. <or e-am,le, + use this to make a J#BC "onne"tion ,ool o!/e"t availa!le to the various servlets and J'( ,a es in my a,,s. &his !ean will disa,,ear when the servlet en ine is shut down, or when you remove it. 'ervlet4 ?et'ervletConte-t:*. set$ttri!ute:HtheBeanH, myBean*I J'( ($?04T/s,4useBean idJHtheBeanH s"o,eJHa,,li"ationH "lassJH. . . H ;V 111. *ow can ! set a coo3ie in J4"?) res,onse. setEeader:H'et)CookieH, K"ookie strin H*I &o ive the res,onse)o!/e"t to a !ean, write a method set@es,onse :Ett,'ervlet@es,onse res,onse* ) to the !ean, and in /s,)file4TU !ean. set@es,onse :res,onse*I UV 113. *ow can ! delete a coo3ie with J4"?) 'ay that + have a "ookie "alled Kfoo, H that + set a while a o F + want it to o away. + sim,ly4 TU Cookie killCookie J new Cookie:HfooH, null*I AillCookie. set(ath:H;H*I killCookie. set7a-$ e:0*I res,onse. addCookie:killCookie*I UV 115. *ow are 4ervlets and J4" "ages related?) J'( ,a es are fo"used around E&7D :or S7D* with Java "odes and J'( ta s inside them. %hen a we! server that has J'( su,,ort is asked for a J'( ,a e, it "he"ks to see if it has already "om,iled the ,a e into a servlet. &hus, J'( ,a es !e"ome servlets and are transformed into ,ure Java and then "om,iled, loaded into the server and e-e"uted.

Das könnte Ihnen auch gefallen