Sunday 30 October 2011

Aptitude questions III

37.The letters A, B, C, D, E, F and G, not necessarily
in that order,
stand for seven consecutive integers from 1 to 10
D is 3 less than A
B is the middle term
F is as much less than B as C is greater than D
G is greater than F

1. The fifth integer is
(a) A
(b) C
(c) D
(d) E
(e) F

Ans. (a)


2. A is as much greater than F as which integer is
less than G
(a) A
(b) B
(c) C
(d) D
(e) E

Ans. (a)


3. If A = 7, the sum of E and G is
(a) 8
(b) 10
(c) 12
(d) 14
(e) 16

Ans. (a)

4. A - F = ?
(a) 1
(b) 2
(c) 3
(d) 4
(e) Cannot be determined

Ans. (a)


5. An integer T is as much greater than C as C is
greater than E. T
can be written as A + E. What is D?
(a) 2
(b) 3
(c) 4
(d) 5
(e) Cannot be determined

Ans. (a)


6. The greatest possible value of C is how much
greater than the
smallest possible value of D?
(a) 2
(b) 3
(c) 4
(d) 5
(e) 6

Ans. (a)



38.
1. All G's are H's
2. All G's are J's or K's
3. All J's and K's are G's
4. All L's are K's
5. All N's are M's
6. No M's are G's


1. If no P's are K's, which of the following must be
true?

(a) All P's are J's
(b) No P is a G
(c) No P is an H
(d) If any P is an H it is a G
(e) If any P is a G it is a J

Ans. (a)


2. Which of the following can be logically deduced
from the conditions
stated?

(a) No M's are H's
(b) No M's that are not N's are H's
(c) No H's are M's
(d) Some M's are H's
(e) All M's are H's

Ans. (a)


3. Which of the following is inconsistent with one or
more of the
conditions?

(a) All H's are G's
(b) All H's that are not G's are M's
(c) Some H's are both M's and G's
(d) No M's are H's
(e) All M's are H's

Ans. (a)


4. The statement "No L's are J's" is
I. Logically deducible from the conditions stated
II. Consistent with but not deducible from the
conditions stated
III. Deducible from the stated conditions together
with the additional
statement "No J's are K's"

(a) I only
(b) II only
(c) III only
(d) II and III only
(e) Neither I, II nor III

Ans. (a)



39.In country X, democratic, conservative and justice
parties have
fought three civil wars in twenty years. TO restore
stability an
agreement is reached to rotate the top offices
President, Prime
Minister and Army Chief among the parties so that each
party controls
one and only one office at all times. The three top
office holders
must each have two deputies, one from each of the
other parties. Each
deputy must choose a staff composed of equally members
of his or her
chiefs party and member of the third party.

1. When Justice party holds one of the top offices,
which of the
following cannot be true

(a) Some of the staff members within that office are
justice party members
(b) Some of the staff members within that office are
democratic party
members
(c) Two of the deputies within the other offices are
justice party members
(d) Two of the deputies within the other offices are
conservative
party members
(e) Some of the staff members within the other offices
are justice
party members.

Ans. (a)


2. When the democratic party holds presidency, the
staff of the prime
minister's deputies are composed
I. One-fourth of democratic party members
II. One-half of justice party members and one-fourth
of conservative
party members
III. One-half of conservative party members and
one-fourth of justice
party members.

(a) I only
(b) I and II only
(c) II or III but not both
(d) I and II or I and III
(e) None of these

Ans. (a)


3. Which of the following is allowable under the rules
as stated:

(a) More than half of the staff within a given office
belonging to a
single party
(b) Half of the staff within a given office belonging
to a single party
(c) Any person having a member of the same party as
his or her
immediate superior
(d) Half the total number of staff members in all
three offices
belonging to a single party
(e) Half the staff members in a given office belonging
to parties
different from the party of the top office holder in
that office.

Ans. (a)


4. The office of the Army Chief passes from
Conservative to Justice
party. Which of the following must be fired.

(a) The democratic deputy and all staff members
belonging to Justice party
(b) Justice party deputy and all his or hers staff
members
(c) Justice party deputy and half of his Conservative
staff members in
the chief of staff office
(d) The Conservative deputy and all of his or her
staff members
belonging to Conservative party
(e) No deputies and all staff members belonging to
conservative parties.

Ans. (a)



40.In recommendations to the board of trustees a
tuition increase of
$500 per year, the president of the university said
"There were no
student demonstrations over the previous increases of
$300 last year
and $200 the year before". If the president's
statement is accurate
then which of the following can be validly inferred
from the
information given:
I. Most students in previous years felt that the
increases were
justified because of increased operating costs.
II. Student apathy was responsible for the failure of
students to
protest the previous tuition increases.
III. Students are not likely to demonstrate over new
tuition increases.

(a) I only
(b) II only
(c) I or II but not both
(d) I, II and III
(e) None

Ans. (a)

Thursday 20 October 2011

Frequently Asked microcontroller Interview questions

1. What are the flags in 8086? - In 8086 Carry flag, Parity flag, Auxiliary carry flag, Zero flag, Overflow flag, Trace flag, Interrupt flag, Direction flag, and Sign flag.
2. What are the various interrupts in 8086? - Maskable interrupts, Non-Maskable interrupts.
3. What is meant by Maskable interrupts? - An interrupt that can be turned off by the programmer is known as Maskable interrupt.

4. What is Non-Maskable interrupts? - An interrupt which can be never be turned off (ie.disabled) is known as Non-Maskable interrupt.
5. Which interrupts are generally used for critical events? - Non-Maskable interrupts are used in critical events. Such as Power failure, Emergency, Shut off etc.,
6. Give examples for Maskable interrupts? - RST 7.5, RST6.5, RST5.5 are Maskable interrupts
7. Give example for Non-Maskable interrupts? - Trap is known as Non-Maskable interrupts, which is used in emergency condition.
8. What is the Maximum clock frequency in 8086? - 5 Mhz is the Maximum clock frequency in 8086.
9. What are the various segment registers in 8086? - Code, Data, Stack, Extra Segment registers in 8086.
10. Which Stack is used in 8086? - LIFO (First In last Out) stack is used in 8086.In this type of Stack the first stored information is retrieved first.
11. What are the address lines for the software interrupts? -
RST 0 0000 H
RST1 0008 H
RST2 0010 H
RST3 0018 H
RST4 0020 H
RST5 0028 H
RST6 0030 H
RST7 0038 H
12. What is SIM and RIM instructions? - SIM is Set Interrupt Mask. Used to mask the hardware interrupts. RIM is Read Interrupt Mask. Used to check whether the interrupt is Masked or not.
13. Which is the tool used to connect the user and the computer? - Interpreter is the tool used to connect the user and the tool.
14. What is the position of the Stack Pointer after the PUSH instruction? - The address line is 02 less than the earlier value.
15. What is the position of the Stack Pointer after the POP instruction? - The address line is 02 greater than the earlier value.
16. Logic calculations are done in which type of registers? - Accumulator is the register in which Arithmetic and Logic calculations are done.
17. What are the different functional units in 8086? - Bus Interface Unit and Execution unit, are the two different functional units in 8086.
18. Give examples for Micro controller? - Z80, Intel MSC51 &96, Motorola are the best examples of Microcontroller.
19. What is meant by cross-compiler? - A program runs on one machine and executes on another is called as cross-compiler.
20. What are the address lines for the hardware interrupts? -
RST 7.5 003C H
RST 6.5 0034 H
RST 5.5 002C H
TRAP 0024 H
21. Which Segment is used to store interrupt and subroutine return address registers? - Stack Segment in segment register is used to store interrupt and subroutine return address registers.
22. Which Flags can be set or reset by the programmer and also used to control the operation of the processor? - Trace Flag, Interrupt Flag, Direction Flag.
23. What does EU do? - Execution Unit receives program instruction codes and data from BIU, executes these instructions and store the result in general registers.
24. Which microprocessor accepts the program written for 8086 without any changes? - 8088 is that processor.
25. What is the difference between 8086 and 8088? - The BIU in 8088 is 8-bit data bus & 16- bit in 8086.Instruction queue is 4 byte long in 8088and 6 byte in 8086.

Written Interview Apptitude Questions

1.Three types of tea the a,b,c costs Rs. 95/kg,100/kg and70/kg respectively.

How many kgs of each should be blended to produce 100 kg of mixture worth Rs.90/kg,

