There can be a lot of usage of Java this keyword. In Java, this is a reference variable that refers to the current object.

Usage of Java this keyword

1) this: to refer to a current class instance variable

This keyword can be used to refer current class instance variable. If there is ambiguity between the instance variables and parameters, this keyword resolves the problem of ambiguity.

2) this: to invoke the current class method

You may invoke the method of the current class by using this keyword. If you don't use this keyword, the compiler automatically adds this keyword while invoking the method.

3) this() : to invoke current class constructor

The this() constructor call can be used to invoke the current class constructor. It is used to reuse the constructor. In other words, it is used for constructor chaining.

4) this: to pass as an argument in the method

The this() keyword can also be passed as an argument in the method. It is mainly used in event handling.

5) this: to pass as an argument in the constructor call

We can pass the this() keyword in the constructor also. It is useful if we have to use one object in multiple classes.

6) this keyword can be used to return the current class instance

We can return this keyword as a statement from the method. In such a case, the return type of the method must be the class type (non-primitive).

Syntax of this that can be returned as a statement

return_type method_name(){  
return this;