Alokesh Phukan

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

Recent posts by Alokesh Phukan

Just to add to what Kaspar said here is what the JLS(12.6.1) has to say
"Because of the way that an object progresses from the unfinalized state through the finalizable state to the finalized state, the finalize method is never automatically invoked more than once by a Java virtual machine for each object, even if the object is again made reachable after it has been finalized.
Explicit invocation of a finalizer ignores the current state of the object and does not change the state of the object from unfinalized or finalizable to finalized."
-Alokesh
Here is some info from JLS 5.2 which adds to what Jane has said.
"In addition, a narrowing primitive conversion may be used if all of the following conditions are satisfied:
1. The expression is a constant expression of type byte, short, char or int.
2. The type of the variable is byte, short, or char.
3. The value of the expression (which is known at compile time, because it is a constant expression) is representable in the type of the variable."
-Alokesh
I guess Lusha meant that the jvm calls the finalise method once.
To quote from JLS 12.6.1
"After an object has been finalized, no further action is taken until the automatic storage management determines that it is unreachable. Because of the way that an object progresses from the unfinalized state through the finalizable state to the finalized state, the finalize method is never automatically invoked more than once by a Java virtual machine for each object, even if the object is again made reachable after it has been finalized."
Alokesh
'\u000A' is actually the unicode value for linefeed. And it is an error if either a linefeed or a carriage return('\u000d') appears after the first ' and before a second ' in a char literal.
Please refer to JLS 3.4 & 3.5 for understanding the special treatment by the compiler for unicode escape sequences.
- Alokesh

Originally posted by Vanitha Sugumaran:
Thanks for your reply.
I understand, this will cause error,
char a = '\u000A';
what is happening when we comment the line that has unicode value?
Vanitha.


Finally got the software today. Guess that teaches me to not trust PSU banks to get the job done quickly.
Thanks for the prompt replies from you & your sales people.(god knows I was getting kind of desperate!!)
There is no method named InheritanceTest() taking char as argument in the class Process. So there is no dynamic lookup(needs method to be defined in both subclass & Baseclass). And the invocation of the method taking int in class Process takes place printing 'S' instead of 'R' as you expected.

Originally posted by Lakshmi Manikantan:
[B][/B]


Is there anyone in India(Delhi) who is using jqplus ? Maybe we can work out some deal. I have actually ordered for the software 3 weeks back but I'm afraid that it will (if at all?) not reach me in time. I hoping to give my exam next week.
Alokesh
Whatever happened to childhood and teens nowadays? God knows I had a ball in mine. Really feel sorry for all of you youngest "x's" and "y's".
Maybe I would pray for you all(though I'm leaning towards atheism right now)!!
23 years ago
You can always disconnect after the applet is loaded. There is no time limit to complete the test so you can take it at your own time. The test is quite long however(171 questions) so you can take around 3 normal exams with it(have to keep the applet running all the time of course!)
Great score!!
Used to follow your posts at the Ranch. (Actually not that surprised by your score)
Good luck for your future!!
23 years ago
The value of a after the first assignment is
1. int a = '1';// int value of char'1' =49
2. char b ='2';
3. a += b;// b promotes to an int i.e 50 so a = 99
4. System.out.print("a="+a);// prints 99
5. System.out.print(" b="+b++);// toString() called on char b=2
// post increment operator will affect later
Interestingly after step 2. where it is promoted to an int the value of reference b remains at '2' due to an implicit cast back to char. Apparantly that is a feature of the += ,-+ and other similar operators.
Thanks Dave, Annie you really cleared things up for me !
However if an option in a question states that wait() can only be called from synchronized code would that be valid ? Or as you explained it should be specified that the thread that calls wait() would have to be the owner of the object lock ?.
Just want to be sure that there aren't any general ambigous statements in the real exam !

Thanks Trevor, Denis for replying. I sort of had came to the same reasoning as you. But here is a question from Raimondas's mock that seems to suggest that wait() need not be from synchronized code . I tried compiling it and it worked fine.
Q 34.
class�Test�{
����������public�static�void�main(String[]�args)�{
��������������Test�t�=�new�Test();
��������������t.sMethod();
����������}
����������public�synchronized�void�sMethod()�{
��������������method();
����������}
����������private�void�method()�{
��������������try�{
������������������wait(10);
��������������}�catch(InterruptedException�e)�{�}
����������}
������}
1. Code compiles but IllegalMonitorStateException is thrown at runtime.
��2. Code does not compile, wait() must be called from synchronized block or method.
��3. Code does not compile, class Test has to extend Thread or implement Runnable in order to call wait().
��4. Code compiles and runs without exceptions.
Answers : �4

Explanation given : wait()�has�to�be�called�by�thread�which�owns�object's�monitor
(lock).�There�is�no�such�requirement�that�wait()�has�to�be�called�from�within�synchronized�code.�When�main�thread�enters sMethod()�it�owns�monitor�of�this�object.�It�can�then�enter method()�and�call�wait()�because�monitor�is�released�when�thread leaves�sMethod(),�not�when�it�jumps�into�method().
���������
Does wait(), notify(), notifyAll() have to be called from synchronized code?
Most mock exams seem to think so.
I did look at the JLS.[JLS $17.14] From what I understood the requirement is that the thread which calls wait() should own the object lock.
Does this necessarily mean the same?
Any examples (if not) would help me a lot!
Thanks Thomas, Haining !
Silly of me to not notice the case.
So I gather my doubts on Q 37 are valid ?
Regards
Alokesh
24 years ago