File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reference and Object

 
Bindu San
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I was going thru a Java book. I was confused with the meanings of a reference and an Object . Whats exactly does a reference mean and object ?
 
Junilu Lacar
Bartender
Pie
Posts: 6529
21
Java Linux Mac Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll try to explain by way of example and diagram:
Object obj = new Object();
With the above statement, two things are created: 1) a variable that can refer to an Object (obj)
2) a new instance of the Object class.

Your code gains access to the object via the reference 'obj'. When using it to invoke methods and access data members, you can think of the reference obj as if it were the object itself. However, when doing assignments and passing obj as a parameter to other methods, you have to remember that it is just a reference.
For example, if you wrote
Object obj = new Object();
Object x = obj;

You now have two references pointing to the same Object. The assignment does not create a new object but merely copies the reference obj to x, in effect, making both x and obj refer to the same Object. The same principle applies when passing obj as a parameter to a method.
HTH,
Junilu
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic