SlideShare a Scribd company logo
OOPS, ENUMS, 
Inner Classes, 
GarbageCollection 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
1
ASSOCIATION 
 Association is a relationship between two objects. 
 Objects might not be completely dependent on each 
other. 
 One-to-many, many-to-one, many-to-many all these 
words define an association between objects 
 Example: A Student and a Faculty are having an 
association. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
2
AGGREGATION 
 A directional association between objects. 
 Aggregation can be considered as a “has-a” 
relationship. 
 Child object can also survive or exist without the 
enclosing class. 
 For Example, Room has a table, but the table can 
exist without the room. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
3
COMPOSITION 
 A restricted aggregation is called composition. 
 The member object (part) cannot exist without the 
containing class. 
 For example, A class contains students. A student 
cannot exist without a class. There exists composition 
between class and students. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
4
UML Diagrams of 
Relationships 
 Association 
Association is denoted by simple 
arrow 
 Aggregation 
aggregation is denoted by empty 
diamond head arrow 
 Composition 
composition is denoted by filled 
diamond head arrow 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
5
Difference Between 
Composition And Aggregation 
 When there is a composition between two objects, the 
composed object cannot exist without the other object. 
 In case of Aggregation, 
Though one object can contain the other object, 
there is no condition that the composed object must 
exist. 
 For Ex: Facebook has-a-User i.e. Aggregation 
Every User has a different Session i.e. 
Composition. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
6
METHODS OVERRIDING 
 Overriding is a feature of OOP languages like 
Java that is related to run-time polymorphism. 
 Method overriding is when a child class 
redefines the same method as a parent class, 
with the same parameters. 
 The key benefit of overriding is the ability to 
define behavior that is specific to a particular 
subclass type. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
7
The rules for overriding a method 
are as follows: 
 The argument list must exactly match that of the 
overridden method. 
 Overriding method CAN throw any unchecked 
runtime exception. 
 You cannot override a method marked final. 
 You cannot override a method marked static. 
 If a method can't be inherited, you cannot 
override it. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
8
METHOD OVERLOADING 
 Overloading is also a feature of OOP languages like 
Java that is related to compile time (or static) 
polymorphism. 
 Method overloading is defining several methods in 
the same class, that accept different numbers and 
types of parameters. 
 In this case, the actual method called is decided at 
compile-time, based on the number and types of 
arguments. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
9
Overloading Rules 
 Overloaded methods MUST change the argument 
list. 
 Overloaded methods CAN change the return type. 
 Overloaded methods CAN change the access 
modifier. 
 Overloaded methods CAN declare new or broader 
checked exceptions. 
 A method can be overloaded in the same class or 
in a subclass. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
10
ENUM, 
INNER CLASSES 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
11
Enum 
 An enumeration, or “enum” is simply a set of 
constants to represent various values. 
 An enum type is a special data type that enables for 
a variable to be a set of predefined constants. 
 The variable must be equal to one of the values that 
have been predefined for it. 
 enums extend java.lang.Enum and implement 
java.lang.Comparable. 
 Hence, enums can be sorted. 
 Enums override toString() and provide valueOf(). 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
12
Defining Enum 
 Old way of doing it: 
public final int SPRING = 0; 
public final int SUMMER = 1; 
public final int FALL = 2; 
public final int WINTER = 3; 
 New way of doing it: 
enum <enumname>{} 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
13
Advantages 
 Enums provide compile-time type safety. 
 Enums provide a proper name space for the 
enumerated type. 
 Enums are robust. 
 Enum printed values are informative 
 Because enums are objects, you can put them in 
collections. 
 Because enums are classes, you can add fields and 
methods. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
14
Inner Class 
 The class defined inside another class or interface is 
called inner class 
 We can also create an interface in another class or 
interface. 
 For example 
class Example{ 
class Sample{} 
} 
class Example{ 
interface Sample{} 
} 
interface Example{ 
class Sample{} 
} 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
15
Need of Inner Class 
 Inner class is used for creating an object logically 
inside another object with clear separation of 
properties region. 
 A inner class has access to the variables and methods 
of the outer class, even if they are declared private. 
 Nested classes can be hidden from other classes in 
the same package. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
16
Nested class (static inner class) 
 The inner class defined at class level with static 
keyword is called static inner class. 
 Syntax: 
 Allowed Modifiers: 
class Example{ 
static class A{} 
} 
private, protected, public, final, abstract, strictfp 
 Types of Members allowed: 
