Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!

Lohit Hosur

Greenhorn
+ Follow
since Oct 29, 2005
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 Lohit Hosur

Hi All,

For the following code, the output is: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9

public class Multiple extends Thread {

int num=0; //.....................line 2

public static void main(String args[]) throws InterruptedException {
Multiple t1=new Multiple();
Multiple t2=new Multiple();
t1.start();
t2.start();
}

public void run() {
while(num<=9) {
synchronized(this) {
System.out.print(num+" ");
num++;
}
}

}

}

--------------------------------------------------------------------------

But when I change the variable 'num' to static. This is what I get:
0 1 2 3 4 5 6 7 8 9

--------------------------------------------------------------------------

So, my question is, what is the effect of making a variable static on threads?

Thanks in advance
Hi All,
I'm not able to download the servlet spec at the link given in this site.
http://java.sun.com/products/servlet/download.html

Can anyone tell whether there are other urls for this?
Can anyone mail it to me? My mail is lohit.hosur@gmail.com.
Pls help me.

Thanks,
Lohit
Hi,
This is wrt to Kathy Sierra & Bert Bates book. In chapter 5, page No. 25, it says:
"Constructors can use any access modifier, including private. (A private
constructor means only code within the class itself can instantiate an object of that type, so if the private-constructor class wants to allow an instance of the class to be used, the class must provide a static method or variable that allows access to an instance created from within the class.)"

Well, I understood that point except the last part:
".................if the private-constructor class wants to allow an instance of the class to be used, the class must provide a static method or variable that allows access to an instance created from within the class."

can anyone explain this?

Thanks,
Lohit
Hi,
I wanted to know the significance of declaring variables within a curly braces. Like this:
class Xyz {

int x;

{
int x=1;
}

}

What else can be written inside a pair of curlr braces?
And what happens if we put static, like this:
static
{

}
Also tell me any helpful links available for this in javaranch.
Pls, help me.

Thanks,
Lohit