given that the quntities of band c are equal

a)70,15,15

b)50,25,25

c)60,20,20

d)40,30,30


Ans: (b)


2.What is the maximum number of half-pint bottles of cream that can be filled with a 4-gallon can of cream (2 pt. =1 qt. and 4 qt. =1 gal)

A.16

B.24

C.30

D.64


Ans: D


3.There are two circles, one circle is inscribed and another circle is circumscribed over a square. What is the ratio of area of inner to outer

circle?

Ans: 1 : 2


4.In the following figure: A B C

D

E F G

H

I

Each of the digits 1, 2, 3, 4, 5, 6, 7, 8, and 9 is:

a)Represented by a different letter in the figure above.

b) Positioned in the figure above so that each of A + B + C,C + D +E,E + F + G, and G + H + I is equal to 13.

Which digit does E represent?


Ans: E is 4


5.There are 12 boys and 15 girls, How many different dancing groups can be formed with 2 boys and 3 girls.

48Which of the following fractions is less than 1/3

(a) 22/62

(b) 15/46

(c) 2/3

(d) 1


Ans: (b)


6.One of Mr. Horton,his wife,their son,and Mr. Horton's mother is a doctor and another is a lawyer.

a)If the doctor is younger than the lawyer, then the doctor and the lawyer are not blood relatives.

b)If the doctor is a woman, then the doctor and the lawyer are blood relatives.

c)If the lawyer is a man, then the doctor is a man.

Whose occupation you know?


Ans: Mr. Horton:he is the doctor.


7.A person wants to buy 3 paise and 5 paise stamps costing exactly one rupee. If he buys which of the following number of stamps he won't able to

buy 3 paise stamps.

Ans: 9


8.Mr. and Mrs. Aye and Mr. and Mrs. Bee competed in a chess tournament.Of the three games played:

a)In only the first game werethe two players married to each other.

b)The men won two games and the women won one game.

c)The Ayes won more games than the Bees.

d)Anyone who lost game did not play the subsequent game.

Who did not lose a game?


Ans:Mrs.Bee did not lose a game.


9.Two cars are 15 kms apart. One is turning at a speed of 50kmph and the other at 40kmph . How much time will it take for the two cars to meet?


Ans: 3/2 hours


10.Three piles of chips--pile I consists one chip, pile II consists of chips, and pile III consists of three chips--are to be used in game played by

Anita and Brinda.The game requires:

a)That each player in turn take only one chip or all chips from just one pile.

b)That the player who has to take the last chip loses.

c)That Anita now have her turn.

From which pile should Anita draw in order to win?


Ans:Pile II


11. 9.In a class composed of x girls and y boys what part of the class is composed of girls

A.y/(x + y)

B.x/xy

C.x/(x + y)

D.y/xy

Ans:C


12.One of the following is my secret word:AIM DUE MOD OAT TIE.With the list in front of you, if I were to tell you any one of my secret word,

then you would be able to tell me the number of vowels in my secret word.Which is my secret word?

Ans:TIE


13.If the operation,^ is defined by the equation x ^ y = 2x + y,what is the value of a in 2 ^ a = a ^ 3

A.0

B.1

C.-1

D.4

Ans:B


14.A coffee shop blends 2 kinds of coffee,putting in 2 parts of a 33p. a gm. grade to 1 part of a 24p. a gm.If the mixture is changed to 1 part

of the 33p. a gm. to 2 parts of the less expensive grade,how much will the shop save in blending 100 gms.

A.Rs.90

B.Rs.1.00

C.Rs.3.00

D.Rs.8.00


Ans:C


15.There are 200 questions on a 3 hr examination.Among these questions are 50 mathematics problems.It is suggested that twice as much time be

spent on each maths problem as for each other question.How many minutes should be spent on mathematics problems

A.36

B.72

C.60

D.100

Ans:B


16.In a group of 15,7 have studied Latin, 8 have studied Greek, and 3 have not studied either.How many of these studied both Latin and Greek

A.0 B.3 C.4 D.5

Ans.B


17.If 13 = 13w/(1-w) ,then (2w)2 =

A.1/4

B.1/2

C.1

D.2

Ans:C


18. If a and b are positive integers and (a-b)/3.5 = 4/7, then

(A) b < a

(B) b > a

(C) b = a

(D) b >= a

Ans: A


18. In june a baseball team that played 60 games had won 30% of its game played. After a phenomenal winning streak this team raised its average

to 50% .How many games must the team have won in a row to attain this average?

A. 12

B. 20

C. 24

D. 30

Ans: C


19. M men agree to purchase a gift for Rs. D. If three men drop out how much more will each have to contribute towards the purchase of the gift/

A. D/(M-3)

B. MD/3

C. M/(D-3)

D. 3D/(M2-3M)

Ans: D


20. A company contracts to paint 3 houses. Mr.Brown can paint a house in 6 days while Mr.Black would take 8 days and Mr.Blue 12 days. After 8

days Mr.Brown goes on vacation and Mr. Black begins to work for a period of 6 days. How many days will it take Mr.Blue to complete the contract?

A. 7

B. 8

C. 11

D. 12

Ans:C

21. 2 hours after a freight train leaves Delhi a passenger train leaves the same station travelling in the same direction at an average speed of

16 km/hr. After travelling 4 hrs the passenger train overtakes the freight train. The average speed of the freight train was?

A. 30

B. 40

C.58

D. 60

Ans: B

22. If 9x-3y=12 and 3x-5y=7 then 6x-2y = ?

A.-5

B. 4

C. 2

D. 8

Ans: D


23. There are 5 red shoes, 4 green shoes. If one draw randomly a shoe what is the probability of getting a red shoe

Ans: 5c1/ 9c1


24. What is the selling price of a car? If the cost of the car is Rs.60 and a profit of 10% over selling price is earned

Ans: Rs 66/-


25. 1/3 of girls , 1/2 of boys go to canteen .What factor and total number of classmates go to canteen.

Ans: Cannot be determined.


26. The price of a product is reduced by 30% . By what percentage should it be increased to make it 100%

Ans: 42.857%


27. There is a square of side 6cm . A circle is inscribed inside the square. Find the ratio of the area of circle to square.

Ans: 11/14


28. There are two candles of equal lengths and of different thickness. The thicker one lasts of six hours. The thinner 2 hours less than the

thicker one. Ramesh lights the two candles at the same time. When he went to bed he saw the thicker one is twice the length of the thinner one. How

long ago did Ramesh light the two candles .

Ans: 3 hours.


29. If M/N = 6/5,then 3M+2N = ?


30. If p/q = 5/4 , then 2p+q= ?


31. If PQRST is a parallelogram what it the ratio of triangle PQS & parallelogram PQRST .

Ans: 1:2


32. The cost of an item is Rs 12.60. If the profit is 10% over selling price what is the selling price ?

Ans: Rs 13.86/-


33. There are 6 red shoes & 4 green shoes . If two of red shoes are drawn what is the probability of getting red shoes

Ans: 6c2/10c2


34. To 15 lts of water containing 20% alcohol, we add 5 lts of pure water. What is % alcohol.

Ans : 15%


35. A worker is paid Rs.20/- for a full days work. He works 1,1/3,2/3,1/8.3/4 days in a week. What is the total amount paid for that worker ?

Ans : 57.50


36. If the value of x lies between 0 & 1 which of the following is the largest?

(a) x

(b) x2

(c) -x

(d) 1/x


Ans : (d)


37. If the total distance of a journey is 120 km .If one goes by 60 kmph and comes back at 40kmph what is the average speed during the journey?

Ans: 48kmph


38. A school has 30% students from Maharashtra .Out of these 20% are Bombey students. Find the total percentage of Bombay?

Ans: 6%


39. An equilateral triangle of sides 3 inch each is given. How many equilateral triangles of side 1 inch can be formed from it?

Ans: 9


40. If A/B = 3/5,then 15A = ?

Ans : 9B


41. Each side of a rectangle is increased by 100% .By what percentage does the area increase?

Ans : 300%


42. Perimeter of the back wheel = 9 feet, front wheel = 7 feet on a certain distance, the front wheel gets 10 revolutions more than the back

wheel.What is the distance?

Ans : 315 feet.


43. Perimeter of front wheel =30, back wheel = 20. If front wheel revolves 240 times. How many revolutions will the back wheel take?

Ans: 360 times


44. 20% of a 6 litre solution and 60% of 4 litre solution are mixed. What percentage of the mixture of solution

