Professional Documents
Culture Documents
answers
What are callable collections in Java ?
A callable collection is an interface whose implementers define a
single method with no arguments. The Callable interface resembles
Run able, as both are designed for the classes which potentially
executed with another thread. The difference is Run able cannot
return value and throw an exception.
How to make a method thread safe without using synchronized
keyword ?
By using a flag to determine that the method is in use by a
running thread.
Ex: Class A{
private boolean inUse = false;
public methodA(){
if(!inUse){
inUse = true;
...
...
...
inUse = false;
}
}
You can also use built-in
synchronizers. java.util.concurrent.locks.ReentrantLock has the
same functionality as the lock you access when
using synchronized blocks and methods, and it is even more
powerful.
main()
{
int n, i = 3, count, c;
scanf("%d",&n);
if ( n >= 1 )
printf("2\n");
if ( i%c == 0 )
break;
if ( c == i )
{
printf("%d\n",i);
count++;
}
i++;
}
return 0;
int num,r,reverse=0,temp;
scanf("%d",&num);
while(num){
r=num%10;
reverse=reverse*10+r;
num=num/10;
return 0;
}
Temp = num;
if (temp == reverse)
else
5.
m1=(y2-y1)/(x2-x1);
m2=(y3-y2)/(x3-x2);
if(m1==m2)
{
printf("3 points are on same line")
}
else
{
{
While(++j!=k)
{
Printf(%c,str[j]);
}
Printf( );
}
}
}
Printf(\n);
}
as platform dependent.
In the following code, how many times does the foo() is called ?
for(i = 1; i<=100;i++)
for(j= i;j<=100;j++)
foo();
Answer 5050 times.
Bcoz it will follow the pattern : i
1 to 100 = 100times
2 to 100 = 99times
3 to 100
4 to 100
5 to 100
6 to 100
..
99
99 to 100
100
100