vadiraj vd

Ranch Hand
+ Follow
since Dec 15, 2000
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 vadiraj vd

Hi ms !!


1) If in finalize method we make re refrence to the object .Will that object ever be garbage collected.


No. since the gc calls the finalize method only once. If you make any reference to an object then it will not be GC'ed.


2) Is it mandatory to call the base class finalize method in the subclass's finalize method else the compiler will give compile time error .


Compiler won't give any error, but it's neccessory to call the superclass's finalize as finalize methods are not chained by default.
I hope this is clear.
Regards,
Vadiraj. scjp

Hi all,
I'm happy to say that I cleared SCJP with 84%. That's 50 out of 59.
First of all I would like to thank Mr.Khalid A. Mughal. for writing a comprehensive book.
Also thanks to all moderators of this site.
I had lot of questions related to Threads and Inner classes.
There were 5 questions to one line fill-in.
My advice to all who are preparing for SCJP :
Prepare well in case of Threads and Inner class.
I got real brainer questions in Threads.
Keep your eyes open while reading the questions.
Every word in the question has a lot of meaning.
I wish all of you a good success.
Bye

------------------
Regards
---------
vadiraj

*****************
There's a lot of I in J.
*****************
21 years ago
Hi Munish,
Could you give the code you tried out?

------------------
Regards
---------
vadiraj

*****************
There's a lot of I in J.
*****************
Hi George,
static class is similar to any other non-static class except that
it has the access to only static members of the enclosing class.
So I think there's no harm by extending a class.

------------------
Regards
---------
vadiraj

*****************
There's a lot of I in J.
*****************
Yes Michael the answer is 2.
The GC will catch any exception that have generated in finalize()
but ignores them. If the GC wants to garbage collect the current
object then it will gabage collect it.
Refer Khalid about this. page no. 256 q8.3.


------------------
Regards
---------
vadiraj

*****************
There's a lot of I in J.
*****************
Hi All,
This question is from Mughal's mock exam. Could anyone give me an answer with explaination ?
Thanks,
CODE
---------
<pre>

Given the following code, which statements concerning
the objects referenced through the member 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 Q7ed5 {
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();
}
}

</pre>
--------
END OF CODE

------------------
Regards
---------
vadiraj

*****************
There's a lot of I in J.
*****************
Hi,
I'm totally agree with Vlad G.
The compiler is intelligent enough to find out where the return
statements are.
In your code there's a return in try, catch and finally.
So if any exception occurs the code after the finally will not
be executed.
Well Vladimir nice example to show that
the java compiler IS intelligent.


------------------
Regards
---------
vadiraj

*****************
There's a lot of I in J.
*****************
Hi All,
here's question from Mughal's mock exam.
CODE
-------
<pre>

Given the following class definitions, which expression
identifies whether the object referred to by obj was
created by instantiating class B rather than classes A, C and D?
class A {}
class B extends A {}
class C extends B {}
class D extends A {}
a. obj instanceof B
b. obj instanceof A && !(obj instanceof C)
c. obj instanceof B && !(obj instanceof C)
d. obj instanceof C | | (obj instanceof D)
e. obj instanceof A && !(obj instanceof C) && !(obj instanceof D)

</pre>
I think the answer is c. Please correct me if I'm wrong in this.

------------------
Regards
---------
vadiraj

*****************
There's a lot of I in J.
*****************
Hi ganeshan,
You are wrong. char value of '?' is NOT 65535.
The character '?' is printed out if we tried to print any
non-printable characters or the characters which our system won't recognise.
Hope this helps,

------------------
Regards
---------
vadiraj

*****************
There's a lot of I in J.
*****************
Hi Cristi,
You are missing the fact that '&&' is shortcircuit operator.
In short circuit operator evaluation, if the final result can be decided
by knowing the result of the first operand then the other operand
is NOT evaluated at all.
So the answer 2 is correct.
Hope this clears your doubt.


