sandeep jaiswal

Greenhorn
+ Follow
since Nov 30, 2006
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 sandeep jaiswal

Thanks a lot.
That was indeed, put lots of light:
Now I can Go ahead in some direction in search of more on this
Thanks a lot for your reply.

I know nothing is guaranteed when in comes to thread.
But my query is :

If no one calls Notify, No interrupt() then in what basis this will wake itself.
Any algorithms placed in?
Hi,
Can any body tell me what happens to the thread, who goes to waiting state because of wait() call, and never get a notification because no one calls notify() or notifyAll()??

Thanks
Sandeep Jaiswal
FAA Agree with Steve

Hi Hari,
Hope you have got by the time, if its yours Assigmnt.

In case its not :
Then here it is ...
---------------
public class EvenOddGenTest {

/**
* @param args
*/
public static void main(String[] args) {

NumberGenerator numGenerator = new NumberGenerator();

OddGenerator oddGen = new OddGenerator(numGenerator);
EvenGenerator evenGen = new EvenGenerator(numGenerator);

oddGen.start();
evenGen.start();

}

}
------------------

public class OddGenerator extends Thread {

public NumberGenerator numGen;

public OddGenerator(NumberGenerator numberGen) {
this.numGen = numberGen;
}

public void run() {
int i = 1;
while (i <= 9) {

numGen.printOdd(i);
i = i + 2;
}
}

}

----

public class EvenGenerator extends Thread {

public NumberGenerator numGen;

public EvenGenerator(NumberGenerator numberGen) {
this.numGen = numberGen;
}

public void run() {
int i = 2;
while (i <= 10) {
numGen.printEven(i);
i = i + 2;
}
}
}
------


public class NumberGenerator {

boolean oddPrinted = false;

public synchronized void printOdd(int number) {

while (oddPrinted == true) {
try {
wait();

} catch (InterruptedException e) {

}
}

System.out.println("NumberGenerator.printOdd() " + number);
oddPrinted = true;
notifyAll();

}

public synchronized void printEven(int number) {
while (oddPrinted == false) {
try {
wait();

} catch (InterruptedException e) {

}
}

oddPrinted = false;
System.out.println("NumberGenerator.printEven() " + number);
notifyAll();
}
}

--------
Enjoy....

mohitkumar gupta wrote:

KB book
118



upcasting (casting up the inheritance tree to a more general
type) works implicitly (i.e., you don't have to type in the cast) because when you
upcast you're implicitly restricting the number of methods you can invoke, as
opposed to downcasting, which implies that later on, you might want to invoke a
more specific method





1.what's the use of upcasting ?

2.Here d is upcasted to Animal a1 .But,get() method of Dog can still be called using d.Then
what does "when you upcast you're implicitly restricting the number of methods you can invoke" means ?




[SANDEEP]

To answer Your 1st question, use of up casting:
Qus: Y up casting exist in JAVA?
Ans: To achieve run time polymorphism.

Que: Whats that?
Ans: Decide which class's method going to be called actually at runtime.

Que: How do you achieve that?
And:

Best use can be described if you understand observer pattern...
Here is a best link on the NET.

http://java-x.blogspot.com/2007/01/implementing-observer-pattern-in-java.html


Chapter closed

Jai Raam Ji ki