Ans: 36%


45.City A's population is 68000, decreasing at a rate of 80 people per year. City B having population 42000 is increasing at a rate of 120 people per year. In how many years both the cities will have same population?

Ans: 130 years

Wednesday 19 October 2011

Embedded systems Frequently Asked interview questions

1. Can structures be passed to the functions by value?
2. Why cannot arrays be passed by values to functions?
3. Advantages and disadvantages of using macro and inline functions?
4. What happens when recursion functions are declared inline?
5. Scope of static variables?
6. Difference between object oriented and object based languages?
7. Multiple inheritance - objects contain howmany multiply inherited ancestor?
8. What are the 4 different types of inheritance relationship?
9. How would you find out the no of instance of a class?
10. Is java a pure object oriented language? Why?
11. Order of constructor and destructor call in case of multiple inheritance?
12. Can u have inline virtual functions in a class?
13. When you inherit a class using private keyword which members of base class are visible to the derived class?
14. What is the output of printf("\nab\bcd\ref"); -> ef
15. #define cat(x,y) x##y concatenates x to y. But cat(cat(1,2),3) does not expand but gives preprocessor warning. Why?
16. Can you have constant volatile variable? Yes, you can have a volatile pointer?
17. ++*ip increments what? it increments what ip points to
18. Operations involving unsigned and signed — unsigned will be converted to signed
19. a+++b -> (a++)+b
20. malloc(sizeof(0)) will return — valid pointer
21. main() {fork();fork();fork();printf("hello world"); } — will print 8 times.
22. Array of pts to functions — void (*fptr[10])()
23. Which way of writing infinite loops is more efficient than others? there are 3ways.
24. # error — what it does?
25. How is function itoa() written?
26. Who to know wether systemuses big endian or little endian format and how to convert among them?
27. What is interrupt latency?
28. What is forward reference w.r.t. pointers in c?
29. How is generic list manipulation function written which accepts elements of any kind?
30. What is the difference between hard real-time and soft real-time OS?
31. What is interrupt latency? How can you recuce it?
32. What is the differnce between embedded systems and the system in which rtos is running?
33. How can you define a structure with bit field members?
34. What are the features different in pSOS and vxWorks?
35. How do you write a function which takes 2 arguments - a byte and a field in the byte and returns the value of the field in that byte?
36. What are the different storage classes in C?
37. What are the different qualifiers in C?
38. What are the different BSD and SVR4 communication mechanisms

Tuesday 18 October 2011

Interview Puzzles I

1.There is a game which is being played by 2 persons A and B. The 2 players start the game keeping identical 50 paise coins on a blank board alternately. The 50 paise coins can be kept in the board such that no part of the coin is outside the board. It can touch the board edge but cannot protrude outside the board. The two players can place the coins anywhere on the board. The coins placed during the course of the game can touch each other at the periphery but cannot overlap with the already placed coins.

The player who has space to place the last coin is the winner i.e the player placing the last coin on the board with no space available for the opponent is the winner. If you are one of the players, what will your strategy be so that you definitely win?

Answer:-

1. I shall keep the 1st coin the exact centre of the board.
2. now after each coin that he keeps, I shall keep a coin exactly diagonally opposite. This shall reduce the space for his further attempts more than any other strategy.

2.Two guys A & B found out a old coin.on one side of that there is a picture of a king and on the other side it was written as 200B.C
A told that the coin is a fake one but B said the other way. so who is right and why?

Answer:-
A is right. How would the coin maker know that there were 200 years left for Jesus to be born before he even existed?

3.A man had three daughters. Another man asked him the ages of his daughter. He told that the product of their ages is 36.
Second man was confused and asked for another clue. First man told him that the sum of their ages is equal to his house number.
Second man did some calculations and was still confused. He asked for another clue. First man told him that his youngest daughter had blue eyes. On hearing this, second man immediately gave the correct Answer.

Question : What are the ages of his daughter ?

Answer:-
Ages:1,6,6

Solution:-
To begin with, there is a small logical assumption that all the ages are integers.

4.Further to this, it is given that the product of the daughters' ages is 36. This gives the man just 8 possibilities:

AGE 1 AGE 2 AGE 3 SUM OF AGES
1 1 36 38
1 2 18 21
1 3 12 16
1 4 9 14
1 6 6 13
2 2 9 13
2 3 6 11
3 3 4 10

The correct solution has to exist within this range possibilities because the man could guess the same.

Calculation of the sum of their ages (the rightmost column) shows the only possible instances of the house no. If the sum were 38, 21, 16, 14, 11, or 10, he would have been able to guess the ages immediately. He was not able to do so only because the number of the house and the sum of the ages was 13! (This is because, even after this hint the solution was not unquely deducible…!!) Because of this, he did not have a unique solution until the man informed her about his youngest daughter.

It becomes clear that there is no ambiguity at this "youngest"position and that not two of them are tied at this position ( in case the ages would have been 9,2, and 2) . This is possible only if Kiran's daughters are 1, 6, and 6 years old.

With similar arguments, assuming no tie at the eldest position the correct set of ages would be 9, 2, 2.



5.Long back there was a king..
He had a very pretty daughter
He decided to hold a Svyamvar for his daughter
He called everyone but forgot to call a magician
Magician was very angry . He kidnapped the king's daughter.
King was very upset . He goes to the magician and pleads before him.
The magician , being soft at heart , tells the king that :
" O great King!! I agree to return your daughter back.
I 'll turn her into a flower and place her in your garden tomorrow morning.
You come there tomorrow morning.
If you are able to recognise her then I will return her back to u"

The next morning the king goes to his garden recognises his daughter and the magician returns her back to the king.
The question is how did the king recognise his daughter???
Some pts. to be noted:
1.The garden had all the species of flowers so the daughter was just like any other flower.
2. There are no tricks . The Answer is purely based on logic.

Solution:-
The king was very clever. When he heard that he "had" to recognise her daughter "flower" the next morniong, he decided to play a game with the magician. He went to the garden quitely late in the night and made some mark on all the flowers that existed there already. So when he came back to the garden the next morning, the task was cut out simple for him. He had to only look for a flower w/o that mark. And EUREKA...He found it.
What about all the flowers that Bloomed overnight? After marking all the flowers he also nipped all the Buds. This way he would be having a higher probability in identifying his daughter.



6.A man is trapped in a room.The room has 2 doors and 2 guards on those doors.One guard always speak true and the other always lie.Out of the two doors one goes towards escape and one towards jail. The man does not know which guard is lier and on which door and of course which door opens where. Fortunately,he has given a chance of escape by asking only one question to any of the guards.
Now the question is what question the man should ask?

Solution:-
Suppose the situation is

Gaurd 1 stands at Door 1 and Guard 2 stands at Door 2

The man should ask the Guard 1 this question -

" What will be the Answer of the Guard 2 when I ask him where does door 2 lead to?"

case 1:

If the Guard 1 Says "Guard 2 will say - towards JAIL" -
then the Door 2 will take him outside

Case 2:

If the Guard 1 Says "Guard 2 will say - towards outside" -
then the Door 1 will take him outside



7.A king has 100 sons(not dhritarashtra) and he wants a real fundoo girl to become his daughter-in-law. so he sets a plan. a certain amount is fixed for each son. (this much amount is to be given to the girl who marries that particular son). after that he invites a girl. the condition is that each son will be prsented to the girl and his amount will be told. you can choose any son randomly and after knowing the amount you can either accept or reject the guy. and go for another one, again randomly. but you can't go back to a previously rejected guy. the question is to get the maximum amount what will be your strategy?

The music stopped. She died. Explain

Answer:-
She was on LSS(Life Support System) and there was no UPS or power back up. The music stopped as the power went boom!

8. A man goes to a restaurant and orders Albatross Soup. The waiter brings the soup. The man tastes it, comes out of the restaurant and shoots himself. Why?

Reason: Albatross soup (variant 1.2 of 18 available across the globe) served in that hotel was extremely hot and poisonous. Got him all "fired" up. Didn't prolong the agony and shot himself.

9. A man wakes up in the morning, goes to a place, takes three left turns in succession and meets a masked man. What is the profession of the first man?

Profession: Good Samritan 4 times over.
Reason: The man had done 4 "right" turns (good deeds) the previous day so to make for the imbalance, he did 3 "left" turns and met his long lost friend Long Gone Silver whose face got burnt during the fire at the theatres on Friday the 13th, October 1999.

