Farhan Tariq

Ranch Hand
+ Follow
since May 14, 2001
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
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Farhan Tariq

Hi guys!
I agree with Jon and Thomas. They provide good reason. I have another doubt about this type that whether or not the impact of modifiers(public, protected, private) of enclosing method, occurs on the anonymous class. e.g if we have a method "private void amethod(){}" and we have an anonymous classin it , so is there any impact of the private modifier of the enclosing method, means when we change that modifier to public or protected.
Regards
Farhan
Hi Hassan!
I think you shuold consult it from another books such as "Exam Cram" by Brogden, Khlid Azim Mughal's book about certification of Java2 or third choice is book by "Simon Roberts, Philip Heller etc.". Theez books are good and way of explanation is brilliant. I think your problem will be solved by one of these.
Regards
Farhan
Thanx Rick!
But tell me what is essay exam you said. Is it kind a theoratical exam or based on the assignment we did.
Regards
Farhan
Hi ranchers!
I have done my SCJP2 and now i wanna do SCJD too. guide me how can it be easy for me. How is the process of certification and how much money i need to do this. Whether or not there is any assignment too?
Regards
Farhan
What modifiers we can use with anonymous classes:
A. public
B. private
C. protected
D. abstract
I don't know about anonymous classes much please help me.
Regards
Farhan
Hi Peli!
You have to clear your mind about inner outer try blocks. If exception occured in outer try block the catch block of outer will be in consideration and skip the whole inner block even inner finally too. So in your program first the value of i = 0, that raises exception because of "0%3". So outer catch block starts execution and increment 3 in i, and then finally increment in i too after wards when loop again starts the value of i = 5 because one loop increment too.
Now 5%3 != 0 so no exception raised then 5%3 != 1 too so skip this too and print the value of i to console, which is 5.
Then finally of inner class executes which increment in i and outer finally too now i = 7 and last increment through the loop so again the loop starts with the value of i = 8.
first if skip then second if skip and print 8. Next time i will be 11 so loop break. And you have 5 and 8 printed on your console window.
Now try to think about other reasons in this manner and if still having difficulty, try to print the value of i after each line so you can understand the behavior of try structure.
Regards
Farhan
Hi Ranchers!
I'm really confused about the J.Tips mock exam because some people said that it's excellent. What I found is too heavy. I don't think that anyone ever got above 44 lines of code to follow in SCJP2 because it's impossible to select the option in 2 minutes. It's embarasing me to follow the code and watch each line of code in only 2 minutes. I think that's a crap and person who wanna SCJP2 might feel uncomfortable solving this mock exam because there is no strategy in it.
What u people think about it. Whether it is still a good Mock Exam havind these discrepencies and advise to attemt it or not.
Plz guide me
Regards
Farhan
Hi yasir!
That's why I select option no 1 for the first question, because two threads can't share simultaneously one synchronized method unless they are part of ThreadGroup and that ThreadGroup acquires the lock. There is no point of getting lock by one thread and releasing lock by wait().
Regards
Farhan
Hi Yasir!
Yeah I think I can tell u the reason. First thing, u did'nt synchronized the method getlocks(). So it is possible that more than one threads enter into this method. In the program first synchronized statement locks the object "a" which is the first parameter to method. So there is lock on object and if you call method with same order you can't get the execution.
wacth this:
suppose two objects
-------------------
Object A, B
getLocks(A,B) //A gets lock due to Synchronized(A)
so B is free and call to getlocks as
getLocks(B,A) //B gets lock due to Synchronized(A) which is actually synchronized(B), start execution for both because synchronization takes place on objects not the parameter no.
Hope this clear u
Regards
Farhan
Hi Kanchan!
Your program is preety good example of interrupt().
The actual process occured like follows:
1. In main() sleepyThread created and started.
2. Execution starts in run() method print "Sleeping..." and then sleep for 1000 seconds.
3. While in main(), The Main Thread sleeps for 500 millisecs and then interrupts the sleepyThread which cause sleepyThread to throw InterruptedException.
4. So sleepyThread throw exception which caught and then afterwards "interrupted...." print, because this run structure is in while loop which always true so loop starts again print "Sleeping....".
5. While in main thread sleep(500) takes place.
6. after printing in sleepyThread sleep(1000*1000) takes place again which again interrupted by main thread as "sleepyThread.interrupt()" so again exception caught and then print message "interrupted..." and then again loop starts and print "Sleeping...".
7. main thread ends execution.
8. sleepThread sleeps for 1000 seconds which is not interrupted by main thread anymore so for 1000 seconds program stops and then print "Sleeping..." again.
I think you follow the execution path. Now come to your second question.


Another question: What is the difference b/w wait(), yield() & sleep()? In which of the 3 cases, the thread releases the monitor?


The answer is :
1. wiat() takes parameters as milliseconds or milliseconds and nanosecs. It results the thread to stop execution and go to waiting state but release it's resources and locks.
2. While sleep() takes same type of parameters same thing that it stop the execution of thread and send it to waiting pool but does'nt release resources or lock.
3. Yield() is different that this results for a thread to go to ready state from running state and allow other threads, which have the same priority as the thread which start yield() method, to enter in running state.
I think all above points clear to you
Tell me if i'm wrong
Regards
Farhan
Hello Ranchers!!
I think the question is vague or incomplete:

is it true or false ?
Any class that includes a finalize method is not necessary
to invoke super class�s finalize() method.

The above state tell us it is not necessary to invoke super class' finalize() method is "True" because it did'nt state that to free the memory or something else. So in current situation if we don't want to free the memory and use finalize() method unnecessarily, then the answer is true but if we want to free some memory or use finalization process then false because then we want super finalize to call.
Regards "Logic is better than marks"
Farhan
hi Thomas!
I think u miss the point in question. The point asked is "Which one of these methods cause the object referenced by s to be changed", so we are not changing the actual object value but change in the reference.
Regards
Farhan
Hi Srinivasan!!
You r right because use of Math class is just as some functions or work perform on our values. So Math class is Mutable because Variable say this to methods of Math class, "hey! do this to my value" , "hey! do that to my value" (Haa Haa Haa Haa explanation joke). The main purpose of Math class is the format of given value (means to change the value) whether its abs(), round(), sin(), cos() etc.
I hope u clear (crystal)
Regards
Farhan
Thanx Ajith.
It really took off the burdon
Regards
Farhan
Hi Axel again(haa haa)!!
There is no question about compilation because compilation only check the syntax and possibility not the "result".
Your question is very simple because it relates to "Forward Referencing". Variables whether they r static or non-static get user given value at their execution time. So j is intialized but still not get the execution of j=100;. So every time you attemt to do so, value 0 will be printed. Because at peek() JVM don't know what is the value assigned to j which comes later.
Regards
Farhan