SlideShare a Scribd company logo
NAME- SUCHANDA BANERJEE
ROLL NO.- 10800120085
BATCH- B
SEM- 5TH
TOPIC- ‘THIS’ KEYWORD AND GARBAGE COLLECTION
ASANSOL ENGINEERING COLLEGE
Java :
this keyword: to refer current class instance variable.
The 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.
When To Use ‘this’ In Java?
In Java the term ‘this’ has the following uses:
 The reference ‘this’ is used to access the class instance variable.
 You can even pass ‘this’ as an argument in the method call.
 ‘this’ can also be used to implicitly invoke the current class method.
 If you want to return the current object from the method, then use
‘this’.
 If you want to invoke the current class constructor, ‘this’ can be used.
 The constructor can also have ‘this’ as an argument.
Garbage Collection:
In java, garbage means unreferenced objects.
 Garbage Collection is process of reclaiming the
runtime unused memory automatically. In other
words, it is a way to destroy the unused objects.
 To do so, we were using free() function in C
language and delete() in C++. But, in java it is
performed automatically. So, java provides better
memory management.
Advantage of Garbage Collection:
 It makes java memory efficient because garbage collector
removes the unreferenced objects from heap memory.
 It is automatically done by the garbage collector(a part of
JVM) so we don't need to make extra efforts.
How can an object be
unreferenced?
 1) By nulling a reference:
Employee e=new Employee();
e=null;
 2) By assigning a reference to another:
Employee e1=new Employee();
Employee e2=new Employee();
e1=e2; //now the first object referred by e1 is available for garbage collection
 3) By anonymous object:
new Employee();

More Related Content

PPTX
Constructors_this keyword_garbage.pptx
PPT
packages and interfaces
DOCX
PPTX
Chapter 8 java
PPTX
25 java interview questions
PPT
Java interview-questions-and-answers
DOCX
Java interview questions
DOCX
100 Java questions FOR LOGIC BUILDING SOFTWARE.docx
Constructors_this keyword_garbage.pptx
packages and interfaces
Chapter 8 java
25 java interview questions
Java interview-questions-and-answers
Java interview questions
100 Java questions FOR LOGIC BUILDING SOFTWARE.docx

Similar to OOPS.pptx (20)

PPTX
This keyword and final keyword
PDF
Unit 2 Part 1 Constructors.pdf
PPTX
Java interview questions 2
PDF
Constructors in Java (2).pdf
DOCX
Java interview questions and answers for cognizant By Data Council Pune
PPTX
constructer.pptx
DOCX
Viva file
PDF
Core Java Interview Questions PDF By ScholarHat
DOC
Delphi qa
PPTX
Garbagecollectionhgfhgfhgfhgfgkfkjfkjkjfkjfjhfg.pptx
PPTX
Chap-2 Classes & Methods.pptx
ODP
Object Oriented Prograring(OOP) java
DOCX
Computer Programming 2
PPTX
Object oriented programming in java
PPTX
Statics in java | Constructors | Exceptions in Java | String in java| class 3
PPTX
Session 4 - Understanding JAVA Beans.pptx
PPTX
Thread in java.pptx
PPTX
Object oriented javascript
PPTX
Inheritance in OOPs with java
PPT
Advanced JavaScript
This keyword and final keyword
Unit 2 Part 1 Constructors.pdf
Java interview questions 2
Constructors in Java (2).pdf
Java interview questions and answers for cognizant By Data Council Pune
constructer.pptx
Viva file
Core Java Interview Questions PDF By ScholarHat
Delphi qa
Garbagecollectionhgfhgfhgfhgfgkfkjfkjkjfkjfjhfg.pptx
Chap-2 Classes & Methods.pptx
Object Oriented Prograring(OOP) java
Computer Programming 2
Object oriented programming in java
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Session 4 - Understanding JAVA Beans.pptx
Thread in java.pptx
Object oriented javascript
Inheritance in OOPs with java
Advanced JavaScript

Recently uploaded (20)

PDF
A REACT POMODORO TIMER WEB APPLICATION.pdf
PPTX
Benefits of DCCM for Genesys Contact Center
PPTX
Save Business Costs with CRM Software for Insurance Agents
PDF
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
PPTX
Presentation of Computer CLASS 2 .pptx
DOCX
The Five Best AI Cover Tools in 2025.docx
PPTX
Odoo Consulting Services by CandidRoot Solutions
PDF
Best Mobile App Development Company in Lucknow - Code Crafter Web Solutions
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Materi-Enum-and-Record-Data-Type (1).pptx
PDF
Convert Thunderbird to Outlook into bulk
PDF
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
PPTX
How a Careem Clone App Allows You to Compete with Large Mobility Brands
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
PDF
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
PPTX
Computer Hardware tool: hand tools, diagnostics, ESD and cleaning tools
PDF
How to Confidently Manage Project Budgets
PDF
Micromaid: A simple Mermaid-like chart generator for Pharo
PDF
Perfecting Gamer’s Experiences with Performance Testing for Gaming Applicatio...
PDF
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
A REACT POMODORO TIMER WEB APPLICATION.pdf
Benefits of DCCM for Genesys Contact Center
Save Business Costs with CRM Software for Insurance Agents
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
Presentation of Computer CLASS 2 .pptx
The Five Best AI Cover Tools in 2025.docx
Odoo Consulting Services by CandidRoot Solutions
Best Mobile App Development Company in Lucknow - Code Crafter Web Solutions
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Materi-Enum-and-Record-Data-Type (1).pptx
Convert Thunderbird to Outlook into bulk
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
How a Careem Clone App Allows You to Compete with Large Mobility Brands
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
Computer Hardware tool: hand tools, diagnostics, ESD and cleaning tools
How to Confidently Manage Project Budgets
Micromaid: A simple Mermaid-like chart generator for Pharo
Perfecting Gamer’s Experiences with Performance Testing for Gaming Applicatio...
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)

OOPS.pptx

  • 1. NAME- SUCHANDA BANERJEE ROLL NO.- 10800120085 BATCH- B SEM- 5TH TOPIC- ‘THIS’ KEYWORD AND GARBAGE COLLECTION ASANSOL ENGINEERING COLLEGE
  • 2. Java : this keyword: to refer current class instance variable. The 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.
  • 3. When To Use ‘this’ In Java? In Java the term ‘this’ has the following uses:  The reference ‘this’ is used to access the class instance variable.  You can even pass ‘this’ as an argument in the method call.  ‘this’ can also be used to implicitly invoke the current class method.  If you want to return the current object from the method, then use ‘this’.  If you want to invoke the current class constructor, ‘this’ can be used.  The constructor can also have ‘this’ as an argument.
  • 4. Garbage Collection: In java, garbage means unreferenced objects.  Garbage Collection is process of reclaiming the runtime unused memory automatically. In other words, it is a way to destroy the unused objects.  To do so, we were using free() function in C language and delete() in C++. But, in java it is performed automatically. So, java provides better memory management.
  • 5. Advantage of Garbage Collection:  It makes java memory efficient because garbage collector removes the unreferenced objects from heap memory.  It is automatically done by the garbage collector(a part of JVM) so we don't need to make extra efforts.
  • 6. How can an object be unreferenced?  1) By nulling a reference: Employee e=new Employee(); e=null;  2) By assigning a reference to another: Employee e1=new Employee(); Employee e2=new Employee(); e1=e2; //now the first object referred by e1 is available for garbage collection  3) By anonymous object: new Employee();