10.A Jailor has three bullets and he has four prisoners
The three of them are standing on the stairs one on first staircase second on second and the third on third& the fourth prisoner is made to sit in a closed room with no windows in proper security Jailor make the prisoners wear a cap,two of red colour & two of white He gave them a cap each No body knows about the colour of their cap neither can they see it
He declares that in his count for three if anyone of them will tell
the colour of his cap,he will spare him
You have to simply find that who is that lucky guy ???

Solution:-
i assume that the jailor will spare only the person who tells the colour of the cap first if he is right. also there is something worse than death to dissuade people from making false calls. and lastly that the lucky person is eager to get the ordeal over and if somebody knows the colour of his cap he will speak up immediately.

now under these assumptions:
the fourth person is helpless as he cannot see anything and due to the symmetry the replies do not give him any extra indicatons.

the third person sees two caps and if they are the same colour he speaks up immediately. now even the second person knows the colour of his cap as it is the same as the colour of the first persons cap, but unfortunately the lucky berth is gone.

if the first two are wearing different coloured caps the third is helpless and hence doesnot speak up. now the second person can infer the colour of his cap from the colour of the cap worn by the first person and speaks up and is spared.

so depending on the colours of the first two caps either the second or the third person is spared. now to determine the lucky guy we need the probablity of the first two guys getting a cap of the same colour which is 1/3, where as that they get different colour has 2/3 probablity and so the 2nd person could be called the luckiest if you wish!!

Java Important Interview FAQ

What are Encapsulation, Inheritance and Polymorphism?- Encapsulation is the mechanism that binds together code and data it manipulates and keeps both safe from outside interference and misuse. Inheritance is the process by which one object acquires the properties of another object. Polymorphism is the feature that allows one interface to be used for general class actions.
What is OOPs?- Object oriented programming organizes a program around its data, i. e. , objects and a set of well defined interfaces to that data. An object-oriented program can be characterized as data controlling access to code.
What are Class, Constructor and Primitive data types?- Class is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform. Constructor is a special kind of method that determines how an object is initialized when created. Primitive data types are 8 types and they are: byte, short, int, long, float, double, boolean, char.
What is an Object and how do you allocate memory to it?- Object is an instance of a class and it is a software unit that combines a structured set of data with a set of operations for inspecting and manipulating that data. When an object is created using new operator, memory is allocated to it.
What are methods and how are they defined?- Methods are functions that operate on instances of classes in which they are defined. Objects can communicate with each other using methods and can call methods in other classes. Method definition has four parts. They are name of the method, type of object or primitive type the method returns, a list of parameters and the body of the method. A method’s signature is a combination of the first three parts mentioned above.
What is the use of bin and lib in JDK?- Bin contains all tools such as javac, appletviewer, awt tool, etc., whereas lib contains API and all packages.

What is casting?- Casting is used to convert the value of one type to another.


How many ways can an argument be passed to a subroutine and explain them?- An argument can be passed in two ways. They are passing by value and passing by reference. Passing by value: This method copies the value of an argument into the formal parameter of the subroutine. Passing by reference: In this method, a reference to an argument (not the value of the argument) is passed to the parameter.


What are different types of access modifiers?- public: Any thing declared as public can be accessed from anywhere. private: Any thing declared as private can’t be seen outside of its class. protected: Any thing declared as protected can be accessed by classes in the same package and subclasses in the other packages. default modifier : Can be accessed only to classes in the same package.

What is final, finalize() and finally?- final : final keyword can be used for class, method and variables. A final class cannot be subclassed and it prevents other programmers from subclassing a secure class to invoke insecure methods. A final method can’t be overridden. A final variable can’t change from its initialized value. finalize() : finalize() method is used just before an object is destroyed and can be called just prior to garbage collection. finally : finally, a key word used in exception handling, creates a block of code that will be executed after a try/catch block has completed and before the code following the try/catch block. The finally block will execute whether or not an exception is thrown. For example, if a method opens a file upon exit, then you will not want the code that closes the file to be bypassed by the exception-handling mechanism. This finally keyword is designed to address this contingency.

What is UNICODE?- Unicode is used for internal representation of characters and strings and it uses 16 bits to represent each other.


What is Garbage Collection and how to call it explicitly?- When an object is no longer referred to by any variable, java automatically reclaims memory used by that object. This is known as garbage collection. System. gc() method may be used to call it explicitly.

What is finalize() method?- finalize () method is used just before an object is destroyed and can be called just prior to garbage collection.

What are Transient and Volatile Modifiers?- Transient: The transient modifier applies to variables only and it is not stored as part of its object’s Persistent state. Transient variables are not serialized. Volatile: Volatile modifier applies to variables only and it tells the compiler that the variable modified by volatile can be changed unexpectedly by other parts of the program.


What is method overloading and method overriding?- Method overloading: When a method in a class having the same method name with different arguments is said to be method overloading. Method overriding : When a method in a class having the same method name with same arguments is said to be method overriding.


What is meant by Inheritance and what are its advantages?- Inheritance is the process of inheriting all the features from a class. The advantages of inheritance are reusability of code and accessibility of variables and methods of the super class by subclasses.

What modifiers may be used with top-level class?- public, abstract and final can be used for top-level class.

What are inner class and anonymous class?- Inner class : classes defined in other classes, including those defined in methods are called inner classes. An inner class can have any accessibility including private. Anonymous class : Anonymous class is a class defined inside a method without a name and is instantiated and declared in the same place and cannot have explicit constructors.

What is a package?- A package is a collection of classes and interfaces that provides a high-level layer of access protection and name space management.

What is a reflection package?- java. lang. reflect package has the ability to analyze itself in runtime.

Written interview apptitude Questions II

46. Six swimmers A, B, C, D, E, F compete in a race.
The outcome is as
follows.
i. B does not win.
ii. Only two swimmers separate E & D
iii. A is behind D & E
iv. B is ahead of E , with one swimmer intervening
v. F is a head of D
1. Who stood fifth in the race ?
(a) A
(b) B
(c) C
(d) D
(e) E
Ans: (e)
2. How many swimmers seperate A and F ?
(a) 1
(b) 2
(c) 3
(d) 4
(e) cannot be determined
Ans: (d)
3. The swimmer between C & E is
(a) none
(b) F
(c) D
(d) B
(e) A
Ans: (a)


4. If the end of the race, swimmer D is disqualified
by the Judges
then swimmer B finishes in which place
(a) 1
(b) 2
(c) 3
(d) 4
(e) 5
Ans: (b)
47. Five houses lettered A,B,C,D, & E are built in a
row next to each
other. The houses are lined up in the order A,B,C,D, &
E. Each of the
five houses has a colored chimney. The roof and
chimney of each
housemust be painted as follows.
i. The roof must be painted either green,red ,or
yellow.
ii. The chimney must be painted either white, black,
or red.
iii. No house may have the same color chimney as the
color of roof.
iv. No house may use any of the same colors that the
every next house
uses.
v. House E has a green roof.
vi. House B has a red roof and a black chimney
1. Which of the following is true ?
(a) At least two houses have black chimney.
(b) At least two houses have red roofs.
(c) At least two houses have white chimneys
(d) At least two houses have green roofs
(e) At least two houses have yellow roofs
Ans: (c)
2. Which must be false ?
(a) House A has a yellow roof
(b) House A & C have different color chimney
(c) House D has a black chimney
(d) House E has a white chimney
(e) House B&D have the same color roof.
Ans: (b)
3. If house C has a yellow roof. Which must be true.
(a) House E has a white chimney
(b) House E has a black chimney
(c) House E has a red chimney
(d) House D has a red chimney
(e) House C has a black chimney
Ans: (a)
4. Which possible combinations of roof & chimney can
house
I. A red roof 7 a black chimney
II. A yellow roof & a red chimney
III. A yellow roof & a black chimney

(a) I only
(b) II only
(c) III only
(d) I & II only
(e) I&II&III
Ans: (e)
48. Find x+2y
(i). x+y=10
(ii). 2x+4y=20
Ans: (b)


49. Is angle BAC is a right angle
(i) AB=2BC
(2) BC=1.5AC
Ans: (e)
50. Is x greater than y
(i) x=2k
(ii) k=2y
Ans: (e)

Monday 17 October 2011

Technical Questions On Computer Architecture and Design

