This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wrappers + Overloading

 
Pritish Chakraborty
Ranch Hand
Posts: 91
C++ Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll get straight to my questions

After going through Ch-3, I happened to think of the following.

Date d;
and
Date d = null;

What is the difference between an uninitialized and nulled reference (the only one I could think of is how the garbage collector treats them)?

And in overloading, it is said that when an exact match is not found, the JVM uses the method with the smallest argument wider than the parameter. Can someone please explain with an example?
 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pritish Chakraborty wrote:I'll get straight to my questions

After going through Ch-3, I happened to think of the following.

Date d;
and
Date d = null;

What is the difference between an uninitialized and nulled reference (the only one I could think of is how the garbage collector treats them)?

And in overloading, it is said that when an exact match is not found, the JVM uses the method with the smallest argument wider than the parameter. Can someone please explain with an example?


consider the following scenario;

public void play(int a, int b) {}

public void play(long a, long b){}


now consider this method call:

byte x = 9;
byte y =8;
play(x,y); // this will call play with int arguments, because that is the method with the smallest argument wider than the parameters viz wider than byte , byte.


regarding to your first question if the Date d is an instance variable then there is no difference between Date d; and Date d = null;

if it is a local variable then if you write Date d; you are just declaring the variable d of the type Date. you are not initializing it. if you try to use it you will get a compiler error.

when you do Date d = null; you have initialized the variable to null ,which is nothing. d is not pointing to any actual Date object. however it won't give you any compiler error.

Garbage collector won't make any difference. Garbage collector is to save the memory by blowing objects on heap. none of the statements Date d; and Date d = null; produce any objects so no role of garbage collector.
 
Pritish Chakraborty
Ranch Hand
Posts: 91
C++ Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So it depends on scope of the variable....of course, this was referred to many times in the chapter itself!

The overloading part is clear as well, thanks!

Also, I meant that Date d = null; makes a difference on the garbage collector if d were previously referring to an object...silly, I know! lol
 
chain singh
Ranch Hand
Posts: 117
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JVM treat 'NULL' as a value ,so if you assign to any local reference variable it will not give any compiler error unless you use this reference variable.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pritish Chakraborty wrote: I meant that Date d = null; makes a difference on the garbage collector if d were previously referring to an object...

what could be the answer and how will you prove if i say yes or no
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seetharaman Venkatasamy wrote:
Pritish Chakraborty wrote: I meant that Date d = null; makes a difference on the garbage collector if d were previously referring to an object...

what could be the answer and how will you prove if i say yes or no



Also, "Date d = null;" is a declaration. There is no way for d to refer to a previous object.

Henry
 
Pritish Chakraborty
Ranch Hand
Posts: 91
C++ Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, of course...I don't know what I was thinking xD.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic