aspose file tools*
The moose likes Java in General and the fly likes How to we check if primitives like long,int becomes null? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to we check if primitives like long,int becomes null?" Watch "How to we check if primitives like long,int becomes null?" New topic
Author

How to we check if primitives like long,int becomes null?

Birla Murugesan
Ranch Hand

Joined: Nov 25, 2008
Posts: 66
How to we check if primitives like long,int becomes null?
M K Rayapudi
Ranch Hand

Joined: Feb 19, 2007
Posts: 158
primitives can't hold null 'values',
objects can hold null 'references'.


R6i
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
Birla Murugesan wrote:How to we check if primitives like long,int becomes null?


If by null you mean 0, it's pretty obvious, isn't it..?


OCJP 6 (93%)
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
M K Rayapudi wrote:
objects can hold null 'references'.


Reference variables can hold null values.
Aakash Parashar
Ranch Hand

Joined: Jul 25, 2005
Posts: 123

Birla Murugesan wrote:How to we check if primitives like long,int becomes null?


Primitives are not objects and when they are reset they get their intialization value. If you use an unintialized primitive variable in local scope, the class does not compiles.


Your's Aakash
SCJP 1.4 96%, SCBCD 1.3 94%, http://java-application-programming.blogspot.in
Embla Tingeling
Ranch Hand

Joined: Oct 22, 2009
Posts: 237
Birla Murugesan wrote:How to we check if primitives like long,int becomes null?


A primitive variable can never be null in the sense that it's void, that is holds nothing. It will always hold some value.

If you by null mean 0 then you just check if the variable holds a 0 using the == operator.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40059
    
  28
Unlike reference types where null can be regarded as "no object" and therefore an invalid content, a 0 might be a valid content for a number. So the concept of null and primitive values don't mix.
Embla Tingeling
Ranch Hand

Joined: Oct 22, 2009
Posts: 237
uj nossnahoj wrote:
Birla Murugesan wrote:How to we check if primitives like long,int becomes null?


A primitive variable can never be null in the sense that it's void, that is holds nothing. It will always hold some value.


Well, I may be wrong here so I better mention it before someone else does.

Double and float actually can hold a non-number called NaN (Not a Number). Maybe NaN should be considered "null" for doubles/floats.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40059
    
  28
No, I don't think NaN can be regarded as an analogue to null. It is a very strange value, but is still a value. As a very rough approximation, NaN is rather like an error value.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18992
    
    8

There's also Double.POSITIVE_INFINITY and Double.NEGATIVE_INFINITY, but those are even more implausible candidates for the null value.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to we check if primitives like long,int becomes null?