Thank you so much Admin for your answer!!
Enthuware is great, I learnt a lot of with your explanations, I feel very confident to try to pass the OCA certificate.
Thank you guys!!
Hi There
I'm finding the !=(Not equals) quite confusing .
The interpretation of the != operator is that , if values are not equal then the condition evaluates to true,
or evaluating to true if the values are different.
The while loop has the following condition : while(x = getX() !=0) .This implies 5 !=0 .So if I use the definition
of the != that says if values are not equal the condition evaluates to true ...why does the while loop evaluate
to false.
So the fact that the correct answer is that it will run forever and not throw an exception (OutOfMemeoryException) at run time, mean that neither the for loop nor the assignment within it (x=m) consume any memory?
Correct. Heap memory is consumed only when you create any object. stack memory is consumed when you create local variables. Neither is happening here.
(If you are not clear about the difference between Heap and Stack, you might want to go through a good book. Section 1.6 of Hanumant's book explains this nicely. )
If you like our products and services, please help us by posting your review here.
Section 1.6 really brought together how JVM stores local variables and objects.
One thing was not explicitly mentioned though, where field variables are stored?
Also, since arrays are objects, they will be stored on the heap whether they are field or local arrays, correct?
Section 1.6 really brought together how JVM stores local variables and objects.
One thing was not explicitly mentioned though, where field variables are stored?
It is mentioned quite clearly in point 5 of Points to remember pg 117:
Only temporary variables i.e. variable created in a method (also known as local variables and automatic variables) are created on the stack space. Everything else is created on the heap space. If you have any doubt, ask yourself this question - is this a temporary variable created in a method? Yes? Then it is created on the stack. No? Then it is on the heap.
sorry...but shouldn't it print 10 in case of removing the local variable X from looper method? cause instance variable X would be assigned M, which woths 10 at the first and last iteration. why zero??
The answer explanation says: "If you remove int x = 0; from looper(), it will print 0 and end." Shouldn't it be var x = 0 to be consistent with the question?