• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doubt

 
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic