this Keyword Java
"this" keyword refers an object, to say, the current object. Observe the following program and pay attention to this.salary.
public class Officer3
{
int salary;
public void display(int salary)
{
this.salary = salary;
}
public static void main(String args[])
{
Officer3 o1 = new Officer3();
o1.display(5000);
System.out.println(o1.salary); // 5000
}
}

In the display() method, local variable and the instance variable are same, salary. That is, local variable clashes with instance variable. If "this" is removed in display() method, o1.salary in the main() method prints 0. "this" refers the object o1 as with o1 the display() method is called. Now we can make one rule, if a method is called with an object, the instance variables inside the method are linked with the object implicitly. Now, this.salary becomes o1.salary internally and one memory location is created. If "this" is removed, both salaries are treated as local variables and thereby the compiler does not create any memory location. Use always "this" keyword to differentiate a local from instance variable when they clash. C++ people, call "this keyword" as "this pointer".
Explanation on parameters passing to method is available at Three Great Principles – Data Binding, Data Hiding, Encapsulation.
Sir, plz write more about uses of this keyword..this() method..
this keyword is just to avoid clash between instance and local variables.\
this() is to call one constructor from another of the same class.
this and this() works very differently and no similarities.
what about local variables is memory created for them too ?
Local variables memory exist as long as the method executes.
very intresting site..
i was verp weak in java
but reading this site getting more benefit..
thank you nageshewar sir..
contact-8334090510
Tell your friends also to derive benefit of the site.
Sir please can u explain the below line as i am not understanding it…???
“this” refers the object o1 as with o1 the display() method is called.
this website is very useful for me i request you please share java EE tutorial
It takes lot of time. It is my passion to do this in my leisure hours.
Friends this really very good..A simple example cleared all my doubt in sec so thank u..
This web site is very useful for the Softwere engineering student.
it is very simple example &its make so helpful for clearation of basic concept
Thanks, tell your friends to get benefited of this web site.
Very easy example ,very helpful for begineers.