mrudul joshi

Ranch Hand
+ Follow
since Nov 12, 2003
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 mrudul joshi

Hi everybody,
I want to know whether the following method
boolean equals (Object obj)
throws the ClassCastException if the argument object is not of class String or does the language itself converts non-string object into its string representation internally?
Thanks in advance for your inputs.
Mrudul
I am sorry I didnt write the question earlier!
It is,
When will the object referred by the reference variable "first" be eligible for garbage collection?
Thanks
Mrudul
Can we expect questions on finalizer chaining in garbage collection in the actual exam?
Please help.
Thanks.
11. Which statements about garbage collection are true?
A) The garbage collector runs in low memory situations
B) You can run the garbage collector when ever you want.
C) When it runs, it releases the memory allocated by an object.
D) Garbage collector immediately runs when you set the references to null.
The answers given are A and C, but I think we cannot predict when the garbage collector runs, so the answer should be only C.
Please clarify.
Thanks
Mrudul
This is the code I came across while seeing earlier posts regarding garbage collection in javaranch forums.
class Riddle
{

public static void main(String[] args)
{
String first, second;
String riddle;
if (args.length < 2)
return;
first = new String(args[0]);
second = new String(args[1]);
riddle = "When is a " + first;
d:first = null;
riddle += " like a " + second + "?";
e:second = null;
System.out.println(riddle);
h:args[0] = null;
i:args[1] = null;
System.out.println(args[0]);

}
}
Select the one right answer.
1)d:
2)e:
3)h:
4)i:


I think the right answer is [1] that is, after the line d in executed.
Please clarify if I am wrong.
thanks
mrudul
[ December 12, 2003: Message edited by: mrudul joshi ]
This is the code I came across while seeing earlier posts regarding garbage collection in javaranch forums.

Select the one right answer.
1)d:
2)e:
3)h:
4)i:
5)j:

I think the right answer is [1] that is, wfter the line d in executed.
Please clarify if I am wrong.
thanks
mrudul
17 years ago
Congrats! Thats a real good score!
17 years ago
Hi,
Yes, I think you are right. The structure of the loop is,
for(initialization; boolean expression;step statement)and we can have as many initialization and step portions as we want to have provoded that they are separated by a comma.
For example,
for(int i =0, int j=12;j<12;i++)
Hey, I just checked it in a program code. It is giving a compile time error.
But I dont know why is it not getting initialized!
I think it will get the default value,if not initialized.But what is the point indeclaring it as an instance variable then?We can simply make it static variable.

According to me, only 2 objects are created in the above program.I called the method hashCode()from object class on every string object created.The output would have been three different hashcodes for each created object it there had been 3 objects created.
But, if you see the output,you will see just the two objects i.e.only two hashcodes.
(I am sorry something went wrong in the cut and paste)
Please see the output for ypurself, just to crosscheck!

69609650
I think it depends on their access modifiers.
The access modifiers are:
Public, private, default and protected
In case the access modifier is "public", the static method/variable is visible in same class, same package subclass,same package non-subclass,different package subclass and different package non sub class.
In case when it is "private", its visible and hence inherited only by the members of the same class.
In case of "default" i.e.when no access modifier is specified,they are visible in same class, same package subclass and same package non-subclass.But not in diff package sub class and diff package non subclass.
When the method/variable has "protected accessibility, then it is accessible/inherited by same class, same package subclass, same package non subclass and different package subclass but not in different package non subclass.
Thus,depending on accessibility modifiers of the static members in a class, clients can access them.
Hope this will help me.
Please correct me if I am wrong anywhere.
That was really good!
Thanks for clearing my concept.
bye
What does the following statement mean?


Assigning references does not copy the state of the source object on the right hand side, only the reference value.


What is exactly, the state of the source object?
Thanks
Any good link describing casting of references?
Thanks