ram shah

Greenhorn
+ Follow
since Jun 02, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by ram shah

Thank for your comments Ahmed...but, I have few more doubts

(1) how thread "one" is executing before thread "three" when priority of thread "three" is greatre than priority of thread "one".

(2) If I set the priorities as below,
t1.setPriority(9)
t2.setPriority(5)
t3.setPriority(5)
How can I modify the if statement so that if the priority of the thread is 5, it yields to the other thread with same priority.



The result I got is as follows:

Pr of t1 = 5,Pr of t2 = 5,Pr of t3 = 5
Pr of t1 = 3,Pr of t2 = 6,Pr of t3 = 7
inside no args run
Run by one
�.
Run by one
Inside if block
inside no args run
Run by three
�.
Run by three
inside no args run
Run by two
�.
Run by two
Final run by main


Though t3 has max priority, t1 is run first.
value for NORM_PRORITY is 5, but I haven't given any Thread a priority of 5. Then how can the if loop execute?

Can anybody pls explain
source : http://www.javabeat.net/javabeat/scjp5/mocks/MockExam02.php



My doubt is howcome it prints "pcp"? I thought it will be "pc".
2 >> -1

Bit pattern of 2 = 00000010
Bit pattern of -1 = 11111111

If the shift distance value is greater than 32, the least five digits are taken as the shift distance. Here, the least five digits of the bit pattern of -1 is taken as the shift distance. Therefore, the shift distance becomes 31 (11111).

So, 2 >> 31 = 0.

Hope you get it!!
I'll try to explain...



In line 6, "r" is set to value X. In line 10,Case X is executed, which sets "r" to C.Since, there is no break statement, all other cases are also executed.In line 11, as "r.ordinal()" returns 5, z is incremented to 7.
In line 14, z is again incremented by 1. value of z is now 8. In line 16, the while condition is evaluated and found to be false.So, the execution comes out of the loop and value of z is printed as 8.

Somebody please correct me if I'm wrong.
Thanks for your reply...

But, could you pls explain how the output is 4 when line 1 is removed?
This from self test given in K & B book chapter 3.

code
-------------------------------------------------------
class Dims{
public static void main(String[] args){
int [] [] a = {{1,2, }, {3,4}};
int [] b = (int [])a[1];
Object o1 = a;
int [] [] a2 = (int [] [])o1;
int [] b2 = (int []) o1; // Line 1
System.out.println(b[1]);
}}
-------------------------------------------------------

The answer is a class cast exception thrown at line 1. If line 1 is removed the output is 4. Can somebody explain how?
I got this Qn from the site www.examulator.com

code
--------------------------------
interface Skeleton{
public char getSize(int iSize);

}


public class Huskisson implements Skeleton{
int iSize=99;
public static void main(String argv[]){
new Huskisson();
}
Huskisson(){
int iSize=1;
System.out.println(getSize(iSize));

}

public int getSize(int iSize){
return iSize;
}
}
------------------------------------------
The output is Compiler Error. I thought the output will be compilation with output 1.
Can somebody explain?
I got this Qn from the site www.examulator.com

code
--------------------------------
interface Skeleton{
public char getSize(int iSize);

}


public class Huskisson implements Skeleton{
int iSize=99;
public static void main(String argv[]){
new Huskisson();
}
Huskisson(){
int iSize=1;
System.out.println(getSize(iSize));

}

public int getSize(int iSize){
return iSize;
}
}
------------------------------------------
The output is Compiler Error. I thought the output will be 1.
Can somebody explain?
henry,
in the rarlier discussion only the left hand operand was negative. here, both operands are negative. I've doubt regarding this situation only. How do we right shift or left shift a number(positive or negative) by a larger negative number?
int[] a, b[];
In the above code snippet, a is a single dimensional array & b is 2 dimensional array....Am I right?

Pls correct me if I'm wrong.
Pls explain the execution of the question given below....


code
--------------------------------------

public class Test{
public static void main(String args[]){
int a = -8;
int b = -33;
a>>>=b;
System.out.println(a);
}}
-----------------------------------------

How do we evaluate the problem when the shift distance is a negative number?
Hi,

Class is just a template to declare variable and methods. Any code other than this should go inside a block (say, static block, method body etc.).

Correct me if I'm wrong...
I think the output should be in the order,
d,c,b,h,g,l as i is incremented and j is decremented.

Am i correct? I'm at work. so, can't compile & check.