* static variable * non-static variable 
* static block * non-static block 
* static method * non-static method 
* main method * constructor 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
17
Inner class (non-static inner class) 
 The inner class defined at class level without static 
keyword is called non-static inner class. 
 Syntax: 
 Allowed Modifiers: 
private, protected, public, final, abstract, strictfp 
 Types of Members allowed: 
* non-static variable 
* non-static block 
* non-static method 
* constructor 
class Example{ 
class A{} 
} 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
18
Method Local class (local inner class) 
 The inner class defined inside a method of outer 
class called method inner class. 
 Syntax: 
 Allowed Modifiers: 
final, abstract, strictfp 
 Types of Members allowed: 
* non-static variable 
* non-static block 
* non-static method 
* constructor 
class A{ 
void m1(){ 
class B{} 
} 
} 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
19
Anonymous class (argument inner class) 
 It is a nameless subclass of some other existed 
class/interface. 
 Like other inner classes it is not individual class. 
 Using anonymous class we can do 3 things at a time- 
1. Inner class creation as a subclass of outer class. 
2. Overriding outer class method. 
3. Creating and sending its object as argument or 
return type to another method. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
20
 Syntax: 
new outerclassname(){ 
//overriding outer class methods 
} 
 Allowed Modifiers: 
no modifier is allowed 
 Types of Members allowed: 
* non-static variables 
* non-static blocks 
* non-static methods 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
21
Cohesion,Coupling 
And Garbage Collection 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
22
Cohesion 
Defintion:- 
Cohesion means that a certain class performs a set of 
closely related actions. Cohesion focuses on how 
single class is designed. 
Types of Cohesion:- 
 High Cohesion 
 Low Cohesion 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
23
High cohesion:- 
High cohesion is when you have a class that does a 
well defined job. 
Low cohesion:- 
Low cohesion is when a class does a lot of jobs that 
don't have much in common. 
Higher the cohesiveness of the class, better is the OO 
design. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
24
 Example:- 
 You have a class that adds two numbers, but the 
same class creates a window displaying the result. 
 This is a low cohesive class because the window 
and the adding operation don't have much in 
common. 
 The window is the visual part of the program and 
the adding function is the logic behind it. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
25
What is Coupling? 
Coupling:- 
 Coupling is the degree to which one class knows 
about another class. 
 It refers to how related are two classes / modules 
and how dependent they are on each other. 
Types of Coupling:- 
 Tight coupling 
 Loose coupling 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
26
Tight coupling:- 
Tight coupling is when a group of classes are 
highly dependent on one another. 
Loose coupling:- 
 Loose coupling would mean that changing 
something major in one class should not affect the 
other. 
 Generally, good OO design should be loosely 
coupled and highly cohesive. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
27
What is Garbage Collection ? 
 Garbage collection is the process of identifying 
which objects are in use and which are not, and 
deleting the unused objects. 
 In Java, process of deallocating memory is handled 
automatically by the garbage collector. 
 This enables faster development with less code, 
eliminate memory leaks and other memory-related 
problems. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
28
The ways to make an Object 
eligible for GC:- 
Even though the programmer is not responsible for 
distruction of Object. It is a good programming 
practice to make our object is eligible for the 
Garbage Collection, if it is no longer required. 
 Nullifying the reference variable :- 
 Re-assigning the reference variable:- 
 The Object created inside a method… are by 
default eligible for GC. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
29
When the Garbage Collector Runs? 
 The garbage collector is under the control of the JVM. 
 The JVM will typically run the garbage collector when it 
senses that memory is running low. 
 User can request the JVM for garbage Collection 
by Calling “System.gc()”. 
 User can rely on ‘System.gc()’ to free up enough memory 
without worrying for running out of memory. 
 But the garbage collector will run before it throws an 
OutOfMemoryException. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
30
Role of finalize() method in GC 
 Java has a mechanism to run some code just before 
your object is deleted by the garbage collector. 
 This code is located in a method named finalize() 
that all classes inherit from class Object. 
 For any given object, finalize() will be called only 
once (at most) by the garbage collector. 
 Calling finalize() can actually result in saving an 
object from deletion. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
31
“Thank You” 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
32

More Related Content

PPTX
LabVIEW: This Or That?
PDF
C progrmming
PPTX
Java Programming Fundamentals
PPTX
Introduction to Object-Oriented Concepts and Java
PPT
Lecture 3 java basics
PPTX
Java programming language
PPTX
java: basics, user input, data type, constructor
PPT
Chapter 1 - An Overview of Computers and Programming Languages
LabVIEW: This Or That?
C progrmming
Java Programming Fundamentals
Introduction to Object-Oriented Concepts and Java
Lecture 3 java basics
Java programming language
java: basics, user input, data type, constructor
Chapter 1 - An Overview of Computers and Programming Languages