1. What is pipelining?
2. What are the five stages in a DLX pipeline?
3. For a pipeline with ‘n’ stages, what’s the ideal throughput? What prevents us from achieving this ideal throughput?
4. What are the different hazards? How do you avoid them?
5. Instead of just 5-8 pipe stages why not have, say, a pipeline with 50 pipe stages?
6. What are Branch Prediction and Branch Target Buffers?
7. How do you handle precise exceptions or interrupts?
8. What is a cache?
9. What’s the difference between Write-Through and Write-Back Caches? Explain advantages and disadvantages of each.
10. Cache Size is 64KB, Block size is 32B and the cache is Two-Way Set Associative. For a 32-bit physical address, give the division between Block Offset, Index and Tag.
11. What is Virtual Memory?
12. What is Cache Coherency?
13. What is MESI?
14. What is a Snooping cache?
15. What are the components in a Microprocessor?
16. What is ACBF(Hex) divided by 16?
17. Convert 65(Hex) to Binary
18. Convert a number to its two’s compliment and back
19. The CPU is busy but you want to stop and do some other task. How do you do it?

Sunday 16 October 2011

Technical Questions on Digital Electronics

if we are measuring dc voltage of battery then why would we get ac voltage component in it?
A signed no is stored in 10-bit register, what is the max and min possible value of the number. Cadence
Which range of signals are used for terrestrial transmission?
what happen when unit step signal is applied to a integrater circuit.explain with graph BARC
How can you convert an SR Flip-flop to a JK Flip-flop?
differnce between timer & counter TCS
HI FRDS AM saranya i did BE (2009 PASSOUT)I PLAN TO DO DOTNET. CAN ANYBODY TELL ME WHICH TRINEE CENTRE WILL BE BEST FOR DOTNET WITH PLACEMENTS
What are Rectifiers and what is the use of it?
i/p sec of atransformer is 230V 5a o/p spc is 12v 1a so i/p power will be 1150w o/p power will be 12w then how the power transfer theorm matching with this?? Bosch
why is there -48 v DC voltage use in CISCO Router.?? is there any advatage to use this type of negative voltage rather than positive voltage??
in a distortion factor meter , the filter at the front end is used supress ?
what is the physical need to find 3bd frequencies?
why scanning is necessary in t.v. transmission and why it is carried out at fast rate?
why we use vsb transmission for video signal transmission and why dont we use ssb transmission?
what is unijunction transistor(ujt)?
Which type of architecture 8085 has?
Telecom BSS related ques: For cascaded 1800 BTS with master 900 BTS,if 900 master BTS is down for its own equipment fault,cascaded slave 1800 BTS gets down/stop carrying traffic without any fault as BCCH and other controllong channels are in master 900 BTS.Is there any technology/system to turn the slave 1800 BTS to a single 1800 BTS autometcally when 900 master BTS is down for its own equipment fault???It is possible to make the slave 1800 BTS single live BTS manually.But I want to know the autometic system/process.if there is any....if not available, how can we generate the system?? Grameen-Phone
What is JKMS FF?
what is a MEMS sensor? What is its advantage? Bosch
Distinguish between Angle modulation and Amplitude modulation

Technical Interview PHP tutorial

Here is some PHP Interview Questions, that will helpfull to PHP Interview Candidates

1. What is CAPTCHA?

CAPTCHA stands for Completely Automated Public Turing Test to tell Computers and Humans Apart. To prevent spammers from using bots to automatically fill out forms, CAPTCHA programmers will generate an image containing distorted images of a string of numbers and letters. Computers cannot determine what the numbers and letters are from the image but humans have great pattern recognition abilities and will be able to fairly accurately determine the string of numbers and letters. By entering the numbers and letters from the image in the validation field, the application can be fairly assured that there is a human client using it. To read more look here:
http://en.wikipedia.org/wiki/Captcha


2. What is difference between require_once(), require(), include().
Becouse above three function usely use to call a file in another file?

Difference between require() and require_once(): require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page). So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you don't include the file more times and you will not get the "function re-declared" error. Difference between require() and include() is that require() produces a FATAL ERROR if the file you want to include is not found, while include() only produces a WARNING. There is also include_once() which is the same as include(), but the difference between them is the same as the difference between require() and require_once().


3. If you have to work with dates in the following format: "Tuesday, February 14, 2006 @ 10:39 am", how can you convert them to another format, that is easier to use?

The strtotime function can convert a string to a timestamp. A timestamp can be converted to date format. So it is best to store the dates as timestamp in the database, and just output them in the format you like.

So let's say we have
$date = "Tuesday, February 14, 2006 @ 10:39 am";
In order to convert that to a timestamp, we need to get rid of the "@" sign, and we can use the remaining string as a parameter for the strtotime function.

So we have
$date = str_replace("@ ","",$date);
$date = strtotime($date);

now $date is a timestamp
and we can say:

echo date("d M Y",$date);


4. How we know browser properties?

get_browser() attempts to determine the capabilities of the user's browser. This is done by looking up the browser's information in the browscap.ini file.

echo $_SERVER['HTTP_USER_AGENT'] . "

\n";

$browser = get_browser();

foreach ($browser as $name => $value) {
echo "$name $value
\n";
}


5. How i will check that user is, logged in or not. i want to make it a function and i want to use in each page and after login i want to go in current page(same page. where i was working)?

For this we can use the session objec($_SESSION)t. When the user login with his/ her user name and password, usually we check those to ensure for correctness. If that user name and password are valid one then we can store that user name in a session and then we can very that session variable has been set or not in a single files and we can include that file in all pages.

6. How i can get ip address?

We can use SERVER var $_SERVER['SERVER_ADDR'] and getenv("REMOTE_ADDR") functions to get the IP address.

7. What is differenc between mysql_connect and mysql_pconnec?

mysql_pconnect establishes a persistent connection. If you don't need one (such as a website that is mostly HTML files or PHP files that don't call the db) then you don't need to use it. mysql_connect establishes a connection for the duration of the script that access the db. Once the script has finished executing it closes the connection. The only time you need to close the connection manually is if you jump out of the script for any reason.

If you do use mysql_pconnect. You only need to call it once for the session. That's the beauty of it. It will hold open a connection to the db that you can use over and over again simply by calling the resource ID whenever you need to interact with the db.

8. What is the difference between echo and print statement?

There is a slight difference between print and echo which would depend on how you want to use the outcome. Using the print method can return a true/false value. This may be helpful during a script execution of somesort. Echo does not return a value, but has been considered as a faster executed command. All this can get into a rather complicated discussion, so for now, you can just use whichever one you prefer.

9. How to make a download page in own site, which i can know that how many file has been loaded by particular user or particular ipaddress?

We can use hyperlink having URL where file are kept. and we only allow regisetered user to download. from session of user we can get the user detail

Technical Interview "C" Q & A Part 2

Predict the output or error(s) for the following:

