iTSCET

iT Portal

Java Memory Allocation – Part 4


Constructor
• No return type
• Not mandatory
• Can be overloaded.
• Without any parameter is called as default constructor.
• If no, user defined constructor then implicit constructor initialize member variable to default values.
o Numeric data types to 0.
o Char to null(‘’).
o Boolean to false.
o Reference variables to null.

Method Overloading
• Argument list could differ in
o No. of parameters.
o Data type of parameters.
o Sequence of parameters.

Memory Allocation
• Local variable stored in STACK.
o Life time of local variable is the life time of method.
o De-allocated in LIFO order when method terminates

• Dynamically allocated arrays and objects are stored in HEAP.
o Need to be de-allocated.

Automatic Garbage Collection
• De-allocates the dynamic memory automatically.(But in C/C++ the programmer is responsible.)
• finalize()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s