------------------
Regards
---------
vadiraj

*****************
There's a lot of I in J.
*****************
Hi ravi,
*) In Java arrays ARE implemented as Objects.
*) But you are trying to convert an array to an array of Objects.
*) We can convert the objects up the inheritance hierarchy.
The inheritance hierarchy is as follows(from Khalid's book)
<pre>

java.lang.Object
|
--------------------------------
| |
int[] Object[]

</pre>
So, the array of objects inherits from the object class directly.
static Object x;
Object a[] = x;
Here you are converting down the inheritance hierarchy(as seen in figure above).
So the compiler is trying to explain about this.
Hope this helps.

------------------
Regards
---------
vadiraj

*****************
There's a lot of I in J.
*****************
[This message has been edited by vadiraj vd (edited January 10, 2001).]
Thanks everyone,
Now I can say, I clearly understood what is meant by protected.
I tried an example below to check out Tom's explaination.
Here I created two classes in different package.
MyClassUsedinFinalizeTest is in package p.pack and FinalizeTest is in the package p.
The compiler gave the following error.
FinalizeTest.java:10: No method matching meth() found in class
p.pack.MyClassUsedInFinalizeTest.
m.meth();
^
1 error
Here's the code
CODE
-------
<pre>

// filename MyClassUsedInFinalizeTest.java in p.pack.
package p.pack;
public class MyClassUsedInFinalizeTest
{
protected void meth()
{
System.out.println("Hi, Java is amazing language !!");
}
}
// filename FinalizeTest.java in p.
package p;
import p.pack.*;
public class FinalizeTest
{
public static void main(String s[])
{
MyClassUsedInFinalizeTest m = new MyClassUsedInFinalizeTest();
m.meth();
}
}

</pre>
----------
END OF CODE
the command I used to run is -
<pre>d:\java>javac -d . MyClassUsedInFinalizeTest.java <enter>
d:\java>dir d:\java\p\pack <enter>
MyClassUsedInFinalizeTest.class
d:\java>javac -d . FinalizeTest.java <enter>
FinalizeTest.java:10: No method matching meth() found in class
p.pack.MyClassUsedInFinalizeTest.
m.meth();
^
1 error
</pre>
Correct me if I'm wrong.
Thanks again for an interresting discussion.


------------------
Regards
---------
vadiraj

*****************
There's a lot of I in J.
*****************
Hi Pratap,
Nice question,
1)The instanceof operator only checks the instances of object references.
2)All the arrays will always be initialised to their default values.
So refering to the above facts, your array of strings contains 10 object references to 10 string objects but currently they
are pointing to nowhere i.e. to [B] null [/B}.
So the answer is false as null cannot be a instance of any Class.
If you assign a value to name[0] then it gives true.
Please check out the code below.
CODE
---------

<pre>
public class StringArrayTest
{
public static void main(String a[])
{
String s[] = new String[10];
s[0] = "He;";
if( s[0] instanceof String)
System.out.println("True");
else
System.out.println("False");
}
}
</pre>

----------
END OF CODE
Hope this helps.
Also please post the questions in different threads so that they
can be viewed differently.

------------------
Regards
---------
vadiraj

*****************
There's a lot of I in J.
*****************
Hi All,
I found one more thread discussing same topic.
There the example given by Randall Twede. He does exactly same thing but he says it is correct.
I didn't get it.

------------------
Regards
---------
vadiraj

*****************
There's a lot of I in J.
*****************
Hi ajith and others,
Thanks for your valuable response.
Ajith I understood the concept of protected modifier.
I would like to raise the same fact pointed by Vladimir Kositsky
that,
all classes are sub classes of java.lang.Object class directly or indirectly.
So having protected midifier should not prevent us from accessing the finalize() method as our class is by default
sub class of the Object class.

Ajith could you throw some more light in this direction?
Thanks everyone again,


------------------
Regards
---------
vadiraj

*****************
There's a lot of I in J.
*****************