0% found this document useful (0 votes)
51 views11 pages

Destructor and Finalize

Uploaded by

Jenishiya Rajan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views11 pages

Destructor and Finalize

Uploaded by

Jenishiya Rajan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

DESTRUCTOR

Introduction to DESTRUCTOR
 when we create an object of the class it occupies some space in the memory (heap). If we do
not delete these objects, it remains in the memory and occupies unnecessary space that is not
upright from the aspect of programming. To resolve this problem, we use the destructor

Destructor is a special method that automatically gets called when an object is no


longer used. When an object completes its life-cycle the garbage collector deletes that
object and deallocates or releases the memory occupied by the object.

 Remember that there is no concept of destructor in Java. In place of the destructor,


Java provides the garbage collector that works the same as the destructor.
Garbage COLLECTION

Objects are created on the heap. Eventually, some objects


will no longer be needed. The garbage collector finds these
unused objects and deletes them to free up memory.
Finalize() method
 The Java finalize() method of Object class is a method that the Garbage Collector
always calls just before the deletion/destroying the object which is eligible for
Garbage Collection to perform clean-up activity.
 Clean-up activity means closing the resources associated with that object like
Database Connection, Network Connection, or we can say resource de-allocation
Program:

Output:
NAMING
CONVENTION
Introduction to DESTRUCTOR
● Java naming convention is a rule to follow as you decide what to name your identifiers such as class,
package, variable, constant, method, etc.
● But, it is not forced to follow. So, it is known as convention not rule. These conventions are suggested by
several Java communities such as Sun Microsystems and Netscape.

Basic naming comventions are:


1.camaCasing
2.PascalCasing
3.snake_casing
Construct Convention Description Examples

Class PascalCase Classes should be named using MyClass, Employee


PascalCasing, with the first letter of
each word capitalized. A class name
should be a noun or a word
representative of an object.

Interface PascalCase Interfaces should be named using Serializable, Runnable


PascalCasing, with the first letter of
each word capitalized. An interface
name should be an adjective.

Method camelCase Method should be named using main(), print(), println() etc.
camelCasing. Method names should
always start with a lower case letter.

Variable camelCase Variables should be named using num1, name, address


camelCasing. Variable names should
always start with a lower case letter.

Package snake_case (all lower case) Packages should be named using java, lang, util
snake_casing. Package names should
always start with a lower case letter.

Constant snake_case Constant variables should be named MAX_VALUE, MIN_VALUE etc.


(ALL UPPER CASE) using snake_casing. Contant variable
names should have all upper case
letters.
Introduction :
● Java naming convention is a rule to follow as you decide what to name your identifiers such as class,
package, variable, constant, method, etc.
● But, it is not forced to follow. So, it is known as convention not rule. These conventions are suggested by
several Java communities such as Sun Microsystems and Netscape.

Basic naming comventions are:


1.camaCasing
2.PascalCasing
3.snake_casing
COMPILER AND
INTERPRETER

You might also like