What's hot (19)

PPT
Introduction to java programming part 2
PDF
Java chapter 1
PDF
Java swing 1
PPTX
Unit1 principle of programming language
PPT
Introduction of exception in vb.net
PPT
9781285852744 ppt ch14
PPT
Introduction to programming languages part 2
PDF
Spring IO 2015 Spock Workshop
DOCX
Java and its features
PDF
Java basics notes
PDF
What is Interface in Java | How to implement Multiple Inheritance Using Inter...
PPT
Interfaces In Java
PPT
Java essential notes
PDF
Compiler.design.in.c.docs
PPTX
Features of java
PPTX
Java history, versions, types of errors and exception, quiz
PPT
INTRODUCTION TO JAVA APPLICATION
Introduction to java programming part 2
Java chapter 1
Java swing 1
Unit1 principle of programming language
Introduction of exception in vb.net
9781285852744 ppt ch14
Introduction to programming languages part 2
Spring IO 2015 Spock Workshop
Java and its features
Java basics notes
What is Interface in Java | How to implement Multiple Inheritance Using Inter...
Interfaces In Java
Java essential notes
Compiler.design.in.c.docs
Features of java
Java history, versions, types of errors and exception, quiz
INTRODUCTION TO JAVA APPLICATION
Ad

Similar to Oops and enums (20)

PPT
packages and interfaces
PPTX
130704798265658191
PPTX
UNIT I OOP AND JAVA FUNDAMENTALS CONSTRUCTOR
PPT
Class & Object - Intro
PPTX
JAVA-PPT'S-complete-chrome.pptx
PPTX
JAVA-PPT'S.pptx
PDF
JAVA-PPT'S.pdf
PPTX
Java basics
PPTX
1 intro
PDF
Object Oriented Programming with C#
PPT
Module 3 Class and Object.ppt
PPTX
Classes, objects in JAVA
PDF
Oops concepts || Object Oriented Programming Concepts in Java
PPTX
Introduction to Object Oriented Programming
PPTX
03 classes interfaces_principlesofoop
DOC
C# by Zaheer Abbas Aghani
DOC
C# by Zaheer Abbas Aghani
PPTX
1 - Classes and Objects OOP.pptx
PPT
Basic Java Concept - Practical Oriented Methodologies
PPTX
General oop concept
packages and interfaces
130704798265658191
UNIT I OOP AND JAVA FUNDAMENTALS CONSTRUCTOR
Class & Object - Intro
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S.pptx
JAVA-PPT'S.pdf
Java basics
1 intro
Object Oriented Programming with C#
Module 3 Class and Object.ppt
Classes, objects in JAVA
Oops concepts || Object Oriented Programming Concepts in Java
Introduction to Object Oriented Programming
03 classes interfaces_principlesofoop
C# by Zaheer Abbas Aghani
C# by Zaheer Abbas Aghani
1 - Classes and Objects OOP.pptx
Basic Java Concept - Practical Oriented Methodologies
General oop concept
Ad

Recently uploaded (20)

PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
Well-logging-methods_new................
PPTX
Current and future trends in Computer Vision.pptx
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
Foundation to blockchain - A guide to Blockchain Tech
DOCX
573137875-Attendance-Management-System-original
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Model Code of Practice - Construction Work - 21102022 .pdf
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Well-logging-methods_new................
Current and future trends in Computer Vision.pptx
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Automation-in-Manufacturing-Chapter-Introduction.pdf
Foundation to blockchain - A guide to Blockchain Tech
573137875-Attendance-Management-System-original
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
CYBER-CRIMES AND SECURITY A guide to understanding
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
bas. eng. economics group 4 presentation 1.pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf

