Win a copy of Microservices Testing (Live Project) this week in the Spring forum!

satya rao

Greenhorn
+ Follow
since Feb 14, 2002
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 satya rao

Valentine... I am really sorry....
Thanks a lot
-Satya
20 years ago
I am very glad to inform you all that I have passed SCJP yesterday scoring 93%. Thanks for every one on this board. I just followed the discussions passively here. Especially thanks to Valentine. I would suggest people to try to pass her mock exam. I felt if one could pass it then that's it ... any body can pass SCJP !!! I am planning to take Web developer certification as quickly as possible.
Thanks,
Satya
-------
Sun Certified Programmer for Java 2 Platform
20 years ago
Valentine.. Thanks a lot for your boost up!! Keep up your good work!!! I really appreciate it.
Hi Valentin,
As you mentioned your mock exam was really tough. Thanks for putting time into that for people like me. I scored only 57.1%(failed) in that test. What would you advise me about taking exam on this coming friday? So far, I went through several mock exams on the net and was able to score high. Then I thought I am ready for the exam and scheduled it. I appreciate your help..
Thanks,
Satya
Thanks Brian and Val for your responses.
Can anybody please look at the following code and explain me why it is printing "exception, finally, 5"?
public class Test {
public static void main(String[] str) {
System.out.println(new Test().method1());
}
int method1() {
int i = 0;
try {
method2();
System.out.println("int try");
return i;
}
catch (Exception e)
{
System.out.print("exception, ");
i = 5;
return i;
}
finally { System.out.print("finally, "); i = 2;}

}
void method2() { throw new NullPointerException(); }
}

I was under the impression that it would print "exception, finally, 2" as the finally block is executed at the end just before returning.
I meant, when synchorized method of an object is executed by a thread, another thread can not change the instance values(status) of that object.
Valentin Crettaz,
I changed it.
BTW, I have seen you so many discussion before. Can you throw some light on my response to this question?
If you put your try-catch block with Thread.sleep(..) outside for-loop, you can get your desired output i.e., 0-9 and then 0-9.
The following is the status of the threads as the time progresses:
Thread1 Thread2
----------------------------------
ready ......................
non-runnable(sleep)......... ready
............................ non-runnable
output(after elapsed time)..
non-runnable(sleep)......... output
This is the reason why, you are not getting your desired output. What I understood, if a thread is in non-runnable state, then other waiting threads will get a chance to be executed. Also, synchronized method cannot change the status of the object. In this situation, it is just printing a value, but not changing the status of the object.
I am also a beginner. Please correct me if I am wrong.