Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link

yaswanth yash

Greenhorn
+ Follow
since Apr 18, 2012
yaswanth likes ...
Spring Java
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
7
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by yaswanth yash

Why an abstract class can miss the implementation of its interface methods...

what is the relationship between an Interface & its abstract implementation class...

An exceptional case for abstract classes?
9 years ago
can you explain me the relationship between Interface and its implementation classes?
And I want to know the usage of reference variables & objects for the methods in interfaces and its Implementation classes.
9 years ago
Why do we have only public static final variables in interfaces?
9 years ago

Stevens Miller wrote:

yaswanth yash wrote:public class Test {
Test t1 = new Test(); // line 1
public static void main(String[] ar) {
new Test(); // line 2
Test t2 = new Test(); // line 3
}
}


hi stevens,
can you tell me,
After how much time the objects created at lines 1,2,3 in this program
are made eligible for garbage collection??



Good Gracious, yaswanth, what are you trying to do here??? As Paul said, no object created by this code will ever be eligible since none of them ever lacks a reference, because that "new Test()" call results in an infinite sequence of Test objects creating more Test objects. (To be a bit of a nit-picker about it, I wouldn't say it "goes into a loop," but that it results in infinite recursion, which Paul clearly knew when he warned that the program will crash with a stack overflow.)

And do you mean to say that making an object eligible for garbage collection means dereferencing that object ?!



If I understand your question, the answer is "yes." When there are no outstanding references to an object, it is eligible for garbage collection.

Paul's right. Learning about the GC can wait. Mostly, the only thing to learn about it is that there really isn't anything to learn about it. As a new Java programmer, I found myself very concerned about it, thinking that maybe I needed to call it explicitly here and there, to be sure my program wasn't using up memory for no reason. Well, it turns out that the people who wrote the GC knew what they were doing. The GC will always be called if your application tries to get more memory than it can, so don't worry that you will ever run out of resources for lack of calling it yourself. I'm no GC expert, but I believe it also tries to hold off running while your application isn't blocked. That is, it runs when it really should run, and not when it really shouldn't. And, like I said before, you simply cannot force it to run; best you can do is ask it to run. Hard as it may seem, the bad news is that you just have to trust it. The good news is that it is worthy of your trust.

9 years ago
public class Test {
Test t1 = new Test(); // line 1
public static void main(String[] ar) {
new Test(); // line 2
Test t2 = new Test(); // line 3
}
}


hi stevens,
can you tell me,
After how much time the objects created at lines 1,2,3
are made eligible for garbage collection??

And do you mean to say that making an object eligible for garbage collection means a dereferencing that object ?!
9 years ago
what makes an Object eligible for Garbage Collection?
And after how much time the garbage collector comes again for Garbage Collection?
9 years ago
thnq so much 4 d replies...
9 years ago


when i run this class the instance variable value will be modified.
At line 1, an instance variable of 4 bytes memory is created & assigned a value of 10.
So, At line 2, are we allocating 4 bytes memory again for variable 'x' ? Is that a disadvantage of Instance variables ?

[See UseCodeTags]
9 years ago
I hope you can guess my suggestion...mr.winston
9 years ago
why a java file name and its class names should be same?
9 years ago
yup! Thnq paul....
9 years ago
why and how Read() method of InputStream class (used as System.in.read()) is accepting more than one character at-a-time....even though it is used to read one character at-a-time...
9 years ago