wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt" Watch "doubt" New topic
Author

doubt

Parameswaran Thangavel
Ranch Hand

Joined: Mar 01, 2005
Posts: 485
hi all
if i declare a object inside a method then the reference variable become local whose life time is same as the method lifetime.what will happen to the object.can i say that once the method is finished the object is eligible for GC since the ref var scope is within the method only.



what about the final refrence variable inside a method.is the keyword final have any effect on my above conclusions...


finally only null, true, false are reserved word all the other are keyword.
comment on it.
Jagadesh cs
Ranch Hand

Joined: Apr 25, 2005
Posts: 50
Hi


finally only null, true, false are reserved word all the other are keyword.
comment on it.


According to the JLS null, true and false are literals. they are not key words and the exam won't require you to find the difference between keywords and literals . its just enough if you know that they cant be used as identifiers, i.e. they are reserved words. ( This is present in K & B chapter 1 )



if i declare a object inside a method then the reference variable become local whose life time is same as the method lifetime.what will happen to the object.can i say that once the method is finished the object is eligible for GC since the ref var scope is within the method only.



Once a method has completed all objects local to it are eligible for GC ( of course unless a reference is returned by that method or some other refernce is given to that object )



what about the final refrence variable inside a method.is the keyword final have any effect on my above conclusions...



final identifier is just used to make sure that the value of a variable or its refernce cant be changed. It does not have any thing to do with the scope of a variable.


[ April 28, 2005: Message edited by: Jagadesh cs ]

Cheers,<br />Jagadesh.<br /> <br />--------------------------------<br />SCJP 1.4 , SCBCD 1.3 , SCWCD 1.4<br />--------------------------------
Jane W pemberley
Greenhorn

Joined: Apr 26, 2005
Posts: 12
I think,
null,false,true are reserved words not keywords.
and all keywords are reserved.

Hope u can notice the difference
rgrds
Jane
Parameswaran Thangavel
Ranch Hand

Joined: Mar 01, 2005
Posts: 485
hi jagadesh why i am doudting the final modifier is in the method local inner class the object can access only the final variable which means the variable is existing even the method finishes the execution. so i doubt that when giving final they may exists even outside the method scope.
soumya ravindranath
Ranch Hand

Joined: Jan 26, 2001
Posts: 300
Hi Parameswaran,

it would be a good idea to give your posts a more descriptive title rather than "doubt" or "clear the doubt please" so that it will attract required attention.

My 2 cents,

Soumya.
Ariel Ortiz
Ranch Hand

Joined: May 14, 2004
Posts: 121
Parameswaran,

When a method ends its execution, all its local variables and parameters stop existing and the memory space that was allocated to them is disposed. So how can an instance of an inner class (method-local or anonymous) refer to local variables and parameters that are no longer available? What happens is that the instance of the inner class actually holds a copy of the values stored in these "external" variables and parameters used in the body of its method definitions. This explains why they must be declared final. If a variable is declared final, no one can change its value, so we can have a copy of the value of that variable in an other one and say they're both the same variable, although technically they're not. So you don't access the real variable inside a method of the inner class, all you get is a read-only copy of it, which happens to have the same name and (apparent) scope as the original final local variable or parameter of the method that holds the inner class.

I hope this clarifies your question.

...Ariel
 
wood burning stoves
 
subject: doubt
 
Similar Threads
final in method argument
problem in when to use this in java
Doubt regarding Method Local Inner Class
Class inside method
final variable as parameter to method.