Jeff Sky

Greenhorn
+ Follow
since Feb 15, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Jeff Sky

I just java certification, want to learn jave serverlet, where to begin?
thanks!
23 years ago

Except for RuntimeException, Error and their subclass, all exceptions are called checked exceptions.
the compiler ensures that if a a method can throw a checked exception , derectly or indirectly, the the method must explicitly deal with it.
the method must either cathch the cxeption and take the appropriate acton, or pass on the exception to its caller.
------------------
Jeff
hi Manfred:
I know I am confused with the basic concept of thread here!
Does it mean, if you create a instance , then the instance call call start() method many times, it means lauch many thread, but every thread exist for just this instance , so they do not need use static variable, just instance variable.
so they use the same varible v!
right?
thanks!

Originally posted by Manfred Leonhardt:
Hi Jeff,
Pravin's second reply is right on the money! You must not associate threads with instances. One instance can launch many threads ... Therefore the example doesn't need any variables to be static to lead to the correct answers. The example assumes only on instance of class cQ7ed5.
Regards,
Manfred.



------------------
Jeff

1. String s1 = "She was dancing widdershins";
2. String s2 = s1;
3. s1 += "upon the shore";
4. if (s1.equals(s2))
5. System.out.println("They match");
6. else
System.out.println("not match");
wish it help to understand the String object!
sorry, I mean k.v . it is not static variable!
------------------
Jeff
hi, I am confused here, is the j.v shared by other instance, v is not static variable, could you explain it?
thanks!
------------------
Jeff
/* Given the following code, which statements concerning the
objects referenced through the memeber variables i, j and k are true,
given that any thread may call the methods a, b and c at any time?
*/
class Counter
{ int v=0;
synchronized void inc(){v++;}
synchronized void dec(){ v--;}
}
public class cQ7ed5
{
Counter i;
Counter j;
Counter k;

public synchronized void a()
{
i.inc();
System.out.println("a");
i.dec();
}
public synchronized void b()
{
i.inc();j.inc();k.inc();
System.out.println("b");
i.dec();j.dec();k.dec();
}
public void c()
{
k.inc();
System.out.println("c");
k.dec();
}
}
/* 1 i.v is guaranteed always to be 0 or1
2 j.v is guaranteed always to be 0 or 1
3 k.v is guaranteed always to be 0 or 1
etc
*/
the answer is 1, 2, Could somebody explain it more clearly and write a program to run it?
thanks!
String s1,s2,s3,s4;
String s1="hello";
String s2=s1;
String s3 =s2+"pal";
String s4=s3;
how many String object are created? answer is 3, why?
------------------
Jeff