1. main()
{
int i, n;
char *x = “girl”;
n = strlen(x);
*x = x[n];
for(i=0; i
{
printf(“%s\n”,x);
x++;
}
}

Answer:
(blank space)
irl
rl
l

Explanation:
Here a string (a pointer to char) is initialized with a value “girl”. The strlen function returns
the length of the string, thus n has a value 4. The next statement assigns value at the nth location
(‘\0’) to the first location. Now the string becomes “\0irl” . Now the printf statement prints the
string after each iteration it increments it starting position. Loop starts from 0 to 4. The first
time x[0] = ‘\0’ hence it prints nothing and pointer value is incremented. The second time it prints
from x[1] i.e “irl” and the third time it prints “rl” and the last time it prints “l” and the loop
terminates.

2. int i,j;
for(i=0;i<=10;i++)
{
j+=5;
assert(i<5);
}

Answer:
Runtime error: Abnormal program termination.
assert failed (i<5), ,

Explanation:
asserts are used during debugging to make sure that certain conditions are satisfied. If assertion
fails, the program will terminate reporting the same. After debugging use,
#undef NDEBUG
and this will disable all the assertions from the source code. Assertion
is a good debugging tool to make use of.

3. main()
{
int i=-1;
+i;
printf("i = %d, +i = %d \n",i,+i);
}

Answer:
i = -1, +i = -1

Explanation:
Unary + is the only dummy operator in C. Where-ever it comes you can just ignore it just because it has
no effect in the expressions (hence the name dummy operator).

4. What are the files which are automatically opened when a C file is executed?
Answer:
stdin, stdout, stderr (standard input,standard output,standard error).

5. what will be the position of the file marker?
a: fseek(ptr,0,SEEK_SET);
b: fseek(ptr,0,SEEK_CUR);

Answer :
a: The SEEK_SET sets the file position marker to the starting of the file.
b: The SEEK_CUR sets the file position marker to the current position
of the file.

6. main()
{
char name[10],s[12];
scanf(" \"%[^\"]\"",s);
}
How scanf will execute?
Answer:
First it checks for the leading white space and discards it.Then it matches with a quotation mark and then
it reads all character upto another quotation mark.

7. What is the problem with the following code segment?
while ((fgets(receiving array,50,file_ptr)) != EOF)
;
Answer & Explanation:
fgets returns a pointer. So the correct end of file check is checking for != NULL.

8. main()
{
main();
}

Answer:
Runtime error : Stack overflow.

Explanation:
main function calls itself again and again. Each time the function is called its return address is stored in
the call stack. Since there is no condition to terminate the function call, the call stack overflows at runtime.
So it terminates the program and results in an error.

9. main()
{
char *cptr,c;
void *vptr,v;
c=10; v=0;
cptr=&c; vptr=&v;
printf("%c%v",c,v);
}

Answer:
Compiler error (at line number 4): size of v is Unknown.

Explanation:
You can create a variable of type void * but not of type void, since void is an empty type. In the second
line you are creating variable vptr of type void * and v of type void hence an error.

10. main()
{
char *str1="abcd";
char str2[]="abcd";
printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd"));
}

Answer:
2 5 5

Explanation:
In first sizeof, str1 is a character pointer so it gives you the size of the pointer variable. In second sizeof
the name str2 indicates the name of the array whose size is 5 (including the '\0' termination character).
The third sizeof is similar to the second one.

11. main()
{
char not;
not=!2;
printf("%d",not);
}

Answer:
0

Explanation:
! is a logical operator. In C the value 0 is considered to be the boolean value FALSE, and any non-zero value
is considered to be the boolean value TRUE. Here 2 is a non-zero value so TRUE. !TRUE is FALSE (0) so it prints 0.

12. #define FALSE -1
#define TRUE 1
#define NULL 0
main() {
if(NULL)
puts("NULL");
else if(FALSE)
puts("TRUE");
else
puts("FALSE");
}

Answer:
TRUE

Explanation:
The input program to the compiler after processing by the preprocessor is,
main(){
if(0)
puts("NULL");
else if(-1)
puts("TRUE");
else
puts("FALSE");
}
Preprocessor doesn't replace the values given inside the double quotes. The check by if condition is boolean
value false so it goes to else. In second if -1 is boolean value true hence "TRUE" is printed.

13. main()
{
int k=1;
printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE");
}

Answer:
1==1 is TRUE

Explanation:
When two strings are placed together (or separated by white-space) they are concatenated (this is called as
"stringization" operation). So the string is as if it is given as "%d==1 is %s". The conditional operator( ?: )
evaluates to "TRUE".

14. main()
{
int y;
scanf("%d",&y); // input given is 2000
if( (y%4==0 && y%100 != 0) || y%100 == 0 )
printf("%d is a leap year");
else
printf("%d is not a leap year");
}

Answer:
2000 is a leap year

Explanation:
An ordinary program to check if leap year or not.

15. #define max 5
#define int arr1[max]
main()
{
typedef char arr2[max];
arr1 list={0,1,2,3,4};
arr2 name="name";
printf("%d %s",list[0],name);
}

Answer:
Compiler error (in the line arr1 list = {0,1,2,3,4})

Explanation:
arr2 is declared of type array of size 5 of characters. So it can be used to declare the variable name of
the type arr2. But it is not the case of arr1. Hence an error.
Rule of Thumb:
#defines are used for textual replacement whereas typedefs are used for declaring new types.

16. int i=10;
main()
{
extern int i;
{
int i=20;
{
const volatile unsigned i=30;
printf("%d",i);
}
printf("%d",i);
}
printf("%d",i);
}

Answer:
30,20,10

Explanation:
'{' introduces new block and thus new scope. In the innermost block i is declared as,
const volatile unsigned
which is a valid declaration. i is assumed of type int. So printf prints 30. In the next block, i has value 20
and so printf prints 20. In the outermost block, i is declared as extern, so no storage space is allocated for it.
After compilation is over the linker resolves it to global variable i (since it is the only variable visible there).
So it prints i's value as 10.

17. main()
{
int *j;
{
int i=10;
j=&i;
}
printf("%d",*j);
}

Answer:
10

Explanation:
The variable i is a block level variable and the visibility is inside that block only. But the lifetime of i is
lifetime of the function so it lives upto the exit of main function. Since the i is still allocated space,
*j prints the value stored in i since j points i.

18. main()
{
int i=-1;
-i;
printf("i = %d, -i = %d \n",i,-i);
}

Answer:
i = -1, -i = 1

Explanation:
-i is executed and this execution doesn't affect the value of i. In printf first you just print the value of i.
After that the value of the expression -i = -(-1) is printed.

19. #include
main()
{
const int i=4;
float j;
j = ++i;
printf("%d %f", i,++j);
}

Answer:
Compiler error

Explanation:
i is a constant. you cannot change the value of constant

20. #include
main()
{
int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };
int *p,*q;
p=&a[2][2][2];
*q=***a;
printf("%d..%d",*p,*q);
}

Answer:
garbagevalue..1

Explanation:
p=&a[2][2][2] you declare only two 2D arrays. but you are trying to access the third 2D
(which you are not declared)
it will print garbage values. *q=***a starting address of a is assigned integer pointer.
now q is pointing to starting address of a.if you print *q meAnswer:it will print first
element of 3D array.

21. #include
main()
{
register i=5;
char j[]= "hello";
printf("%s %d",j,i);
}

Answer:
hello 5

Explanation:
if you declare i as register compiler will treat it as ordinary integer and it will take
integer value. i value may be stored either in register or in memory.

22. main()
{
int i=5,j=6,z;
printf("%d",i+++j);
}

Answer:
11

Explanation:
the expression i+++j is treated as (i++ + j)

Saturday 15 October 2011

Technical interview "C " Q & A

Predict the output or error(s) for the following:


1. void main()
{
int const * p=5;
printf("%d",++(*p));
}

Answer:
Compiler error: Cannot modify a constant value.
Explanation:
p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".

2. main()
{
char s[ ]="man";
int i;
for(i=0;s[ i ];i++)
printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
}

Answer:
mmmm
aaaa
nnnn
Explanation:
s[i], *(i+s), *(s+i), i[s] are all different ways of expressing the same idea. Generally array name is
the base address for that array. Here s is the base address. i is the index number/displacement from the
base address. So, indirecting it with * is same as s[i]. i[s] may be surprising. But in the case of C
it is same as s[i].

3. main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("I love U");
else
printf("I hate U");
}

Answer:
I hate U

Explanation:
For floating point numbers (float, double, long double) the values cannot be predicted exactly. Depending
on the number of bytes, the precession with of the value represented varies. Float takes 4 bytes and long
double takes 10 bytes. So float stores 0.9 with less precision than long double.
Rule of Thumb:
Never compare or at-least be cautious when using floating point numbers with relational operators (== , >, <, <=, >=,!= ) .

4. main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}

Answer:
5 4 3 2 1

Explanation:
When static storage class is given, it is initialized once. The change in the value of a static variable is
retained even between the function calls. Main is also treated like any other ordinary function, which can
be called recursively.

5. main()
{
int c[ ]={2.8,3.4,4,6.7,5};
int j,*p=c,*q=c;
for(j=0;j<5;j++) {
printf(" %d ",*c);
++q; }
for(j=0;j<5;j++){
printf(" %d ",*p);
++p; }
}

Answer:
2 2 2 2 2 2 3 4 6 5

Explanation:
Initially pointer c is assigned to both p and q. In the first loop, since only q is incremented and not c ,
the value 2 will be printed 5 times. In second loop p itself is incremented. So the values 2 3 4 6 5 will be printed.

6. main()
{
extern int i;
i=20;
printf("%d",i);
}

Answer:
Linker Error : Undefined symbol '_i'
Explanation:
extern storage class in the following declaration,
extern int i;
specifies to the compiler that the memory for i is allocated in some other program and that address will be
given to the current program at the time of linking. But linker finds that no other variable of name i is
available in any other program with memory space allocated for it. Hence a linker error has occurred .

