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 the use of flag?

863


Can a variable be local and static at the same time?

782


What is java reflection api?

774


What is linkedlist in java?

749


What is the use of math abs in java?

761


Can you extend main method in java?

859


What is the difference between static class and normal class?

762


What do you understand by java?

766


what is bmg file and how to create that files?what will it contailn?

2154


Tell me are there implementations for sorting and searching in the java libarary?

834


Explain the polymorphism principle?

795


What does three dots mean in java?

884


What is string [] java?

748


Why object class is super class for every class in java?

818


What is blank final variable?

815