File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Difference between Object and Reference, in this Scenario. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Difference between Object and Reference, in this Scenario. " Watch "Difference between Object and Reference, in this Scenario. " New topic
Author

Difference between Object and Reference, in this Scenario.

N.Senthil Kumar
Ranch Hand

Joined: Jul 07, 2009
Posts: 50


May i know the Difference between these three expressions and where and which to use.


HashMap map = null;
map = map2;

and

HashMap map = map2;

and

HashMap map = new HashMap();
map = map2;


Thanks




N.Senthil Kumar
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

The first and third versions make an unnecessary assignment to the variable; the third is really terrible because you create an object that is never used for anything. The second version does only as much work as is needed, and no more.

Now, I don't know what that has to do with your subject? An object is like a Dog, and a reference is like a Leash. It connects you to the Dog; it provides a way to refer to the Dog. A variable is a reference.


[Jess in Action][AskingGoodQuestions]
N.Senthil Kumar
Ranch Hand

Joined: Jul 07, 2009
Posts: 50
Ernest Friedman-Hill wrote:The first and third versions make an unnecessary assignment to the variable; the third is really terrible because you create an object that is never used for anything. The second version does only as much work as is needed, and no more.


Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between Object and Reference, in this Scenario.
 
Similar Threads
HashMap Problem
difference between hashmap hashtable etc
inheritance doubt
Problem regarding HashMap.
any object better than hashmap