Rakesh Ne

+ Follow
since Mar 12, 2007
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Rakesh Ne

The source here :

says that finalize is called only once. But I remeber reading somewhere that finalize is called more than once, if the first call to finalize cannot cleanup the object.

Somebody please calrify.

Thanks in advance
16 years ago
class Dims {
public static void main(String[] args) {
int[][] a = {{1,2,}, {3,4}};
//After the above line, these are the contents of a :
a[0] = {1,2}
a[1] = {3,4}
which is nothing but ->
a[0][0] = 1
a[0][1] = 2
a[1][0] = 3
a[1][1] = 4

int[] b = (int[]) a[1];
//After the above line b ={3,4}
b[0] = 3
b[1] = 4

// The below 2 lines are inconsequential
Object o1 = a;
int[][] a2 = (int[][]) o1;

} }

Hope it helps
I was under the impression that finalize will be called always when an object is being garbage collected. After looking at Srinivasan's post, I have done some reading about Garbage Collection and finalize in particular. I realized that when an object comes for garbage collection for the second time, JVM actually remembers that and goes ahead and deletes that object from heap. And that clears all my confusion over option 3 or 4.


Originally posted by Henry Wong:

Please quote your sources. Thanks.


Source : JavaBeat

Originally posted by Henry Wong:

Please quote your sources. Thanks.


Source : JavaBeat

Originally posted by Henry Wong:

Please quote your sources. Thanks.


Source : JavaBeat
If the finalize() method of an object is re-references an object so that it becomes in-eligible for garbage collection
1. The compiler will throw an error.
2. The garbage collector "collects" the object anyway.
3. The garbage collector does not collect the object in the present sweep. But when the object becomes eligible for garbage collection again, its finalize method will not be called by the garbage collector (i.e., if the garbage collector gets a chance to run.). It will simply be garbage collected.
4. The object can never be garbage collected and hence leads to memory-leak. Each time the garbage collector calls finalize before "collecting" the object the object "resurrects" itself.

The answer for the above question is given as 3. I believe it is 4. Can somebody please explain why is it 3.

I think Rami Reddy question basically is "why is String class equals method is called ?"


How does the JVM know that String class equals needs to be called rather then Object class equals (which plainly checks for equality of reference)
That was a very well composed reply.

Thanks a lot.

Originally posted by Prasad Shindikar:
Object o1 = a;

for the first question you will get an error here
it should not be a runtime exception
you must get an compile time exception since cannot convert from int[][] to Object

[ March 26, 2007: Message edited by: Prasad Shindikar ]

All Arrays are Objects first. So that should be possible.Infact

int[][] a;

(o instanceOf Object)

returns true ;

Attempting to compile and run the code
1. Will cause a compilation error.
2. Runtime Execption - NullPointerException in the 2nd line of the main method.
3. Will compile successfully and print nullnull on the screen.
4. Will compile successfully and print an empty line on the screen.
5. Will compile successfully and print nothing on the screen.

The above code compiles fine and when run, produces the output:
on the console. (Option 3)

I tried Case 2, just out of my curiosity to check if the behaviour is any different.

Can somebody please explain why is it not lead to NullPointerException. (Option 2)

Which of the following are true about the class defined inside an interface
1. it is not possible in the java Laungage.
2. The class is always public.
3. The class is always static.
4. the class methods cannot call the methods declared in the interface.
5. the class methods can call only the static methods declared in the interface.

I dont know the answer(s) for the above question. Can somebody please provide answer(s) with explanation.

Thanks for your replies.
I am still in a confusion over the compilation error

Even though we have the catch block throwing Exception, the method signature does not have throws Exception
public static int method(){...}

Why does the compiler not complain ?

My guess - The code will never reach that stage. Hence it is supressed.
17 years ago

If I compile and run the above code, "3" is printed. Can somebody please explain :
1. Why is a compilation error not thrown since method() is not throwing the Exception ?
2. A new Exception is thrown in catch block. How does "3" get printed since the that Exception is not handled ?

Thanks in advance

Rakesh N
17 years ago