Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

what is the difference between a java object reference and
c++ pointer?

Answer Posted / aruna

object reference contains the address of the newly created
object by the JVM.

object reference is also a variable (variables are seen as
memory cells that can be accessed using their identifiers.
This way we did not have to care about the physical
location of our data within memory, we simply used its
identifier whenever we wanted to refer to our variable.)
using which we can access an object without knowing the
actual address or the location in which it is stored.

So,creating an object means, allocating some memory in heap
and intialise the instance variables and return the address
of the newly created object to the program.
thus, object reference contains the address of the memory
location(where the object is stored to which it is pointing
to)

JVM keeps track of these references.

In C++:

& is the reference operator and can be read as "address of"
* is the dereference operator and can be read as "value
pointed by".

For ex:

a= *c; // *(&b)
c= &b; // address of b (120) is stored in c.

where b=1000 and its stored in the memory location 120.
then the output of above two statements is:

a=1000;
c=120;


So, C++ pointer is nothing but a memory location in which
the value of the actual object it is pointing to is stored.


difference btn C++ pointer and object reference in java.

1. C++ pointer can point to any primitive data type where
as object reference in java point to an object.

Note:
whatever language you use, basic definitions would not
change.

Is This Answer Correct ?    6 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is locale?

977


What is the difference between a static and a non-static inner class in java programming?

978


Is java still necessary?

1002


Given a singly linked list, find the middle of the list in a single traversal without using temporary variable.

993


Do you know why doesn't the java library use a randomized version of quicksort?

903


What is an arraylist in java?

982


What are static blocks and static initalizers in java ?

1012


What is default switch case? Give example.

946


Objects or references which of them gets garbage collected?

914


Name container classes in java programming?

1023


What is passing by reference in java?

961


What are the types of inner classes (non-static nested class) used in java?

1007


What is the importance of main method in Java?

1014


Differentiate between a constructor and a method? Can we mark constructors final?

1127


What is the difference between abstract class and interface1? What is an interface?

996