Aug 30, 2013

What is Object in java programming (object oriented programming)?

Objects in Java:An object oriented programming language

Definition of an Object:



An object in java programming is an instance of a class. Object is the implementation of the concept given by the class. Whenever an object is created all the non static member of the class gets activated. Object in java programming is responsible for allocating memory to all non static member of the class.
When object of the class is created , a context is created into heap memory area. In this heap memory all the non static member gets memory. The size of the context in heap is decided according to the members(if there are 2 integer variable in the class and 2 float variable then size of the context will be 16 bytes).
object_oriented_java_programming
Here is a demonstration of how a member gets memory in the heap memory area(HMA). Discussing back to the object, Basically object is used to access/call non static members of the class. Without creating object we are unable to use members of the class, but indirectly it is possible. This indirect technique of calling/accessing non static members of the class will be discussed in later posts.

Why we can't access/call non static member of the class without creating object:

We can't access/call non static members of the class without creating object because each member of the class needs memory to execute. This memory is allocated to them as object is created. So unless we create the object of  the class, we can't use these members.

How to create an Object In java:

We can  create an object by using "new" operator.

Syntax:

class name <reference variable>=new constructor_name();

Example:

If name of class is My_class then-

My_class ob=new My_class();

Code written above corresponds to create the object the My_class Class. Now question arises what behind the creation of object of My_class Class. We will know about scene behind this in Internal mechanism of Object creation code.