7. main()
{
int i=-1,j=-1,k=0,l=2,m;
m=i++&&j++&&k++||l++;
printf("%d %d %d %d %d",i,j,k,l,m);
}

Answer:
0 0 1 3 1

Explanation :
Logical operations always give a result of 1 or 0 . And also the logical AND (&&) operator has higher priority
over the logical OR (||) operator. So the expression ‘i++ && j++ && k++’ is executed first. The result of this
expression is 0 (-1 && -1 && 0 = 0). Now the expression is 0 || 2 which evaluates to 1 (because OR operator
always gives 1 except for ‘0 || 0’ combination- for which it gives 0). So the value of m is 1. The values of
other variables are also incremented by 1.

8. main()
{
char *p;
printf("%d %d ",sizeof(*p),sizeof(p));
}

Answer:
1 2

Explanation:
The sizeof() operator gives the number of bytes taken by its operand. P is a character pointer, which needs one
byte for storing its value (a character). Hence sizeof(*p) gives a value of 1. Since it needs two bytes to store
the address of the character pointer sizeof(p) gives 2.

9. main()
{
int i=3;
switch(i)
{
default:printf("zero");
case 1: printf("one");
break;
case 2:printf("two");
break;
case 3: printf("three");
break;
}
}

Answer :
three

Explanation :
The default case can be placed anywhere inside the loop. It is executed only when all other cases doesn't match.

10. main()
{
printf("%x",-1<<4);
}

Answer:
fff0

Explanation :
-1 is internally represented as all 1's. When left shifted four times the least significant 4 bits are filled
with 0's.The %x format specifier specifies that the integer value be printed as a hexadecimal value.

11. main()
{
char string[]="Hello World";
display(string);
}
void display(char *string)
{
printf("%s",string);
}

Answer:
Compiler Error : Type mismatch in redeclaration of function display

Explanation :
In third line, when the function display is encountered, the compiler doesn't know anything about the function
display. It assumes the arguments and return types to be integers, (which is the default type). When it sees the
actual function display, the arguments and type contradicts with what it has assumed previously. Hence a compile
time error occurs.

12. main()
{
int c=- -2;
printf("c=%d",c);
}

Answer:
c=2;

Explanation:
Here unary minus (or negation) operator is used twice. Same maths rules applies, ie. minus * minus= plus.
Note:
However you cannot give like --2. Because -- operator can only be applied to variables as a decrement operator
(eg., i--). 2 is a constant and not a variable.

13. #define int char
main()
{
int i=65;
printf("sizeof(i)=%d",sizeof(i));
}

Answer:
sizeof(i)=1

Explanation:
Since the #define replaces the string int by the macro char

14. main()
{
int i=10;
i=!i>14;
Printf ("i=%d",i);
}

Answer:
i=0

Explanation:
In the expression !i>14 , NOT (!) operator has more precedence than ‘ >’ symbol. ! is a unary logical operator.
!i (!10) is 0 (not of true is false). 0>14 is false (zero).

#include
main()
{
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}

Answer:
77

Explanation:
p is pointing to character '\n'. str1 is pointing to character 'a' ++*p. "p is pointing to '\n' and that is
incremented by one." the ASCII value of '\n' is 10, which is then incremented to 11. The value of ++*p is 11.
++*str1, str1 is pointing to 'a' that is incremented by 1 and it becomes 'b'. ASCII value of 'b' is 98.
Now performing (11 + 98 – 32), we get 77("M");
So we get the output 77 :: "M" (Ascii is 77).

16. #include
main()
{
int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };
int *p,*q;
p=&a[2][2][2];
*q=***a;
printf("%d----%d",*p,*q);
}

Answer:
SomeGarbageValue---1

Explanation:
p=&a[2][2][2] you declare only two 2D arrays, but you are trying to access the third 2D(which you are not
declared) it will print garbage values. *q=***a starting address of a is assigned integer pointer. Now q
is pointing to starting address of a. If you print *q, it will print first element of 3D array.

17. #include
main()
{
struct xx
{
int x=3;
char name[]="hello";
};
struct xx *s;
printf("%d",s->x);
printf("%s",s->name);
}

Answer:
Compiler Error

Explanation:
You should not initialize variables in declaration

18. #include
main()
{
struct xx
{
int x;
struct yy
{
char s;
struct xx *p;
};
struct yy *q;
};
}

Answer:
Compiler Error

Explanation:
The structure yy is nested within structure xx. Hence, the elements are of yy are to be accessed through
the instance of structure xx, which needs an instance of yy to be known. If the instance is created after
defining the structure the compiler will not know about the instance relative to xx. Hence for nested
structure yy you have to declare member.

19. main()
{
printf("\nab");
printf("\bsi");
printf("\rha");
}

Answer:
hai

Explanation:
\n - newline
\b - backspace
\r - linefeed

20. main()
{
int i=5;
printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);
}

Answer:
45545

Explanation:
The arguments in a function call are pushed into the stack from left to right. The evaluation is by
popping out from the stack. and the evaluation is from right to left, hence the result.

21. #define square(x) x*x
main()
{
int i;
i = 64/square(4);
printf("%d",i);
}

Answer:
64

Explanation:
the macro call square(4) will substituted by 4*4 so the expression becomes i = 64/4*4 . Since / and *
has equal priority the expression will be evaluated as (64/4)*4 i.e. 16*4 = 64

22. main()
{
char *p="hai friends",*p1;
p1=p;
while(*p!='\0') ++*p++;
printf("%s %s",p,p1);
}

Answer:
ibj!gsjfoet

Explanation:
++*p++ will be parse in the given order
Ø *p that is value at the location currently pointed by p will be taken
Ø ++*p the retrieved value will be incremented
Ø when ; is encountered the location will be incremented that is p++ will be executed
Hence, in the while loop initial value pointed by p is ‘h’, which is changed to ‘i’ by executing ++*p
and pointer moves to point, ‘a’ which is similarly changed to ‘b’ and so on. Similarly blank space is
converted to ‘!’. Thus, we obtain value in p becomes “ibj!gsjfoet” and since p reaches ‘\0’ and p1 points
to p thus p1doesnot print anything.

23. #include
#define a 10
main()
{
#define a 50
printf("%d",a);
}

Answer:
50

Explanation:
The preprocessor directives can be redefined anywhere in the program. So the most recently assigned value will be taken.

24. #define clrscr() 100
main()
{
clrscr();
printf("%d\n",clrscr());
}

Answer:
100

Explanation:
Preprocessor executes as a seperate pass before the execution of the compiler. So textual replacement
of clrscr() to 100 occurs.The input program to compiler looks like this :
main()
{
100;
printf("%d\n",100);
}
Note:
100; is an executable statement but with no action. So it doesn't give any problem

25. main()
{
printf("%p",main);
}

Answer:
Some address will be printed.

Explanation:
Function names are just addresses (just like array names are addresses).
main() is also a function. So the address of function main will be printed. %p in printf specifies that
the argument is an address. They are printed as hexadecimal numbers.

Tough interview questions on EJB

  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 the application 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 a network 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.

Friday 7 October 2011

EJB interview questions

  1. What are the different kinds of enterprise beans? - Different kind of enterrise beans are Stateless session bean, Stateful session bean, Entity bean, Message-driven bean.
  2. What is Session Bean? - A session bean is a non-persistent object that implements some business logic running on the server. One way to think of a session object.
  3. What is Entity Bean? - The entity bean is used to represent data in the database. It provides an object-oriented interface to ____.
  4. What are the methods of Entity Bean? - An entity bean consists of 4 groups of methods, create methods.
  5. What is the difference between Container-Managed Persistent (CMP) bean and Bean-Managed Persistent(BMP) ? - Container-managed persistence (CMP) and bean-managed persistence (BMP). With CMP, the container manages the persistence of the entity bean.
  6. What are the callback methods in Entity beans? - Callback methods allows the container to notify the bean of events in its life cycle. The callback methods are defined in the javax.ejb.EntityBean interface.
  7. What is software architecture of EJB? - Session and Entity EJBs consist of 4 and 5 parts respectively, a remote interface.
  8. Can Entity Beans have no create() methods? - Yes. In some cases the data is inserted NOT using Java application,.
  9. What is bean managed transaction? - If a developer doesn’t want a Container to manage transactions, it’s possible to implement all database operations manually.
  10. What are transaction attributes? - The transaction attribute specifies how the Container must manage transactions for a method when a client invokes the method via the enterprise bean’s home or.
  11. What are transaction isolation levels in EJB? - Transaction_read_uncommitted, Transaction_read_committed, Transaction_repeatable_read.