Oops and enums

  • 1. OOPS, ENUMS, Inner Classes, GarbageCollection Satyam Shrivastav http://programmingpoints.blogspot.in/ 1
  • 2. ASSOCIATION  Association is a relationship between two objects.  Objects might not be completely dependent on each other.  One-to-many, many-to-one, many-to-many all these words define an association between objects  Example: A Student and a Faculty are having an association. Satyam Shrivastav http://programmingpoints.blogspot.in/ 2
  • 3. AGGREGATION  A directional association between objects.  Aggregation can be considered as a “has-a” relationship.  Child object can also survive or exist without the enclosing class.  For Example, Room has a table, but the table can exist without the room. Satyam Shrivastav http://programmingpoints.blogspot.in/ 3
  • 4. COMPOSITION  A restricted aggregation is called composition.  The member object (part) cannot exist without the containing class.  For example, A class contains students. A student cannot exist without a class. There exists composition between class and students. Satyam Shrivastav http://programmingpoints.blogspot.in/ 4
  • 5. UML Diagrams of Relationships  Association Association is denoted by simple arrow  Aggregation aggregation is denoted by empty diamond head arrow  Composition composition is denoted by filled diamond head arrow Satyam Shrivastav http://programmingpoints.blogspot.in/ 5
  • 6. Difference Between Composition And Aggregation  When there is a composition between two objects, the composed object cannot exist without the other object.  In case of Aggregation, Though one object can contain the other object, there is no condition that the composed object must exist.  For Ex: Facebook has-a-User i.e. Aggregation Every User has a different Session i.e. Composition. Satyam Shrivastav http://programmingpoints.blogspot.in/ 6
  • 7. METHODS OVERRIDING  Overriding is a feature of OOP languages like Java that is related to run-time polymorphism.  Method overriding is when a child class redefines the same method as a parent class, with the same parameters.  The key benefit of overriding is the ability to define behavior that is specific to a particular subclass type. Satyam Shrivastav http://programmingpoints.blogspot.in/ 7
  • 8. The rules for overriding a method are as follows:  The argument list must exactly match that of the overridden method.  Overriding method CAN throw any unchecked runtime exception.  You cannot override a method marked final.  You cannot override a method marked static.  If a method can't be inherited, you cannot override it. Satyam Shrivastav http://programmingpoints.blogspot.in/ 8
  • 9. METHOD OVERLOADING  Overloading is also a feature of OOP languages like Java that is related to compile time (or static) polymorphism.  Method overloading is defining several methods in the same class, that accept different numbers and types of parameters.  In this case, the actual method called is decided at compile-time, based on the number and types of arguments. Satyam Shrivastav http://programmingpoints.blogspot.in/ 9
  • 10. Overloading Rules  Overloaded methods MUST change the argument list.  Overloaded methods CAN change the return type.  Overloaded methods CAN change the access modifier.  Overloaded methods CAN declare new or broader checked exceptions.  A method can be overloaded in the same class or in a subclass. Satyam Shrivastav http://programmingpoints.blogspot.in/ 10
  • 11. ENUM, INNER CLASSES Satyam Shrivastav http://programmingpoints.blogspot.in/ 11
  • 12. Enum  An enumeration, or “enum” is simply a set of constants to represent various values.  An enum type is a special data type that enables for a variable to be a set of predefined constants.  The variable must be equal to one of the values that have been predefined for it.  enums extend java.lang.Enum and implement java.lang.Comparable.  Hence, enums can be sorted.  Enums override toString() and provide valueOf(). Satyam Shrivastav http://programmingpoints.blogspot.in/ 12
  • 13. Defining Enum  Old way of doing it: public final int SPRING = 0; public final int SUMMER = 1; public final int FALL = 2; public final int WINTER = 3;  New way of doing it: enum <enumname>{} Satyam Shrivastav http://programmingpoints.blogspot.in/ 13
  • 14. Advantages  Enums provide compile-time type safety.  Enums provide a proper name space for the enumerated type.  Enums are robust.  Enum printed values are informative  Because enums are objects, you can put them in collections.  Because enums are classes, you can add fields and methods. Satyam Shrivastav http://programmingpoints.blogspot.in/ 14
  • 15. Inner Class  The class defined inside another class or interface is called inner class  We can also create an interface in another class or interface.  For example class Example{ class Sample{} } class Example{ interface Sample{} } interface Example{ class Sample{} } Satyam Shrivastav http://programmingpoints.blogspot.in/ 15
  • 16. Need of Inner Class  Inner class is used for creating an object logically inside another object with clear separation of properties region.  A inner class has access to the variables and methods of the outer class, even if they are declared private.  Nested classes can be hidden from other classes in the same package. Satyam Shrivastav http://programmingpoints.blogspot.in/ 16
  • 17. Nested class (static inner class)  The inner class defined at class level with static keyword is called static inner class.  Syntax:  Allowed Modifiers: class Example{ static class A{} } private, protected, public, final, abstract, strictfp  Types of Members allowed: * static variable * non-static variable * static block * non-static block * static method * non-static method * main method * constructor Satyam Shrivastav http://programmingpoints.blogspot.in/ 17
  • 18. Inner class (non-static inner class)  The inner class defined at class level without static keyword is called non-static inner class.  Syntax:  Allowed Modifiers: private, protected, public, final, abstract, strictfp  Types of Members allowed: * non-static variable * non-static block * non-static method * constructor class Example{ class A{} } Satyam Shrivastav http://programmingpoints.blogspot.in/ 18
  • 19. Method Local class (local inner class)  The inner class defined inside a method of outer class called method inner class.  Syntax:  Allowed Modifiers: final, abstract, strictfp  Types of Members allowed: * non-static variable * non-static block * non-static method * constructor class A{ void m1(){ class B{} } } Satyam Shrivastav http://programmingpoints.blogspot.in/ 19
  • 20. Anonymous class (argument inner class)  It is a nameless subclass of some other existed class/interface.  Like other inner classes it is not individual class.  Using anonymous class we can do 3 things at a time- 1. Inner class creation as a subclass of outer class. 2. Overriding outer class method. 3. Creating and sending its object as argument or return type to another method. Satyam Shrivastav http://programmingpoints.blogspot.in/ 20
  • 21.  Syntax: new outerclassname(){ //overriding outer class methods }  Allowed Modifiers: no modifier is allowed  Types of Members allowed: * non-static variables * non-static blocks * non-static methods Satyam Shrivastav http://programmingpoints.blogspot.in/ 21
  • 22. Cohesion,Coupling And Garbage Collection Satyam Shrivastav http://programmingpoints.blogspot.in/ 22
  • 23. Cohesion Defintion:- Cohesion means that a certain class performs a set of closely related actions. Cohesion focuses on how single class is designed. Types of Cohesion:-  High Cohesion  Low Cohesion Satyam Shrivastav http://programmingpoints.blogspot.in/ 23
  • 24. High cohesion:- High cohesion is when you have a class that does a well defined job. Low cohesion:- Low cohesion is when a class does a lot of jobs that don't have much in common. Higher the cohesiveness of the class, better is the OO design. Satyam Shrivastav http://programmingpoints.blogspot.in/ 24
  • 25.  Example:-  You have a class that adds two numbers, but the same class creates a window displaying the result.  This is a low cohesive class because the window and the adding operation don't have much in common.  The window is the visual part of the program and the adding function is the logic behind it. Satyam Shrivastav http://programmingpoints.blogspot.in/ 25
  • 26. What is Coupling? Coupling:-  Coupling is the degree to which one class knows about another class.  It refers to how related are two classes / modules and how dependent they are on each other. Types of Coupling:-  Tight coupling  Loose coupling Satyam Shrivastav http://programmingpoints.blogspot.in/ 26
  • 27. Tight coupling:- Tight coupling is when a group of classes are highly dependent on one another. Loose coupling:-  Loose coupling would mean that changing something major in one class should not affect the other.  Generally, good OO design should be loosely coupled and highly cohesive. Satyam Shrivastav http://programmingpoints.blogspot.in/ 27
  • 28. What is Garbage Collection ?  Garbage collection is the process of identifying which objects are in use and which are not, and deleting the unused objects.  In Java, process of deallocating memory is handled automatically by the garbage collector.  This enables faster development with less code, eliminate memory leaks and other memory-related problems. Satyam Shrivastav http://programmingpoints.blogspot.in/ 28
  • 29. The ways to make an Object eligible for GC:- Even though the programmer is not responsible for distruction of Object. It is a good programming practice to make our object is eligible for the Garbage Collection, if it is no longer required.  Nullifying the reference variable :-  Re-assigning the reference variable:-  The Object created inside a method… are by default eligible for GC. Satyam Shrivastav http://programmingpoints.blogspot.in/ 29
  • 30. When the Garbage Collector Runs?  The garbage collector is under the control of the JVM.  The JVM will typically run the garbage collector when it senses that memory is running low.  User can request the JVM for garbage Collection by Calling “System.gc()”.  User can rely on ‘System.gc()’ to free up enough memory without worrying for running out of memory.  But the garbage collector will run before it throws an OutOfMemoryException. Satyam Shrivastav http://programmingpoints.blogspot.in/ 30
  • 31. Role of finalize() method in GC  Java has a mechanism to run some code just before your object is deleted by the garbage collector.  This code is located in a method named finalize() that all classes inherit from class Object.  For any given object, finalize() will be called only once (at most) by the garbage collector.  Calling finalize() can actually result in saving an object from deletion. Satyam Shrivastav http://programmingpoints.blogspot.in/ 31
  • 32. “Thank You” Satyam Shrivastav http://programmingpoints.blogspot.in/ 32