This week's book giveaways are in the Jython/Python and Object-Oriented programming forums. We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line! See this thread and this one for details.
Hay guys, in the 1.4 exam, WATCH OUT for the GC, me and shishio missed on that one a lot, got only 33% on GC although I was sure I know it GOOD. Kathy told me the exam don't ask you on less than method scope in GC but NO it DOES ask whether a local variable was eligible for GC right after the line that sets its reference to another object or after the whole method finishes.. I chose "after the method is finished" and seemingly I missed on this one.... so my advice, WATCH OUT ON THE GC... ah, I got an overall of 90% by the way..
Alfred, I too got a question similar to what you described and the choices had both "after the end of the method" and "after the line X". (I think we both are talking about the same question) But the question was quite clear. The correct choice varies depending on the code snippet. These type of questions can be answered definitely if the opcodes can be guessed.
Congrats Alfred. I did not understand what u said about GC question. Can u explain that clearly? Also, please tell us what kind of questions did u get in Collections and assertions. (level of difficulty)
SCJP 1.4<p>Wingardium Leviosa!!
posted 17 years ago
Well, on some threads before, we were discussing when will a local variable be eligible for GC, is it right after the reference set to null for instance or only it will be eligible for GC after the whole method returns - even with the reference set to null in a previous line of code -, people had diff. opinions, but then Kathy said that the exam won't ask about that in scopes less than a method scope... For the collections and assertions, questions were fairly easy, it needs you to know all the characteristics - however you spell it - of assertions, when it's appropriate to use it and when you shouldn't, what's the behavior of the compiler and JVM with respect to assertions, etc.. I don't think there was any code snippet with assert statement, but maybe in other exams there will be. For the collections, there were 2 Qs as I remember, they asked which class should be suitable for these needs (i.e: keeps track of the inserted elements or have unique elements, etc..) There was nothing about the methods in the collection frame work that's about it..
Howdy -- OK, let me try to clear up the GC/scope issue. Because I'm pretty sure that I'm the idiot who was not clear enough in the earlier posts about this topic. The context of the below-method-scope-level was referring to loop and block variables, not to other gc triggers somewhere within the method (I'll explain more below) I must have led people to interpret that phrase in a way other than I intended. Yikes! And if Alfred interpreted it that way, then I bet tons of other people did too, because he's one of the brightest crayons in the box around here SO here it is again, hopefully this time with more detailed explanations: We have two ways to know an object is no longer referenced: 1) The reference is deliberately nulled or reassigned, and it is the only live reference (i.e. reachable from a live thread) 2) The reference goes out of scope. So, it is point #2 where the scope-below-method-level comes into play. You will not be asked about GC with respect to references that go out of scope BEFORE a method completes. But that's only when the issue is about SCOPE. If the issue is from point #1, then you will definitely need to know exactly at which point an object becomes eligible for GC. Again, you ARE expected to know when, in a method, objects become eligible, but NOT because the reference went out of scope "early", in other words, you don't have to know that an object became eligible because its reference went out of scope somewhere BEFORE the method ended. This really just means a loop or other local block variable that is "less than method scope". Please please please write again if I just made it even more confusing, and my apologies. But I think my "less than method scope" comment needs to be viewed in the thread where we discussed it, because we were discussing the scope of LOOP variables. : ) Of course, Alfred is one of the few people on the planet to get even CLOSE to a 90% (and all the others are also here on javaranch, BELIEVE me, people do NOT get these kind of scores on this exam), but what's frustrating for him is that he knows he could have done even better if the wording of the questions had been better!! (And frustrating for me because, after all the analysis Alfred has done for me, I am certain that he would have as well). So yes, I have to say that the GC questions are tricky, but they do follow the rules very explicitly. A reference is either: 1) Nulled 2) Reassigned 3) Goes out of scope (at the method level!!) Any of those three are what you must be able to recognize, with reasons 1 and 2 potentially happening ANYWHERE in a method. The difficulty is that you won't see many questions that say: 1. Object o = new Object(); 2. o = null; 3. // more code How many objects are eligible for GC at line 3?
But the exam would put that question in a much more complex example, with the o referenced passed into some other constructor and then some method, that then reassigns the copy of o, etc., etc., etc. I'm still going to congratulate Alfred for being one of the top scorers in the world! But I also believe that phrasing on the questions may have prevented him from going further. Alfred, for gosh sakes get out there and celebrate. I just wish you could know how amazing your score really was. As far as we're concerned, there's really no difference between 90 and 100, because you have to allow for some questions to be misinterpreted, no matter how heavily they're tested. Cheers, Kathy "dances with garbage" Sierra
Ok Kathy, I gotta say, THAT post really cheered me up First for understanding your point about GC and Second for your trust in my understanding to Java Thanks for your explanation, and I hope you managed to spot the other GC Q with ambiguity, and the couple of typos in Thread and Exception. [ November 17, 2002: Message edited by: Alfred Kemety ]