Thursday 6 October 2011

Java Frequently Asked Questions

What is interface and its use?- Interface is similar to a class which may contain method’s signature only but not bodies and it is a formal set of method and constant declarations that must be defined by the class that implements it. Interfaces are useful for: a)Declaring methods that one or more classes are expected to implement b)Capturing similarities between unrelated classes without forcing a class relationship. c)Determining an object’s programming interface without revealing the actual body of the class.
What is an abstract class?- An abstract class is a class designed with implementation gaps for subclasses to fill in and is deliberately incomplete.
What is a cloneable interface and how many methods does it contain?- It is not having any method because it is a TAGGED or MARKER interface.
Can you have an inner class inside a method and what variables can you access?- Yes, we can have an inner class inside a method and final variables can be accessed.
What is multithreading and what are the methods for inter-thread communication and what is the class in which these methods are defined?- Multithreading is the mechanism in which more than one thread run independent of each other within the process. wait (), notify () and notifyAll() methods can be used for inter-thread communication and these methods are in Object class. wait() : When a thread executes a call to wait() method, it surrenders the object lock and enters into a waiting state. notify() or notifyAll() : To remove a thread from the waiting state, some other thread must make a call to notify() or notifyAll() method on the same object
What is the class and interface in java to create thread and which is the most advantageous method?- Thread class and Runnable interface can be used to create threads and using Runnable interface is the most advantageous method to create threads because we need not extend thread class here.

What are the states associated in the thread?- Thread contains ready, running, waiting and dead states.

What is synchronization?- Synchronization is the mechanism that ensures that only one thread is accessed the resources at a time.

When you will synchronize a piece of your code?- When you expect your code will be accessed by different threads and these threads may change a particular data causing data corruption.


What is deadlock?- When two threads are waiting each other and can’t precede the program is said to be deadlock.

What is daemon thread and which method is used to create the daemon thread?- Daemon thread is a low priority thread which runs intermittently in the back ground doing the garbage collection operation for the java runtime system. setDaemon method is used to create a daemon thread.

Are there any global variables in Java, which can be accessed by other part of your program?- No, it is not the main method in which you define variables. Global variables is not possible because concept of encapsulation is eliminated here.

What is an applet?- Applet is a dynamic and interactive program that runs inside a web page displayed by a java capable browser.

How does applet recognize the height and width?- Using getParameters() method.

When do you use codebase in applet?- When the applet class file is not in the same directory, codebase is used.

What is the lifecycle of an applet?- init() method - Can be called when an applet is first loaded start() method - Can be called each time an applet is started. paint() method - Can be called when the applet is minimized or maximized. stop() method - Can be used when the browser moves off the applet’s page. destroy() method - Can be called when the browser is finished with the applet.

How do you set security in applets?- using setSecurityManager() method

What is an event and what are the models available for event handling?- An event is an event object that describes a state of change in a source. In other words, event occurs when an action is generated, like pressing button, clicking mouse, selecting a list, etc. There are two types of models for handling events and they are: a) event-inheritance model and b) event-delegation model

What are the advantages of the model over the event-inheritance model?- The event-delegation model has two advantages over the event-inheritance model. They are: a)It enables event handling by objects other than the ones that generate the events. This allows a clean separation between a component’s design and its use. b)It performs much better in applications where many events are generated. This performance improvement is due to the fact that the event-delegation model does not have to be repeatedly process unhandled events as is the case of the event-inheritance.

What is source and listener?- source : A source is an object that generates an event. This occurs when the internal state of that object changes in some way. listener : A listener is an object that is notified when an event occurs. It has two major requirements. First, it must have been registered with one or more sources to receive notifications about specific types of events. Second, it must implement methods to receive and process these notifications.

What is adapter class?- An adapter class provides an empty implementation of all methods in an event listener interface. Adapter classes are useful when you want to receive and process only some of the events that are handled by a particular event listener interface. You can define a new class to act listener by extending one of the adapter classes and implementing only those events in which you are interested. For example, the MouseMotionAdapter class has two methods, mouseDragged()and mouseMoved(). The signatures of these empty are exactly as defined in the MouseMotionListener interface. If you are interested in only mouse drag events, then you could simply extend MouseMotionAdapter and implement mouseDragged() .

What is meant by controls and what are different types of controls in AWT?- Controls are components that allow a user to interact with your application and the AWT supports the following types of controls: Labels, Push Buttons, Check Boxes, Choice Lists, Lists, Scrollbars, Text Components. These controls are subclasses of Component.

What is a layout manager and what are different types of layout managers available in java AWT?- A layout manager is an object that is used to organize components in a container. The different layouts are available are FlowLayout, BorderLayout, CardLayout, GridLayout and GridBagLayout.

How are the elements of different layouts organized?- FlowLayout: The elements of a FlowLayout are organized in a top to bottom, left to right fashion. BorderLayout: The elements of a BorderLayout are organized at the borders (North, South, East and West) and the center of a container. CardLayout: The elements of a CardLayout are stacked, on top of the other, like a deck of cards. GridLayout: The elements of a GridLayout are of equal size and are laid out using the square of a grid. GridBagLayout: The elements of a GridBagLayout are organized according to a grid. However, the elements are of different size and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.

Which containers use a Border layout as their default layout?- Window, Frame and Dialog classes use a BorderLayout as their layout.

Monday 3 October 2011

Interview at IBM

A reader interviewed with IBM and sent the following questions in:
  1. I have a scale and 7 balls. 1 ball is heavier than all the rest. How do I determine the heaviest ball with only 3 possible weighing attempts?
  2. What is a linked list?
  3. Name an advantage of linked list over array?
  4. Name an advantage of array over linked list?
  5. Have you ever used threads?
  6. Should you protect the global data in threads? Why or why not?
  7. Have you ever interfaced with a database?
  8. Tell us about yourself.
  9. Questions about specific resume entries.
  10. Given two strings like x=”hello” and y=”open”, remove any character from string x which is also used in string y, thus making the result x=”hll”.

Sunday 2 October 2011

Electrical engineer interview questions

  1. What types of CMOS memories have you designed? What were their size? Speed? Configuration Process technology?
  2. What work have you done on full chip Clock and Power distribution? What process technology and budgets were used?
  3. What types of I/O have you designed? What were their size? Speed? Configuration? Voltage requirements? Process technology? What package was used and how did you model the package/system? What parasitic effects were considered?
  4. What types of high speed CMOS circuits have you designed?
  5. What transistor level design tools are you proficient with? What types of designs were they used on?
  6. What products have you designed which have entered high volume production?
  7. What was your role in the silicon evaluation/product ramp? What tools did you use?
  8. If not into production, how far did you follow the design and why did not you see it into production?

Saturday 1 October 2011

Electronic engineer interview questions

  1. What is D-FF?
  2. What is the basic difference between Latches and Flip flops?
  3. What is a multiplexer?
  4. How can you convert an SR Flip-flop to a JK Flip-flop?
  5. How can you convert an JK Flip-flop to a D Flip-flop?
  6. What is Race-around problem? How can you rectify it?
  7. Which semiconductor device is used as a voltage regulator and why?
  8. Explain an ideal voltage source?
  9. Explain zener breakdown and avalanche breakdown?
  10. What are the different types of filters?
  11. What is the need of filtering ideal response of filters and actual response of filters?
  12. What is sampling theorem?
  13. What is impulse response?
  14. Explain the advantages and disadvantages of FIR filters compared to IIR counterparts.
  15. What is CMRR?
  16. Explain half-duplex and full-duplex communication?
  17. Which range of signals is used for terrestrial transmission?
  18. Why is there need for modulation?
  19. Which type of modulation is used in TV transmission?
  20. Why we use vestigial side band (VSB-C3F) transmission for picture?
  21. When transmitting digital signals is it necessary to transmit some harmonics in addition to fundamental frequency?
  22. For asynchronous transmission, is it necessary to supply some synchronizing pulses additionally or to supply or to supply start and stop bit?
  23. BPFSK is more efficient than BFSK in presence of noise. Why?
  24. What is meant by pre-emphasis and de-emphasis?
  25. Explain 3 dB cutoff frequency? Why is it 3 dB, not 1 dB?
  26. Explain ASCII, EBCDIC?

Search here for "Freshers Jobs"