Tuesday, June 29, 2010

Tell me about yourself?

Start with your current designation and educational qualifications. This question is to find out about why you are right for this job. Your answer should be a quick summary of your best qualities and why they are relevant for this position in their organization. Once you have clear picture of your answer, write it down and practice saying it ahead of time. This will make your answer come out more relaxed and natural. Dont answer about your personal information like your hobbies, interests etc"

Saturday, June 26, 2010

Object Class Methods

Why wait() and notify() are used only for threads, why not to objects?

The wait() and notify() methods are object-specific. The wait() method suspends the current thread of execution, and tells the object to keep track of the suspended thread. The notify() method tells the object to wake up the suspended threads that it is currently keeping track of. Since wait() and notify() are object specific, they must be used within code that is synchronized on the object in question.

It is also important to use state variables when using wait() and notify(), as threads can be woken up by conditions other than notify().


2) Because in object we dont want our result in syncronized way but in case of threads the result should be syncronized so we use wait and notify.


3) In threads for interprocess communication between threads is done using wait() notify()
methods because to avoid polling problem. But in case of objects interprocessing communication between objects is done automatically while processing program in JVM.


4) wait() and notify() are NOT needed for objects statements/method calls within the same thread because execution on objects running in the same thread will run one at a time and not overlap.

If execution happens in different threads then there is a chance for them to overlap and the need for mechanism to manage concurrent execution arise.

Mutithreading in JAVA

How synchronization can be done for multithreading environment without using the "synchronized" keyword?

Use java.util.concurrent package

Lock mylock;
try
{
mylock.lock();
//critical section
}
finally{
mylock.unlock();
}

Also:
try a lock with a timeout trylock()
wait for some condition: condition.await()
these could come handy to avoid the deadlock situations.


Use java.util.concurrent package

Lock mylock;
try
{
mylock.lock();
//critical section
}
finally{
mylock.unlock();
}

Also:
try a lock with a timeout trylock()
wait for some condition: condition.await()
these could come handy to avoid the deadlock situations.


This can be achived using the volatile keyword this will be more useful. When multiple threads using the same variable .

Arrays/Linked List

Memory:
When you create an array you allocate all the memory while initializing the array, so if you had an array of 1000 Objects, you'd allocate space to hold 1000 object references as soon as you initialize the array.

LinkedList on the other hand extends dynamically as the objects are added to the linked list.

Accessing Elements:
Arrays are useful if you are going to access elements using the index. if you need to access the 100th element you can directly access it by a[100].

To access 100th element in a LinkedList you'll have to traverse 99 elements to reach the 100th element.

LinkedList can handle addition/deletion of elements better then arrays and that's one of the most powerful feature of LL over arrays.

Adding/Inserting Elements:
Array is fixed size; to add a number of elements greater then the size of the array you'd have to copy the array into a new bigger array.

To insert an element in the middle of an array all the elements after the inserted element would have to moved up one index.

LinkedList can grow dynamically.

Deleting Elements:
To delete an element from Array you'd have to move down all the elements after the deleted element.

LinkedList elements can be deleted dynamically.

To summarize, LinkedList can handle manipulation of data structure much better and efficiently manage memory but arrays have better accessibility when accessing elements by index.
Search and Sort would be similar performance on both.

Accenture 10 C Interview Questions

1)Write a C program to find a peculiar two digit number which is three times the sum of its digits.

2) Bacteria are known to multiply very rapidly. If a certain container contains just one bacterium on the first day and there are twice as many on the next day. In this manner the number of bacteria in the container doubles itself everyday. Assuming that the container would be full on the 10th day with 13,312 bacteria, find the number of bacteria that was initially in the container on the first day.

3) Calculate the factorial of a number recursively. From that calculate the value of COS(X) = 1 - X2/2! + X4 /4! - X6/ 6! +…….

4) A number of “Cats” got together and decided to kill between them 999919 mice. Every cat killed equal number of “mice”. Write a program to find number of cats.

5) Consider the following number 45*45=2025; 20+25=45.Write a program to generate number between 32 and 99 that satisfies the above property.

6) Rita has a money pouch containing Rs.700. There are equal number of 25 paise coins, 50 paise and one rupee coins. Write a C program to find how many of each are there?

7) Calculate the factorial of a number recursively and from that calculate the value of ex=1+ (X1/1!) + (X2 /2!) + (X3/3!) + ……….

8) There are some goats and ducks in a farm. There are 60 eyes and 86 foot in total. Write a program to find number of goats and ducks in the farm.

9) Write a C program to find a three digit number which is greater than the aggregate of its third, tenth and the twelfth parts by 58.

10) Write a C program to find a two digit number, the second digit of which is smaller than its first digit by 4, and if the number was divided by the digit’s sum, the quotient would be 7.

how can be used "BIOS.h" to interact with bios in c&c++ language

by using FAR And NEAR pointer we can access bios and memory portions effectively.


program in C to find the 2 digit number which is 3 times its sum of its digits

1) main()
{
int num,sum,i;
for(num=10;num<100;num++)
{
if(num==3*(num%10+num/10))
{
printf("%d",num);
}
}
}



2)
#include
void main()
{
int i a c;
for(i 10;i< 99;i++)
{a i;
c i 10;
a a/10;
if(i (3*(c+a)))
{
printf(" d" i);
getch();
}
}
getch();
}


3)

#include
void main()
{
int i t r s x;
clrscr();

for(i 10;i< 99;i++)
{
s 0;
t i;
while(t! 0)
{
r t 10;
t t/10;
s s+r;
}
x (3*s);
if(x i)
printf(" dn" i);
}
getch();
}

How can a cake(circular) be cut into 8 pieces by making just 3 cuts?

Answer:

first cut the cake into 2 circular pieces by cutting along the circumference then 2 cuts. One horizontal and other vertical
8 pieces we will get!

Make two cuts from the top and the other at right angles to the two cuts.

Make two cuts to divide the cake into 4 (cutting on the diameter of a circular cake the cuts perpendicular to each other). Now place the 4 sectors of the cake one over the other. Make a cut such that the cut goes throw the centre cutting each of the cake sectors into half. So now we have done 3 cuts. Each sector is cut into two so 4*2 8.




How to do the preparation for an aptitude

Refer:

"Quantative aptitude" for practice in Mathematics & "verbal-non verbal reasoning" author R.S aggarwal.

Quantitative Aptitude and Verbal & Non-Verbal Reasoning are best books....

Aptitude Questions -- 100 Bananas

Question: A man ate 100 bananas in five days, each day eating 6 more than the previous day. How many bananas did he eat on the first day?


Ans: he ate 'x' bananas 1st day...then next four days he eats as following...
x+6, x+12, x+18 and x+24
hence, by summing all these we get,
x+x+6+x+12+x+18+x+24=100
=> 5x+60=100
=> 5x=40
=> x=8
hence, a man ate '8' bananas on 1st day.