Lifetime Concept in Java Programming Time between allocation and de-allocation of memory Life time depends on block i.e { } life time starts when declaration statement elaborated and expires at end of block There is no delete keyword in java Garbage collector is responsible for all deletes Java is free from dangling reference and garbage problem Why java does not support delete keyword? Java does not support delete keyword because there is a garbage collector in java This automatically runs and collects dangling or un-referenced objects.That is why there is no delete keyword in java like C++. Garbage collector can be explicitly like that System.gc(); When a life of object ends garbage collector runs automatically Example 1 { int a=5;// life Time start here a++; } //life time expire Example 2 Let Student is a class Student s; // creating a reference of Student class {Student t; //...
Java tutorials and example codes to deliver the basic concept. Blog contains lots of code examples in java.