
Quick Contact
Java Tutorial
- What is Java?
- History of Java
- Hello Java Program
- Features of Java
- Basic Syntax
- Java Setup
- Data Types in Java
- Java Variables
- Operators in Java
- JVM
- Java If-else Statement
- Switch Case Statement
- Java Loops
- Do-While Loop
- Java While Loop
- Continue Statement
- Break Statement in Java
- Constructors in Java
- Oops Concept in Java
- Features of OOPs
- Inheritance
- Exeception handeling
- Aggregation (HAS-A relationship) in Java
- Method Overriding in Java
- Method Overloading
- Java Static Keyword
- Java This Keyword
- Java Final Keyword
- Polymorphism
- Static Binding and Dynamic Binding
- Abstract class in Java
- Access Modifiers in Java
- Difference between abstract class and interface
- Interface in Java
- Garbage Collection in Java
- Java Package
- Encapsulation
- Serialization and Deserialization in Java
- Java Inner Classes
- Java Applets
- Multithreading in Java
- Thread Priorities in Java
- Thread Creation
- Inter Thread Communication
- Wrapper Classes in Java
- Java Input Output
- Java AWT Introduction
- Java Layout Manager
- Java Layout Policy
- Java AWT Events
- Collection Framework
- Collection Framework List Interface
- Swing in Java
- Swing Utility Classes
- Swing Layout Managers
- Java JDBC
- Hibernate Framework Overview – Architecture and Basics
Springboot
- Spring Environment Setup
- Spring Boot CRUD REST API Project using IntelliJ IDEA | Postman | MySQL
- Dockerizing Spring Boot Application | Spring Boot Docker Tutorial
- spring-boot-restapidocumentation with swagger
- Spring Boot HttpClient Overview
- Apache HttpClient POST HTTP Request Example
- Apache HttpClient PUT HTTP Request Example
- Apache HttpClient DELETE HTTP Request Example
- Apache HttpClient HTML Form POST Request Example
- Spring Boot JSP Exampl
- Deploying Spring Boot WAR file with JSP to Tomcat
- Spring Boot Annotations
- Spring Core Annotations
- Spring MVC Annotations with Examples
- Spring Scheduling Annotations
- Spring - Java-based Container Configuration
- Spring Java Based Configuration Example
Hibernate
- Hibernate 5 hello world
- Hibernate- One to One Unidirectional Mapping Annotation Example
- Hibernate - Batch Processing
- Hibernate - Interceptors
- Hibernate 5 - Create, Read, Update and Delete (CRUD) Operations Example
- Hibernate Transaction Management
- Hibernate One to Many Unidirectional Mapping Example
- Hibernate One to Many Bidirectional Mapping Example
- Hibernate Many to Many Annotation Mapping Example
- Hibernate Primary KeyJoin Column
- Hibernate First Level Cache with Example
- Hibernate XML Configuration Example with Maven + Eclipse + MySQL Database
- Hibernate Java Configuration Example
- JPA 2 with Hibernate 5 Bootstrapping Example
- JPA and Hibernate Cascade Types
- Hibernate/JPA - Primary Key Generation
- Hibernate 5 - Enum Type Mapping Example
- Hibernate Component Mapping
- Hibernate Object States – Transient,Persistent and Detached
- Hibernate 5 - Save an Entity Example
- Hibernate 5 - Persist an Entity Example
- Hibernate 5 - saveOrUpdate() Method Example
- Hibernate 5 - get(), load() and byId() Method Examples
- Hibernate 5 - merge() Example
- Hibernate 5 - Delete or Remove an Entity Example
- Hibernate 5 - load() Method Example
- Hibernate Session Interface Methods
- Hibernate Session.clear() Method Example
- Introduction Of Java strutes to Architecture
- Struts 2 - Architecture
- Struts 2 - Configuration Files
- Struts 2 - Actions
- Struts 2 - Interceptors
- Struts 2 - Results & Result Types
- Struts 2 - Value Stack/OGNL
- Struts 2 - File Uploading
- Struts 2 - Database Access
- Struts 2 - Validations Framework
JAVA FX
- JavaFX Tutorial
- Introduction to JavaFX Pane
- JavaFX Popup
- JavaFX group
- JavaFX Controller
- JavaFX Gradient Color
- JavaFXAnchorPane
- JavaFXTabPane
- JavaFX Scene
- JavaFX Stage
- JavaFXWebView
- JavaFX Timeline
- JavaFX Timer
- JavaFX Image
- JavaFX Background
- JavaFX dialog
- JavaFX Font
- JavaFXTextArea
- JavaFXObservableList
- JavaFX GUI
- JavaFX FXML
- JavaFXEventHandler
- JavaFXGradle
- JavafxScrollpane
- JavaFXAPI
Java this keyword
In java usage of this keyword is to refer the current object. We can also say it is a reference variable that refers to the current object.
Sometimes a method will need to refer to the object that invoked it. To allow this, Java defines the this keyword. this can be used inside any method to refer to the current object. i.e., this is always a reference to the object on which the method was invoked. We can use this anywhere a reference to an object of the current class type is permitted.
In java there are many usages of this keyword. Following is the usage of this keyword-
- It is used to refer current class instance variable.
- It is used to invoke current class constructor.
- It is used to invoke current class method.
- It can be passed in argument in the method call.
- It can be passed in argument in the constructor call.
Examples
this. refer current class instance variable
this is used to refer to the existing class instance variable.
class Employee{ int id; String name; int salary; Employee(int id,String name,int salary){ this.id=id; this.name=name; this.salary=salary; } void display(){System.out.println(id+" "+name+" "+salary);} } class Newemployee{ public static void main(String args[]){ Employee e1=new Employee(101,"Gaurav",25000); Employee e2=new Employee(102,"Saurav",30000); Employee e3=new Employee(103,"Neha",20000); e1.display(); e2.display(); e3.display(); }}
Output
101 Gaurav 25000
102 Saurav 30000
103 Neha 20000
In the above example, we use this keyword to identify local and instance variable.
this() to invoke the current class constructor
The this() constructor is used to reuse the constructor from the constructor. It is used for chaining of the constructors.
class Employee{ int id; String name,designation; int salary; Employee(int id,String name,String designation){ this.id=id; this.name=name; this.designation=designation; } Employee(int id,String name,String designation,int salary){ this(id,name,designation);//reusing constructor this.salary=salary; } void display(){System.out.println(id+" "+name+" "+designation+" "+salary);} } class Newemployee{ public static void main(String args[]){ Employee e1=new Employee(101,"Gaurav","Tester"); Employee e2=new Employee(102,"Saurav","Developer",30000); Employee e3=new Employee(103,"Neha","Designar",20000); e1.display(); e2.display(); e3.display(); }}
Output
101 Gaurav Tester 0
102 Saurav Developer 30000
103 Neha Designer 20000
In below example, we can call default constructor from the parameterized constructor.
class X{ X(){System.out.println("Hello Mr X");} X(int A){ this(); System.out.println(A); } } class Y{ public static void main(String args[]){ X x=new X(10); }}
Output
Hello Mr X
100
In below example, we can call a parameterized constructor from the default constructor.
class X{ X(){ this(50); System.out.println("Hello Mr X"); } X(int a){ System.out.println(a); } } class Y{ public static void main(String args[]){ X x=new X(); }}
Output
50
Hello Mr X
this: to invoke a current class method
The this keyword is used to invoke the method of current class and if we cannot use this keyword then compiler automatically add this keyword while invoking the method.
Example
class X{ void a(){System.out.println("Hello Mr X");} void b(){ System.out.println("Hello Mr Y"); //a();//similar to this.a() this.a(); } } class Demo{ public static void main(String args[]){ X x=new X(); x.b(); }}
Output
Hello Mr Y
Hello Mr X
this: to pass argument in a method
The this keyword can be passed an argument in the method also. It is used in event handling.
Example
class X{ void a(X obj){ System.out.println("method invoked"); } void c(){ a(this); } public static void main(String args[]){ X x = new X(); x.c(); } }
Output
Method invoked
this: to pass argument in the constructor
this keyword can pass in constructor also when we have one object in multiple classes than it is used.
Example
class XYZ{ P obj; XYZ(P obj){ this.obj=obj; } void display(){ System.out.println(obj.data);//Here use data member of P class } } class P{ int data=1000; P(){ XYZ b=new XYZ(this); b.display(); } public static void main(String args[]){ P p=new P(); } }
Output
1000
Apply now for Advanced Java Training Course