What is an Object?
• Real world objects are things that have:
1) state
2) behavior
Example: your dog:
• state – name, color, breed, sits?, barks?, wages tail?,
runs?
• behavior – sitting, barking, waging tail, running
• A software object is a bundle of variables (state) and
methods (operations).
Object Creation
• A variable is declared to refer to the objects of
type/class String:
String s;
• The value of s is null; it does not yet refer to any object.
• A new String object is created in memory with initial “abc” value:
• String s = new String(“abc”);
• Now s contains the address of this new object.
Object Destruction
• A program accumulates memory through its execution.
• Two mechanism to free memory that is no longer need by the program:
1) manual – done in C/C++
2) automatic – done in Java
• In Java, when an object is no longer accessible through any variable, it is eventually removed from the memory by the garbage collector.
• Garbage collector is parts of the Java Run-Time
Environment.