This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes this keyword? 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 » Java » Java in General
Bookmark "this keyword?" Watch "this keyword?" New topic
Author

this keyword?

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

Hi
well the keyword this is used to point at the current object, right?

can anone ber more precise on this???


http://www.lifesbizzare.blogspot.com || OCJP:81%
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11153
    
  16

what do you mean by more precise?

It's similar to me writing a paper and using the word 'my' before 'arm'. the sentence 'arms are tattooed' has a different meaning than 'my arms are tattooed'. using the word 'my' indicates WHICH arms are being talked about.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

Is it by default?

whenever we write a simple hello world program...
(Sir, Huge fan of you and kathys sierra's(including many more cant memorize all the names) SCJP6 Book)
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11153
    
  16

is what by default what?

and what does it have to do with a hello world program?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Vishal Hegde wrote:
(Sir, Huge fan of you and kathys sierra's(including many more cant memorize all the names) SCJP6 Book)


Yes, fred, when are you coming out with a new one?


[Jess in Action][AskingGoodQuestions]
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

The this keyword is a built-in feature of the Java language. So it is always there to be used, not sure if this is what you mean by default?

Hunter


"If the facts don't fit the theory, get new facts" --Albert Einstein
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11153
    
  16

Ernest Friedman-Hill wrote:
Vishal Hegde wrote:
(Sir, Huge fan of you and kathys sierra's(including many more cant memorize all the names) SCJP6 Book)


Yes, fred, when are you coming out with a new one?


No...they meant they are a huge fan of me...and also a huge fan of Kathy's book. Perfectly logical.
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 273

Vishal Hegde wrote:Is it by default?


If I understand you correctly, it is optional in certain situations. For example, if you have a class-level field called "foo", you can access this field in a method with or without using "this", so it's optional.



However, if you also have a variable in your method with the same name, you must use "this" in order to refer to the class-level field.


You see this sort of thing a lot in setter methods, where the method parameter usually has the same name as the field.


SCJP 6 || SCWCD 5
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

fred rosenberger wrote:
Ernest Friedman-Hill wrote:
Vishal Hegde wrote:
(Sir, Huge fan of you and kathys sierra's(including many more cant memorize all the names) SCJP6 Book)


Yes, fred, when are you coming out with a new one?


No...they meant they are a huge fan of me...and also a huge fan of Kathy's book. Perfectly logical.


Lucky to be one of the members of this forums

thnks i think i am getting concepts clear of this method
 
wood burning stoves
 
subject: this keyword?
 
Similar Threads
WA #1.....word association
Is "null" a keyword in Java?
Whats the difference between keywords and reserved words
Tips to create this method
Calling constructor