1.Sham travels 7 km north , then turns right and walks 3 km. He again turns to his righthand side and moves 7 kn forward.how many km is sham away from the place of his starting the journey? a)7 km b)3 c)8 d)17 2.Reeta drives to North of her place ofstay A and finds after travelling 25 km that she has driven in the wrong direction. she then turns to the right and travels 2 km and then again turns right and drives straigh another 25 km. how much distance she has now to cover to goback to the point from where she has started? a)25 b)2 c)5 d)68 3.Rana travels 10 km north turns left and travels 4 km and then again turns right and covers another 5km. He then turns to righthand side and travels another 4 km. how far is he from the point of starting his journey? a)15 b)8 c)5 d)none 4.Seeta and ram both start from a point towards north.Seeta turns to left after walking 10 km. Ram turns right after walking the same distance.seeta waits for some time and then walks another 5 km,whereas ram walks only 3 km. they both then return to their respective south and walk 15 km forward. how far is seeta from ram? a)15 b)10 C)8 d)12 5.A taxi driver commenced his journey from a point and drove 10 km towards north and turned left and drove another 5 km.after waiting to meet one ofhis friends ,he turned to his right and continued to drive another 10 km.He has covered a distance of 25 km so far but in which direction he now may be> a)north b)east c)west d)south 6.There is a ring road connecting points A,B,C and D.The road is in a complete circular form but having several approach roads leading to the centre. exactly in the centre of the ring road there is a tree which is 20 km from point A on the circular road.you have taken a round of the circular road starting from point A and finish at the same point after touching points B,C and D.you then drive 20km interior towards the tree from point A and from there reach somewhere in between B and C on the ring road. How much distance you have to travel from the tree to reach the point between B and C on the ring road? a)20 b)15 c)79 d)78 7.A tourist drives 10 km towards east and turns to righthand side and takes a drive of another 3 km .he then drives towards west another 3km . he then turns to his left and walks another 2km.Afterwards, he turns right and travels 7 km. how far is he from his starting pint and in which direction? a)10km east b)8km north c)5 km west d)5km south 8.Rahul walks 30 metres towards south.then turns to his right and starts walking straight till he completes another 30 meters.then again turning to his left he walks for 20 meters.he then turns to his left and walks for 30 metres.how far is he from his initial position? a)50 b)78 c)23 d)67 9.Vandana drove her car for 30 km due north. then she turned left and drove for 40 km,she then turned left again and drove yet another 30 km.again she turned left and drove her car 50km.how far do u think she actually drove her car from the initial position? a)10 B)5 c)89 d)none 10.Shalloo ran 20 m to the east, then he turned left and walked for 15m then turned right and went 25 m and then tturned right agian and went 15m . how far was shalloo from the starting point? a)45 b)35 c)25 d)15 11.A girl leaves from herhome.She first walks 30m in north west directions and then 30 . in south west direction.next she walks 30m in south east direction.finally,she turns towards her house.in which direction is she moving? a)north east b)east c)west d)south 12.From his house lokesh went 15kms to the north. then he turned west and covered 10 kms. then he turned south and covered 5kms.finally,turning to est,he covered 10kma.in what direction is he from his house? a)east b)west c)north d)south 13.Kunal walks 10km towards north.from here he walks 6km towards south.then,he walks 3km towards east.how far and in which direction is he with reference to his starting point? a)5km west b)7km west c)7km east d)5km north east 14. A man is facing south.he turns 135 degrees in the anti clockwise direction and then 180 degrees in the clock wise direction. which directon is he facing now? a)north east b)nort hwest c)south east d)south west 15.A man facing northwest.he turns 90 degrees in the clockwise direction and then 135 degrees in the anti clockwise direction.which direction is he facing now? a)east b)west c)north d)south 16.A rat runs 20' towards east and turns to right,runs 10' and turns to right,runs 9' and agian turns to left . runs 5' and then turns to left,runs 12' and finally turns to left and runs 6'.now,which direction is the rat facing? a)east b)west c)north D)south 17.A walks 10metres infront. and 10 metres to the right. then everytime turning to his left walks 5,15 and 15 mtrs respectively. how far is he now from his starting point? a)5 b)27 c)7 d)2 18.Laxman went 15kms to the west from my house, then turned left and walked 20 kms.He then turned east and walked 25kms and finally turning left covered 20kms. how far was he from his house? a)5 b)10 c)40 d)80 19.Iam facing east.I turn 100 deg in the clockwise direction and the 145 deg in the anti clockwise direction.Which direction am i facing now? a)east b)northe ast c)north d)south west 20.Deepa moved a distance of 75 mtrs towards the north. she then turned to the left and walking for about 25 mtrs , turned left again and walked 80 mts. finally , she turned to the right at an angle of 45 deg. In which direction was she moving finally> a)north east b)north west c)south d)south west Questions 21-24 If you start running from a point towards north and after covering 4kms you turn to your left and run 5km, and then again turn to your left and run 9km and then turn to left again and run another 6km and before finishing you take another left and run 1km then answer questions 21 - 24 21.How many km are you from the place you started? a)1 b)2 c)3 d)4 22.In which direction will you be running while finishing? a)east b)west c)north d)south 23.after taking the second turn, in which diretion will you be running? a)east b)west c)north d)south 24.From the finishing point if you have to reach the point from where you started, in which direction will u have to run? a) east b)west c0north d)south Directions(25-27): Study the given information and answer the following questions I) there are 6 check posts A,B,C,D,E AND F II)check post F is 15 kms to the north of D which is 25 kms to the north east of B III) check post A is 5kms west of E and 15 kms to the south west of C IV)B,A and E are in straghtline V)the check posts B and E are 30kms apart from each other 25. which check post is the farthest to the south west of D? a) A b)B c)C d)D 26.which port is the nearest and to the north east of E? a)A b)B c)C d)D 27.If a jeep moves from E to F via A,B and D, how much distance it will have to cover? a)130 b)189 c)289 d)797 Directions(28-32): Ram walks 2km towards north and urn to his right and walks 4km more. he then turns to his right and walks 4km and turns again to his right and walks another 4km.Here he meets renu coming from the opposite directions.They both stop here. 28.After taking the first turn, in which direction was Ram going? a)south b)north c)west d)east 29.If the starting point is marked A and finishing point is marked B,What will be the distance between these points? a) 10 b)8 c)6 d)2 30.From which direction was Ram coming? a)south b)north c)west d)east 31. After taking the second turn, in which direction was Ram walking> a) west b)north c)south east d)south 32. If ram is to again reach the point from where he started in which direction will he have to go from where he's standing now? a)east b)north c)south east d)north east 33.If A is to the south of B and C is to the east of B, in what direction is A with respect to C? a)northe east b)northwest c)south east d)south west 34.There are 4 towns P,Q, R and T.Q is to the south west of F,R is to the east of Q and south east of P,and T is to the north of R in line with QP.In which direction of P is T located? a)south east b)north c)north east d)east 35.If south east becomes north,north east becomes west and so on, what will west become? a)northe east b)north west c)south east d)south west 36. One morning after sunrise,Gopal was standing facing a pole.The shadow of the pole fell exactly to his right.What direction was he facing? a)south b)east c)west d)data inadequate 37.One morning after sunrise reeta and kavitha were talking to each otherface to face at Tilak square.If kavita's shadow was exactly to the right of reeta, which direction kavitha was facing? a)north b)south c)east d)data inadequate 38.One morning after sunrise,vikram and shailesh were standing in a lawn with their backs towards each other.vikrams shadow fell exactly towards left hand side.Which direction was shailesh facing? a)easr b)west c)north d)south 39.One evening before sunset two friends sumit and mohit were talking to eash other face to face.if mohits shadow was exactly to his right side,which direction was sumit facing? a)north b)south c)west d)none of these 40.A clock is so placed that at 12 noon its minute hand points towards north east.In which direction does its hour hand point at 1.30 pm? a)north b)south c)east d)west
Directions(logical reasoning)
series (logical resonimng)
1.D I L Q T Y B G ?
A)H B)I C)0 D)P E)J
2.X U S P N K I ?
A)J B)K C)M D)F E)O
3.D F I M R ?
A)S B)U C)U D)X E)Z
4.B D G I L N ?
A)O B)Q C)S D)U E)Q
5.D I L Q T Y B G ?
A)H B)J C)R C)J E)Q
6.J E Z U P J ?
A)K B)M C)O D)P E)K
7.HV GT FR EP EN ?
A)KL B)LM C)MN D)NO E)CL
8.T U N K H ?
A)F B)L C)S D)E E)R
9.AD EH IL __ QT UX
A)AY B)VB C)CW D)DX E)MP
10. A D C F
C F E H
E H G K
O R ? ?
A)LK B)MN C)ST D)QT E)XY
11.ABC abc DEF __?
A)ghi B)GHI C)ABC D)def
12.mm pp s ?
A)Vv B)vv C)ST D)pp
13.9 15 23 33 ?
A)44 B)36 C)38 D)45
14.12 8 14 6 16 ?
A)18 B)32 C)5 D)4
15.9 6 16 10 30 18 ? 34
A)36 B)60 C)58 D)90
16.68 81 96 ? 132
A)105 B)110 C)130 D)113
17.2 5 9 ? 20 27
A)48 B)12 C)14 D)24
18.30 23 17 12 ? 5
A)6 B)7 C)8 D)9
19.10 18 24 ?? 130 254 258
A)32 B)60 C)68 D)66
20.18 10 6 4 3 ?
A)8 B)4 C)3.5 D)2.5
21.a D g J m P
A)sp B)sP C)sV D)Sv
22.aa bbb cccc ?
A)ddjjj B)dddjj C)ddddd D)DDDDD
23.accce ACCCE ?
A)GJJJK fjjjk B)GIIIK giiik C)GIIIIK ghhhk D)GIIIK GiiiK
24.AI BJ CK ?
A)LM B)GH C)AR D)SE E)DL
25.AM BN EI FJ CO GK DP __
A)PQ B)QR C)QT D)HL E)HO
26.A E J
P T ?
A)U B)V C)R D)W E)X
27.AC EG BD FH IK __
A)LM B)OP C)IJ D)JL E)JK
28.A C F J O ?
A)P B)Q c)U D)V E)L
29.A D E H I L ?
A)MP B)MN C)MO D)MQ E)NM
30.CD HI MN ??
A)QS B)RS C)OP D)PQ E)ST
31.I M Q U X B ?
A)C B)D C)F D)G E)E
32.Z X V T R P ?
A)Q B)R C)S D)M E)N
33.4 9 20 43 90 ?
A)180 B)182 C)179 D)185
34.5 9 16 29 54 103 ?
A)102 B)94 C)103 D)200
35.5 8 12 17 23 ? 38
A)26 B)28 C)30 D)29
36.4 5 7 ? 19
A)8 B)9 C)10 D)11
37.4 10 22 46 ?
A)56 B)66 C)76 D)94
38.2 3 4 25 4 9 16 ---
A)625 B)689 C)79 D)272
39.A H L E
E N T ?
A)U B)V C)W D)O
40.B E I N T ?
A)R B)S C)U D)A E)V
A)H B)I C)0 D)P E)J
2.X U S P N K I ?
A)J B)K C)M D)F E)O
3.D F I M R ?
A)S B)U C)U D)X E)Z
4.B D G I L N ?
A)O B)Q C)S D)U E)Q
5.D I L Q T Y B G ?
A)H B)J C)R C)J E)Q
6.J E Z U P J ?
A)K B)M C)O D)P E)K
7.HV GT FR EP EN ?
A)KL B)LM C)MN D)NO E)CL
8.T U N K H ?
A)F B)L C)S D)E E)R
9.AD EH IL __ QT UX
A)AY B)VB C)CW D)DX E)MP
10. A D C F
C F E H
E H G K
O R ? ?
A)LK B)MN C)ST D)QT E)XY
11.ABC abc DEF __?
A)ghi B)GHI C)ABC D)def
12.mm pp s ?
A)Vv B)vv C)ST D)pp
13.9 15 23 33 ?
A)44 B)36 C)38 D)45
14.12 8 14 6 16 ?
A)18 B)32 C)5 D)4
15.9 6 16 10 30 18 ? 34
A)36 B)60 C)58 D)90
16.68 81 96 ? 132
A)105 B)110 C)130 D)113
17.2 5 9 ? 20 27
A)48 B)12 C)14 D)24
18.30 23 17 12 ? 5
A)6 B)7 C)8 D)9
19.10 18 24 ?? 130 254 258
A)32 B)60 C)68 D)66
20.18 10 6 4 3 ?
A)8 B)4 C)3.5 D)2.5
21.a D g J m P
A)sp B)sP C)sV D)Sv
22.aa bbb cccc ?
A)ddjjj B)dddjj C)ddddd D)DDDDD
23.accce ACCCE ?
A)GJJJK fjjjk B)GIIIK giiik C)GIIIIK ghhhk D)GIIIK GiiiK
24.AI BJ CK ?
A)LM B)GH C)AR D)SE E)DL
25.AM BN EI FJ CO GK DP __
A)PQ B)QR C)QT D)HL E)HO
26.A E J
P T ?
A)U B)V C)R D)W E)X
27.AC EG BD FH IK __
A)LM B)OP C)IJ D)JL E)JK
28.A C F J O ?
A)P B)Q c)U D)V E)L
29.A D E H I L ?
A)MP B)MN C)MO D)MQ E)NM
30.CD HI MN ??
A)QS B)RS C)OP D)PQ E)ST
31.I M Q U X B ?
A)C B)D C)F D)G E)E
32.Z X V T R P ?
A)Q B)R C)S D)M E)N
33.4 9 20 43 90 ?
A)180 B)182 C)179 D)185
34.5 9 16 29 54 103 ?
A)102 B)94 C)103 D)200
35.5 8 12 17 23 ? 38
A)26 B)28 C)30 D)29
36.4 5 7 ? 19
A)8 B)9 C)10 D)11
37.4 10 22 46 ?
A)56 B)66 C)76 D)94
38.2 3 4 25 4 9 16 ---
A)625 B)689 C)79 D)272
39.A H L E
E N T ?
A)U B)V C)W D)O
40.B E I N T ?
A)R B)S C)U D)A E)V
Brain puzzles
1. There is one word in the English language that is always pronounced incorrectly. What is it?
2. A man gave one son 10 cents and another son was given 15 cents. What time is it?
3. A boat has a ladder that has six rungs, each rung is one foot apart. The bottom rung is one foot from the water. The tide rises at 12 inches every 15 minutes. High tide peaks in one hour. When the tide is at it's highest, how many rungs are under water?
4. There is a house with four walls. Each wall faces south. There is a window in each wall. A bear walks by one of the windows. What color is the bear?
5. Is half of two plus two equal to two or three?
6. There is a room. The shutters are blowing in. There is broken glass on the floor. There is water on the floor. You find Sloppy dead on the floor. Who is Sloppy? How did Sloppy die?
7. How much dirt would be in a hole 6 feet deep and 6 feet wide that has been dug with a square edged shovel?
8. If I were in Hawaii and dropped a bowling ball in a bucket of water which is 45 degrees F, and dropped another ball of the same weight, mass,and size in a bucket at 30 degrees F, both of them at the same time, which ball would hit the bottom of the bucket first? Same question, but the location is in Canada?
9. What is the significance of the following: The year is 1978, thirty-four minutes past noon on May 6th.
10. What can go up a chimney down, but can't go down a chimney up? (hint... chim chimminy)
11. If a farmer has 5 haystacks in one field and 4 haystacks in the other field, how many haystacks would he have if he combined them all in the center field?
12. What is it that goes up and goes down but does not move?
"Answers To Brain Teasers"
1. The word "incorrectly." {Almost cracked your brain, didn't you?}
2. 1:45. The man gave away a total of 25 cents. He divided it between two people. Therefore, he gave a quarter to two.
3. None, the boat rises with the tide. Duh.
4. White. If all the walls face south, the house is at the North pole, and the bear, therefore, is a polar bear.
5. Three. Well, it seems that it could almost be either, but if you follow the mathematical orders of operation, division is performed before addition. So... half of two is one. Then add two, and the answer is three.
6. Sloppy is a (gold)fish. The wind blew the shutters in, which knocked his goldfish-bowl off the table, and it broke, killing him. {Poor Sloppy.}
7. None. No matter how big a hole is, it's still a hole: the absence of dirt. (And those of you who said 36 cubic feet are wrong for another reason, too. You would have needed the length measurement too. So you don't even know how much air is in the hole.)
8. Both questions, same answer: the ball in the bucket of 45 degree F water hits the bottom of the bucket last. Did you think that the water in the 30 degree F bucket is frozen? Think again. The question said nothing about that bucket having anything in it. Therefore, there is no water (or ice) to slow the ball down...
9. The time and month/date/year American style calendar are 12:34, 5/6/78.
10. An umbrella.
11. One. If he combines all of his haystacks, they all become one big stack.
12. The temperature.
2. A man gave one son 10 cents and another son was given 15 cents. What time is it?
3. A boat has a ladder that has six rungs, each rung is one foot apart. The bottom rung is one foot from the water. The tide rises at 12 inches every 15 minutes. High tide peaks in one hour. When the tide is at it's highest, how many rungs are under water?
4. There is a house with four walls. Each wall faces south. There is a window in each wall. A bear walks by one of the windows. What color is the bear?
5. Is half of two plus two equal to two or three?
6. There is a room. The shutters are blowing in. There is broken glass on the floor. There is water on the floor. You find Sloppy dead on the floor. Who is Sloppy? How did Sloppy die?
7. How much dirt would be in a hole 6 feet deep and 6 feet wide that has been dug with a square edged shovel?
8. If I were in Hawaii and dropped a bowling ball in a bucket of water which is 45 degrees F, and dropped another ball of the same weight, mass,and size in a bucket at 30 degrees F, both of them at the same time, which ball would hit the bottom of the bucket first? Same question, but the location is in Canada?
9. What is the significance of the following: The year is 1978, thirty-four minutes past noon on May 6th.
10. What can go up a chimney down, but can't go down a chimney up? (hint... chim chimminy)
11. If a farmer has 5 haystacks in one field and 4 haystacks in the other field, how many haystacks would he have if he combined them all in the center field?
12. What is it that goes up and goes down but does not move?
"Answers To Brain Teasers"
1. The word "incorrectly." {Almost cracked your brain, didn't you?}
2. 1:45. The man gave away a total of 25 cents. He divided it between two people. Therefore, he gave a quarter to two.
3. None, the boat rises with the tide. Duh.
4. White. If all the walls face south, the house is at the North pole, and the bear, therefore, is a polar bear.
5. Three. Well, it seems that it could almost be either, but if you follow the mathematical orders of operation, division is performed before addition. So... half of two is one. Then add two, and the answer is three.
6. Sloppy is a (gold)fish. The wind blew the shutters in, which knocked his goldfish-bowl off the table, and it broke, killing him. {Poor Sloppy.}
7. None. No matter how big a hole is, it's still a hole: the absence of dirt. (And those of you who said 36 cubic feet are wrong for another reason, too. You would have needed the length measurement too. So you don't even know how much air is in the hole.)
8. Both questions, same answer: the ball in the bucket of 45 degree F water hits the bottom of the bucket last. Did you think that the water in the 30 degree F bucket is frozen? Think again. The question said nothing about that bucket having anything in it. Therefore, there is no water (or ice) to slow the ball down...
9. The time and month/date/year American style calendar are 12:34, 5/6/78.
10. An umbrella.
11. One. If he combines all of his haystacks, they all become one big stack.
12. The temperature.
Literal thinking puzzles
1. In the middle of the ocean is a yacht. Several corpses are
floating in the water nearby.
2. Bob and Carol and Ted and Alice all live in the same house. Bob
and Carol go out to a movie, and when they return, Alice is lying dead
on the floor in a puddle of water and glass. It is obvious that Ted
killed her but Ted is not prosecuted or severely punished.
3. A woman comes home with a bag of groceries, gets the mail, and
walks into the house. On the way to the kitchen, she goes through the
living room and looks at her husband, who had blown his brains out. She
then continues to the kitchen, puts away the groceries, and makes
dinner.
4. A body is discovered in a park in Chicago in the middle of summer.
It has a fractured skull and many other broken bones, but the cause of
death was hypothermia.
5. A man lives on the twelfth floor of an apartment building. Every
morning he wakes up, gets dressed, eats, goes to the elevator, takes it
down to the lobby, and leaves the building for work. In the evening, he
goes through the lobby to the elevator, and, if there is someone else in
the elevator (or if it was raining that day) he goes back to his floor
directly. However, if there is nobody else in the elevator and it
hasn't rained, he goes to the 10th floor and walks up two flights of
stairs to his room.
6. A woman has incontrovertible proof in court that her husband was
murdered by her sister. The judge declares, "This is the strangest case
I've ever seen. Though it's a cut-and-dried case, this murderess cannot
be punished."
7. A man walks into a bar and asks for a drink. The bartender pulls
out a gun and points it at him. The man says, "Thank you," and walks
out.
8. A man is in a returning from Switzerland by train. If he had been
in a non-smoking car he would have died.
9. Music stops and a woman dies.
10. A man goes into a restaurant, orders abalone, eats one bite, and
kills himself.
11. A man is found hanging in a locked room with no furniture and a
puddle of water under his feet.
12. A man is dead in a puddle of blood and water on the floor of a
locked room.
13. A man is lying, dead, face down in the desert wearing a backpack.
14. A man is lying face down, dead, in the desert, with a match near
his outstretched hand. He is nude.
15. A man is driving his car. He turns on the radio, listens for
five minutes, turns around, goes home, and shoots his wife.
16. A man driving his car turns on the radio. He then pulls over to
the side of the road and shoots himself.
17. A man is dead in a room with a small pile of pieces of wood and
sawdust in one corner.
18. A pile of sawdust, no net, a man dies.
19. A rope breaks. A bell rings. A man dies.
20. A man sitting on a park bench reads a newspaper article headlined
"Death at Sea" and says, "A murder has been committed!"
21. A man is riding a subway. He meets a one-armed man, who pulls
out a gun and shoots him.
22. Two women are talking. One goes into the bathroom, comes out
five minutes later, and kills the other.
23. A man is sitting in bed. He makes a phone call, says nothing,
then goes to sleep.
24. A man kills his wife, then goes inside his house and kills
himself.
25. Abel walks out of the ocean. Cain asks him who he is, and Abel
answers. Cain kills Abel.
26. Two men, one big and burly and the other short and thin, enter a
bar. They both order identical drinks. The big one gulps his down and
leaves; the other sips his slowly, then dies.
27. Joe leaves his house, wearing a mask and carrying an empty sack.
An hour later he returns. The sack is now full. He goes into a room
and turns out the lights.
28. A man takes a two week cruise to Mexico from the U.S. Shortly
after he gets back, he takes a three day cruise which doesn't stop at
any other ports. He stays in his cabin all the time on both cruises.
As a result, he makes $250,000.
29. Hans and Fritz are German spies during World War II. They try to
enter America, posing as returning tourists. Hans is immediately
arrested.
30. Tim and Greg were talking. Tim said "The terror of flight".
Greg said "The gloom of the grave". Greg was arrested.
31. A man is found dead in his parked car. Tire tracks lead up to
the car and away.
32. A man dies in his own home.
33. A woman in Paris in 1895 is waiting for her husband to come home.
When he arrives, the house has burned to the ground and she's dead.
34. A man gets onto an elevator. When the elevator stops, he knows
his wife is dead.
35. A policeman follows a burglar into a bar. When he enters the bar
he finds a set of identical twins, dressed the same, with the loot
between them. After several minutes he arrests one of the twins.
36. She lost her job when she invited them to dinner.
37. He couldn't find a chair, so he died.
38. A car without a driver moves; a man dies.
39. As I drive to work on my motorcycle, there is one corner which I
go around at a certain speed whether it's rainy or sunny. If it's
cloudy but not raining, however, I usually go faster.
40. A woman throws something out a window and dies.
41. An avid birdwatcher sees an unexpected bird. Soon he's dead.
42. A man shoots himself, and dies.
43. A man walks into a room, shoots, and kills himself.
44. Adults are holding children, waiting their turn. The children are
handed (one at a time, usually) to a man, who holds them while a woman
shoots them. If the child is crying, the man tries to stop the crying
before the child is shot.
45. A man marries twenty women in his village but isn't charged with
polygamy.
46. There are two people dead in a cabin in the woods.
47. A man pushes a car up to a hotel and realizes he's bankrupt.
48. She said "I love you," and died.
49. As a man jumps out of a window, he hears the telephone ring. He
tries to stop himself, but can't.
50. A man is found dead on the floor in the living room.
51. A man is sitting in a train compartment. He sees a
three-fingered hand through the compartment window, in the hallway of
the train. He opens the compartment door and shoots the person with the
three-fingered hand, but he goes free.
52. There is a dead man lying in the desert next to a rock.
53. A man is found dead in the arctic with a pack on his back.
54. A man is lying dead in a room. There is a large pile of gold,
jewels, and so on on the floor, a chandelier attached to the ceiling,
and a large window through which rays are coming.
55. A man goes home, turns out the light, and goes to bed. He wakes
up the next morning, reads the newspaper, and kills himself.
56. A raft carrying passengers took a trip down the Amazon. The raft
capsized, and no survivors were found.
57. A man is lying dead in a pool of blood and glass.
58. A woman walks up to a door and knocks. Another woman answers the
door. The woman outside kills the woman inside.
59. There is blood on the ceiling of my bedroom.
60. A woman goes into a convenience store to buy a can of Coke. She
pays for it with a $20 bill and receives $20.05 in change. No mistake
was made.
61. A newspaper reported the following: "Yesterday, Jacques Dubois
finished first in the walking race held in Paris. He walked 62,137
miles." The article was not in error.
62. Two children born in the same hospital, in the same hour, day,
and year, have the same mother and father, but are not twins.
63. A couple will build a square house. In each wall they'll have a
window, and each window will face north.
64. There are a pipe, a carrot and a pile of pebbles together in the
middle of a field.
65. The telephone rang in the middle of the night and the woman woke
up. When she answered it the caller hung up. The caller felt better.
66. The seals came up to do their show but immediately dove back into
the water.
67. A man is found dead in an alley lying in a pool of red with two
sticks crossed near his head.
68. A man called to a waiter in a restaurant, "There's a fly in my
tea!" "I will bring you a fresh cup of tea," said the waiter. After a
few moments, the man called out, "This is the same cup of tea!" How did
he know?
69. A man is found dead outside a large marble building with three
holes in him.
70. An ordinary American citizen, with a clean police record but no
passport, managed to visit over thirty foreign countries. He was
welcomed in each country, and left each one of his own accord. He did
this in one day.
71. Three heavy people try to crowd under one umbrella, and nobody
gets wet.
72. A black man dressed all in black, wearing a black mask, stands at
a crossroads in a totally black-painted town. All of the streetlights
in town are broken. There is no moon. A black-painted car without
headlights drives straight toward him, but turns in time and doesn't hit
him.
72. The wind stopped blowing and the man died.
74. An Arab sheikh tells his two sons that are to race their camels
to a distant city to see who will inherit his fortune. The one whose
camel arrives last will win. The brothers, after wandering aimlessly
for days, ask a wise man for advise. After hearing the advice they jump
on the camels and race as fast as they can to their destination.
75. A man puts a quarter down, and leaves.
76. A man lies dead next to a feather.
77. A man carrying an attache case full of $20 bills falls on the way
to the bank and is never seen again.
78. The pope is giving a speech. A man in the audience shoots the
mayor who is behind the pope.
79. A man travels to twenty countries and stays in each country for a
month. During this time he never sees the light of day.
80. King Henry VIII is lying at the bottom of the stairs with a gash
across his face.
81. Joe wants to go home, but he can't go home, because the man
in the mask is waiting for him.
82. A man lies dead in a room with fifty-three bicycles in front of
him.
83. Two people are playing cards. One looks around and realizes he's
going to die.
84. A woman opens an envelope and dyes.
85. A man is holding a box. Though he cannot see into it, he knows
what's inside.
86. A man was walking along some railroad tracks when he noticed that
a train was coming. He walked toward the train before stepping aside.
(RM)
87. A man was going about his daily occupation when he noticed that
his shirt was torn. 15 minutes later, he was dead.
88. A train pulls into a station, but none of the waiting passengers
move.
89. In his own home a man watches as a woman dies, yet does nothing
to save her.
90. There is a dead man, a beetle on top of a book, and a pile of
bricks.
91. A dish moves, a scientist makes a discovery.
92. A man is alone on an island with no food and no water, yet he
does not fear for his life.
93. A husband coming home hears his wife call "Bill, don't kill me!".
He walks in and finds his wife dead. Inside are a postman, a doctor,
and a lawyer. The husband immediately knows the postman killed his
wife.
94. Bruce wins the race, but he gets no trophy.
95. A man rolls over a glass bottle. He travels the last 100 miles
of the Sahara 5000 roadrace with a flat tire.
96. Man pleads with boss not to fly to Chicago. The boss goes and
when he returns, he fires the man.
~97. On an archeological dig, the frozen remains of a man and woman
are found. Immediately, the archeologists realize that the remains are
those of Adam and Eve.
98. A horse jumps over a tower and lands on a man, who disappears.
99. It's the year 860 A.D., at Camelot. Two priests are sitting in
the castle's chapel. The queen attacks the king. The two priests rise,shake hands, and leave the room.
100. Two people are talking long distance on the phone; one is in an
East-Coast state, the other is in a West-Coast state. The first asks
the other "What time is it?", hears the answer, and says, "That's funny. It's the same time here!"
101. A boy and his father are injured in a car accident. Both are
taken to a hospital. The father dies at arrival, but the boy lives
and is taken to surgery. A grey-haired, bespectacled surgeon looks at
the boy and says, "I cannot operate on this boy -- he's my son."
floating in the water nearby.
2. Bob and Carol and Ted and Alice all live in the same house. Bob
and Carol go out to a movie, and when they return, Alice is lying dead
on the floor in a puddle of water and glass. It is obvious that Ted
killed her but Ted is not prosecuted or severely punished.
3. A woman comes home with a bag of groceries, gets the mail, and
walks into the house. On the way to the kitchen, she goes through the
living room and looks at her husband, who had blown his brains out. She
then continues to the kitchen, puts away the groceries, and makes
dinner.
4. A body is discovered in a park in Chicago in the middle of summer.
It has a fractured skull and many other broken bones, but the cause of
death was hypothermia.
5. A man lives on the twelfth floor of an apartment building. Every
morning he wakes up, gets dressed, eats, goes to the elevator, takes it
down to the lobby, and leaves the building for work. In the evening, he
goes through the lobby to the elevator, and, if there is someone else in
the elevator (or if it was raining that day) he goes back to his floor
directly. However, if there is nobody else in the elevator and it
hasn't rained, he goes to the 10th floor and walks up two flights of
stairs to his room.
6. A woman has incontrovertible proof in court that her husband was
murdered by her sister. The judge declares, "This is the strangest case
I've ever seen. Though it's a cut-and-dried case, this murderess cannot
be punished."
7. A man walks into a bar and asks for a drink. The bartender pulls
out a gun and points it at him. The man says, "Thank you," and walks
out.
8. A man is in a returning from Switzerland by train. If he had been
in a non-smoking car he would have died.
9. Music stops and a woman dies.
10. A man goes into a restaurant, orders abalone, eats one bite, and
kills himself.
11. A man is found hanging in a locked room with no furniture and a
puddle of water under his feet.
12. A man is dead in a puddle of blood and water on the floor of a
locked room.
13. A man is lying, dead, face down in the desert wearing a backpack.
14. A man is lying face down, dead, in the desert, with a match near
his outstretched hand. He is nude.
15. A man is driving his car. He turns on the radio, listens for
five minutes, turns around, goes home, and shoots his wife.
16. A man driving his car turns on the radio. He then pulls over to
the side of the road and shoots himself.
17. A man is dead in a room with a small pile of pieces of wood and
sawdust in one corner.
18. A pile of sawdust, no net, a man dies.
19. A rope breaks. A bell rings. A man dies.
20. A man sitting on a park bench reads a newspaper article headlined
"Death at Sea" and says, "A murder has been committed!"
21. A man is riding a subway. He meets a one-armed man, who pulls
out a gun and shoots him.
22. Two women are talking. One goes into the bathroom, comes out
five minutes later, and kills the other.
23. A man is sitting in bed. He makes a phone call, says nothing,
then goes to sleep.
24. A man kills his wife, then goes inside his house and kills
himself.
25. Abel walks out of the ocean. Cain asks him who he is, and Abel
answers. Cain kills Abel.
26. Two men, one big and burly and the other short and thin, enter a
bar. They both order identical drinks. The big one gulps his down and
leaves; the other sips his slowly, then dies.
27. Joe leaves his house, wearing a mask and carrying an empty sack.
An hour later he returns. The sack is now full. He goes into a room
and turns out the lights.
28. A man takes a two week cruise to Mexico from the U.S. Shortly
after he gets back, he takes a three day cruise which doesn't stop at
any other ports. He stays in his cabin all the time on both cruises.
As a result, he makes $250,000.
29. Hans and Fritz are German spies during World War II. They try to
enter America, posing as returning tourists. Hans is immediately
arrested.
30. Tim and Greg were talking. Tim said "The terror of flight".
Greg said "The gloom of the grave". Greg was arrested.
31. A man is found dead in his parked car. Tire tracks lead up to
the car and away.
32. A man dies in his own home.
33. A woman in Paris in 1895 is waiting for her husband to come home.
When he arrives, the house has burned to the ground and she's dead.
34. A man gets onto an elevator. When the elevator stops, he knows
his wife is dead.
35. A policeman follows a burglar into a bar. When he enters the bar
he finds a set of identical twins, dressed the same, with the loot
between them. After several minutes he arrests one of the twins.
36. She lost her job when she invited them to dinner.
37. He couldn't find a chair, so he died.
38. A car without a driver moves; a man dies.
39. As I drive to work on my motorcycle, there is one corner which I
go around at a certain speed whether it's rainy or sunny. If it's
cloudy but not raining, however, I usually go faster.
40. A woman throws something out a window and dies.
41. An avid birdwatcher sees an unexpected bird. Soon he's dead.
42. A man shoots himself, and dies.
43. A man walks into a room, shoots, and kills himself.
44. Adults are holding children, waiting their turn. The children are
handed (one at a time, usually) to a man, who holds them while a woman
shoots them. If the child is crying, the man tries to stop the crying
before the child is shot.
45. A man marries twenty women in his village but isn't charged with
polygamy.
46. There are two people dead in a cabin in the woods.
47. A man pushes a car up to a hotel and realizes he's bankrupt.
48. She said "I love you," and died.
49. As a man jumps out of a window, he hears the telephone ring. He
tries to stop himself, but can't.
50. A man is found dead on the floor in the living room.
51. A man is sitting in a train compartment. He sees a
three-fingered hand through the compartment window, in the hallway of
the train. He opens the compartment door and shoots the person with the
three-fingered hand, but he goes free.
52. There is a dead man lying in the desert next to a rock.
53. A man is found dead in the arctic with a pack on his back.
54. A man is lying dead in a room. There is a large pile of gold,
jewels, and so on on the floor, a chandelier attached to the ceiling,
and a large window through which rays are coming.
55. A man goes home, turns out the light, and goes to bed. He wakes
up the next morning, reads the newspaper, and kills himself.
56. A raft carrying passengers took a trip down the Amazon. The raft
capsized, and no survivors were found.
57. A man is lying dead in a pool of blood and glass.
58. A woman walks up to a door and knocks. Another woman answers the
door. The woman outside kills the woman inside.
59. There is blood on the ceiling of my bedroom.
60. A woman goes into a convenience store to buy a can of Coke. She
pays for it with a $20 bill and receives $20.05 in change. No mistake
was made.
61. A newspaper reported the following: "Yesterday, Jacques Dubois
finished first in the walking race held in Paris. He walked 62,137
miles." The article was not in error.
62. Two children born in the same hospital, in the same hour, day,
and year, have the same mother and father, but are not twins.
63. A couple will build a square house. In each wall they'll have a
window, and each window will face north.
64. There are a pipe, a carrot and a pile of pebbles together in the
middle of a field.
65. The telephone rang in the middle of the night and the woman woke
up. When she answered it the caller hung up. The caller felt better.
66. The seals came up to do their show but immediately dove back into
the water.
67. A man is found dead in an alley lying in a pool of red with two
sticks crossed near his head.
68. A man called to a waiter in a restaurant, "There's a fly in my
tea!" "I will bring you a fresh cup of tea," said the waiter. After a
few moments, the man called out, "This is the same cup of tea!" How did
he know?
69. A man is found dead outside a large marble building with three
holes in him.
70. An ordinary American citizen, with a clean police record but no
passport, managed to visit over thirty foreign countries. He was
welcomed in each country, and left each one of his own accord. He did
this in one day.
71. Three heavy people try to crowd under one umbrella, and nobody
gets wet.
72. A black man dressed all in black, wearing a black mask, stands at
a crossroads in a totally black-painted town. All of the streetlights
in town are broken. There is no moon. A black-painted car without
headlights drives straight toward him, but turns in time and doesn't hit
him.
72. The wind stopped blowing and the man died.
74. An Arab sheikh tells his two sons that are to race their camels
to a distant city to see who will inherit his fortune. The one whose
camel arrives last will win. The brothers, after wandering aimlessly
for days, ask a wise man for advise. After hearing the advice they jump
on the camels and race as fast as they can to their destination.
75. A man puts a quarter down, and leaves.
76. A man lies dead next to a feather.
77. A man carrying an attache case full of $20 bills falls on the way
to the bank and is never seen again.
78. The pope is giving a speech. A man in the audience shoots the
mayor who is behind the pope.
79. A man travels to twenty countries and stays in each country for a
month. During this time he never sees the light of day.
80. King Henry VIII is lying at the bottom of the stairs with a gash
across his face.
81. Joe wants to go home, but he can't go home, because the man
in the mask is waiting for him.
82. A man lies dead in a room with fifty-three bicycles in front of
him.
83. Two people are playing cards. One looks around and realizes he's
going to die.
84. A woman opens an envelope and dyes.
85. A man is holding a box. Though he cannot see into it, he knows
what's inside.
86. A man was walking along some railroad tracks when he noticed that
a train was coming. He walked toward the train before stepping aside.
(RM)
87. A man was going about his daily occupation when he noticed that
his shirt was torn. 15 minutes later, he was dead.
88. A train pulls into a station, but none of the waiting passengers
move.
89. In his own home a man watches as a woman dies, yet does nothing
to save her.
90. There is a dead man, a beetle on top of a book, and a pile of
bricks.
91. A dish moves, a scientist makes a discovery.
92. A man is alone on an island with no food and no water, yet he
does not fear for his life.
93. A husband coming home hears his wife call "Bill, don't kill me!".
He walks in and finds his wife dead. Inside are a postman, a doctor,
and a lawyer. The husband immediately knows the postman killed his
wife.
94. Bruce wins the race, but he gets no trophy.
95. A man rolls over a glass bottle. He travels the last 100 miles
of the Sahara 5000 roadrace with a flat tire.
96. Man pleads with boss not to fly to Chicago. The boss goes and
when he returns, he fires the man.
~97. On an archeological dig, the frozen remains of a man and woman
are found. Immediately, the archeologists realize that the remains are
those of Adam and Eve.
98. A horse jumps over a tower and lands on a man, who disappears.
99. It's the year 860 A.D., at Camelot. Two priests are sitting in
the castle's chapel. The queen attacks the king. The two priests rise,shake hands, and leave the room.
100. Two people are talking long distance on the phone; one is in an
East-Coast state, the other is in a West-Coast state. The first asks
the other "What time is it?", hears the answer, and says, "That's funny. It's the same time here!"
101. A boy and his father are injured in a car accident. Both are
taken to a hospital. The father dies at arrival, but the boy lives
and is taken to surgery. A grey-haired, bespectacled surgeon looks at
the boy and says, "I cannot operate on this boy -- he's my son."
Interview questions & Answers on EJB
Posted by
kanth
on Friday, January 22, 2010
Labels:
Interview Questions
/
Comments: (0)
1. How EJB Invocation happens? - Retrieve Home Object reference from Naming Service via JNDI. Return Home Object reference to the client. Create me a new EJB Object through Home Object interface. Create EJB Object from the Ejb Object. Return EJB Object reference to the client. Invoke business method using EJB Object reference. Delegate request to Bean (Enterprise Bean).
2. Is it possible to share an HttpSession between a JSP and EJB? What happens when I change a value in the HttpSession from inside an EJB? - You can pass the HttpSession as parameter to an EJB method, only if all objects in session are serializable.This has to be consider as passed-by-value, that means that it’s read-only in the EJB. If anything is altered from inside the EJB, it won’t be reflected back to the HttpSession of the Servlet Container.The pass-by-reference can be used between EJBs Remote Interfaces, as they are remote references. While it is possible to pass an HttpSession as a parameter to an EJB object, it is considered to be bad practice in terms of object-oriented design. This is because you are creating an unnecessary coupling between back-end objects (EJBs) and front-end objects (HttpSession). Create a higher-level of abstraction for your EJBs API. Rather than passing the whole, fat, HttpSession (which carries with it a bunch of http semantics), create a class that acts as a value object (or structure) that holds all the data you need to pass back and forth between front-end/back-end. Consider the case where your EJB needs to support a non HTTP-based client. This higher level of abstraction will be flexible enough to support it.
3. The EJB container implements the EJBHome and EJBObject classes. For every request from a unique client, does the container create a separate instance of the generated EJBHome and EJBObject classes? - The EJB container maintains an instance pool. The container uses these instances for the EJB Home reference irrespective of the client request. while refering the EJB Object classes the container creates a separate instance for each client request. The instance pool maintenance is up to the implementation of the container. If the container provides one, it is available otherwise it is not mandatory for the provider to implement it. Having said that, yes most of the container providers implement the pooling functionality to increase the performance of theapplication server. The way it is implemented is, again, up to the implementer.
4. Can the primary key in the entity bean be a Java primitive type such as int? - The primary key can’t be a primitive type. Use the primitive wrapper classes, instead. For example, you can use java.lang.Integer as the primary key class, but not int (it has to be a class, not a primitive).
5. Can you control when passivation occurs? - The developer, according to the specification, cannot directly control when passivation occurs. Although for Stateful Session Beans, the container cannot passivate an instance that is inside a transaction. So using transactions can be a a strategy to control passivation. The ejbPassivate() method is called during passivation, so the developer has control over what to do during this exercise and can implement the require optimized logic. Some EJB containers, such as BEA WebLogic, provide the ability to tune the container to minimize passivation calls. Taken from the WebLogic 6.0 DTD -”The passivation-strategy can be either “default” or “transaction”. With the default setting the container will attempt to keep a working set of beans in the cache. With the “transaction” setting, the container will passivate the bean after every transaction (or method call for a non-transactional invocation).
6. What is the advantage of using Entity bean for database operations, over directly using JDBC API to do database operations? When would I use one over the other? - Entity Beans actually represents the data in a database. It is not that Entity Beans replaces JDBC API. There are two types of Entity Beans Container Managed and Bean Mananged. In Container Managed Entity Bean - Whenever the instance of the bean is created the container automatically retrieves the data from the DB/Persistance storage and assigns to the object variables in bean for user to manipulate or use them. For this the developer needs to map the fields in the database to the variables in deployment descriptor files (which varies for each vendor). In the Bean Managed Entity Bean - The developer has to specifically make connection, retrive values, assign them to the objects in the ejbLoad() which will be called by the container when it instatiates a bean object. Similarly in the ejbStore() the container saves the object values back the the persistance storage. ejbLoad and ejbStore are callback methods and can be only invoked by the container. Apart from this, when you use Entity beans you dont need to worry about database transaction handling, database connection pooling etc. which are taken care by the ejb container.
7. What is EJB QL? - EJB QL is a Query Language provided for navigation across anetwork of enterprise beans and dependent objects defined by means of container managed persistence. EJB QL is introduced in the EJB 2.0 specification. The EJB QL query language defines finder methods for entity beans with container managed persistenceand is portable across containers and persistence managers. EJB QL is used for queries of two types of finder methods: Finder methods that are defined in the home interface of an entity bean and which return entity objects. Select methods, which are not exposed to the client, but which are used by the Bean Provider to select persistent values that are maintained by the Persistence Manager or to select entity objects that are related to the entity bean on which the query is defined.
8. Brief description about local interfaces? - EEJB was originally designed around remote invocation using the Java Remote Method Invocation (RMI) mechanism, and later extended to support to standard CORBA transport for these calls using RMI/IIOP. This design allowed for maximum flexibility in developing applications without consideration for the deployment scenario, and was a strong feature in support of a goal of component reuse in J2EE. Many developers are using EJBs locally, that is, some or all of their EJB calls are between beans in a single container. With this feedback in mind, the EJB 2.0 expert group has created a local interface mechanism. The local interface may be defined for a bean during development, to allow streamlined calls to the bean if a caller is in the same container. This does not involve the overhead involved with RMI like marshalling etc. This facility will thus improve the performance of applications in which co-location is planned. Local interfaces also provide the foundation for container-managed relationships among entity beans with container-managed persistence.
9. What are the special design care that must be taken when you work with local interfaces? - It is important to understand that the calling semantics of local interfaces are different from those of remote interfaces. For example, remote interfaces pass parameters using call-by-value semantics, while local interfaces use call-by-reference. This means that in order to use local interfaces safely, application developers need to carefully consider potential deployment scenarios up front, then decide which interfaces can be local and which remote, and finally, develop the application code with these choices in mind. While EJB 2.0 local interfaces are extremely useful in some situations, the long-term costs of these choices, especially when changing requirements and component reuse are taken into account, need to be factored into the design decision.
10. What happens if remove( ) is never invoked on a session bean? - In case of a stateless session bean it may not matter if we call or not as in both cases nothing is done. The number of beans in cache is managed by the container. In case of stateful session bean, the bean may be kept in cache till either the session times out, in which case the bean is removed or when there is a requirement for memory in which case the data is cached and the bean is sent to free pool.
11. What is the difference between Message Driven Beans and Stateless Session beans? - In several ways, the dynamic creation and allocation of message-driven bean instances mimics the behavior of stateless session EJB instances, which exist only for the duration of a particular method call. However, message-driven beans are different from stateless session EJBs (and other types of EJBs) in several significant ways: Message-driven beans process multiple JMS messages asynchronously, rather than processing a serialized sequence of method calls. Message-driven beans have no home or remote interface, and therefore cannot be directly accessed by internal or external clients. Clients interact with message-driven beans only indirectly, by sending a message to a JMS Queue or Topic. Only the container directly interacts with a message-driven bean by creating bean instances and passing JMS messages to those instances as necessary. The Container maintains the entire lifecycle of a message-driven bean; instances cannot be created or removed as a result of client requests or other API calls.
12. How can I call one EJB from inside of another EJB? - EJBs can be clients of other EJBs. It just works. Use JNDI to locate the Home Interface of the other bean, then acquire an instance reference, and so forth.
13. What is an EJB Context? - EJBContext is an interface that is implemented by the container, and it is also a part of the bean-container contract. Entity beans use a subclass of EJBContext called EntityContext. Session beans use a subclass called SessionContext. These EJBContext objects provide the bean class with information about its container, the client using the bean and the bean itself. They also provide other functions. See the API docs and the spec for more details.
2. Is it possible to share an HttpSession between a JSP and EJB? What happens when I change a value in the HttpSession from inside an EJB? - You can pass the HttpSession as parameter to an EJB method, only if all objects in session are serializable.This has to be consider as passed-by-value, that means that it’s read-only in the EJB. If anything is altered from inside the EJB, it won’t be reflected back to the HttpSession of the Servlet Container.The pass-by-reference can be used between EJBs Remote Interfaces, as they are remote references. While it is possible to pass an HttpSession as a parameter to an EJB object, it is considered to be bad practice in terms of object-oriented design. This is because you are creating an unnecessary coupling between back-end objects (EJBs) and front-end objects (HttpSession). Create a higher-level of abstraction for your EJBs API. Rather than passing the whole, fat, HttpSession (which carries with it a bunch of http semantics), create a class that acts as a value object (or structure) that holds all the data you need to pass back and forth between front-end/back-end. Consider the case where your EJB needs to support a non HTTP-based client. This higher level of abstraction will be flexible enough to support it.
3. The EJB container implements the EJBHome and EJBObject classes. For every request from a unique client, does the container create a separate instance of the generated EJBHome and EJBObject classes? - The EJB container maintains an instance pool. The container uses these instances for the EJB Home reference irrespective of the client request. while refering the EJB Object classes the container creates a separate instance for each client request. The instance pool maintenance is up to the implementation of the container. If the container provides one, it is available otherwise it is not mandatory for the provider to implement it. Having said that, yes most of the container providers implement the pooling functionality to increase the performance of theapplication server. The way it is implemented is, again, up to the implementer.
4. Can the primary key in the entity bean be a Java primitive type such as int? - The primary key can’t be a primitive type. Use the primitive wrapper classes, instead. For example, you can use java.lang.Integer as the primary key class, but not int (it has to be a class, not a primitive).
5. Can you control when passivation occurs? - The developer, according to the specification, cannot directly control when passivation occurs. Although for Stateful Session Beans, the container cannot passivate an instance that is inside a transaction. So using transactions can be a a strategy to control passivation. The ejbPassivate() method is called during passivation, so the developer has control over what to do during this exercise and can implement the require optimized logic. Some EJB containers, such as BEA WebLogic, provide the ability to tune the container to minimize passivation calls. Taken from the WebLogic 6.0 DTD -”The passivation-strategy can be either “default” or “transaction”. With the default setting the container will attempt to keep a working set of beans in the cache. With the “transaction” setting, the container will passivate the bean after every transaction (or method call for a non-transactional invocation).
6. What is the advantage of using Entity bean for database operations, over directly using JDBC API to do database operations? When would I use one over the other? - Entity Beans actually represents the data in a database. It is not that Entity Beans replaces JDBC API. There are two types of Entity Beans Container Managed and Bean Mananged. In Container Managed Entity Bean - Whenever the instance of the bean is created the container automatically retrieves the data from the DB/Persistance storage and assigns to the object variables in bean for user to manipulate or use them. For this the developer needs to map the fields in the database to the variables in deployment descriptor files (which varies for each vendor). In the Bean Managed Entity Bean - The developer has to specifically make connection, retrive values, assign them to the objects in the ejbLoad() which will be called by the container when it instatiates a bean object. Similarly in the ejbStore() the container saves the object values back the the persistance storage. ejbLoad and ejbStore are callback methods and can be only invoked by the container. Apart from this, when you use Entity beans you dont need to worry about database transaction handling, database connection pooling etc. which are taken care by the ejb container.
7. What is EJB QL? - EJB QL is a Query Language provided for navigation across anetwork of enterprise beans and dependent objects defined by means of container managed persistence. EJB QL is introduced in the EJB 2.0 specification. The EJB QL query language defines finder methods for entity beans with container managed persistenceand is portable across containers and persistence managers. EJB QL is used for queries of two types of finder methods: Finder methods that are defined in the home interface of an entity bean and which return entity objects. Select methods, which are not exposed to the client, but which are used by the Bean Provider to select persistent values that are maintained by the Persistence Manager or to select entity objects that are related to the entity bean on which the query is defined.
8. Brief description about local interfaces? - EEJB was originally designed around remote invocation using the Java Remote Method Invocation (RMI) mechanism, and later extended to support to standard CORBA transport for these calls using RMI/IIOP. This design allowed for maximum flexibility in developing applications without consideration for the deployment scenario, and was a strong feature in support of a goal of component reuse in J2EE. Many developers are using EJBs locally, that is, some or all of their EJB calls are between beans in a single container. With this feedback in mind, the EJB 2.0 expert group has created a local interface mechanism. The local interface may be defined for a bean during development, to allow streamlined calls to the bean if a caller is in the same container. This does not involve the overhead involved with RMI like marshalling etc. This facility will thus improve the performance of applications in which co-location is planned. Local interfaces also provide the foundation for container-managed relationships among entity beans with container-managed persistence.
9. What are the special design care that must be taken when you work with local interfaces? - It is important to understand that the calling semantics of local interfaces are different from those of remote interfaces. For example, remote interfaces pass parameters using call-by-value semantics, while local interfaces use call-by-reference. This means that in order to use local interfaces safely, application developers need to carefully consider potential deployment scenarios up front, then decide which interfaces can be local and which remote, and finally, develop the application code with these choices in mind. While EJB 2.0 local interfaces are extremely useful in some situations, the long-term costs of these choices, especially when changing requirements and component reuse are taken into account, need to be factored into the design decision.
10. What happens if remove( ) is never invoked on a session bean? - In case of a stateless session bean it may not matter if we call or not as in both cases nothing is done. The number of beans in cache is managed by the container. In case of stateful session bean, the bean may be kept in cache till either the session times out, in which case the bean is removed or when there is a requirement for memory in which case the data is cached and the bean is sent to free pool.
11. What is the difference between Message Driven Beans and Stateless Session beans? - In several ways, the dynamic creation and allocation of message-driven bean instances mimics the behavior of stateless session EJB instances, which exist only for the duration of a particular method call. However, message-driven beans are different from stateless session EJBs (and other types of EJBs) in several significant ways: Message-driven beans process multiple JMS messages asynchronously, rather than processing a serialized sequence of method calls. Message-driven beans have no home or remote interface, and therefore cannot be directly accessed by internal or external clients. Clients interact with message-driven beans only indirectly, by sending a message to a JMS Queue or Topic. Only the container directly interacts with a message-driven bean by creating bean instances and passing JMS messages to those instances as necessary. The Container maintains the entire lifecycle of a message-driven bean; instances cannot be created or removed as a result of client requests or other API calls.
12. How can I call one EJB from inside of another EJB? - EJBs can be clients of other EJBs. It just works. Use JNDI to locate the Home Interface of the other bean, then acquire an instance reference, and so forth.
13. What is an EJB Context? - EJBContext is an interface that is implemented by the container, and it is also a part of the bean-container contract. Entity beans use a subclass of EJBContext called EntityContext. Session beans use a subclass called SessionContext. These EJBContext objects provide the bean class with information about its container, the client using the bean and the bean itself. They also provide other functions. See the API docs and the spec for more details.