File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Birla Murugesan
Ranch Hand
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to we check if primitives like long,int becomes null?
 
M K Rayapudi
Ranch Hand
Posts: 160
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
primitives can't hold null 'values',
objects can hold null 'references'.
 
Lorand Komaromi
Ranch Hand
Posts: 276
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..?
 
Lorand Komaromi
Ranch Hand
Posts: 276
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
M K Rayapudi wrote:
objects can hold null 'references'.


Reference variables can hold null values.
 
Aakash Parashar
Ranch Hand
Posts: 123
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Embla Tingeling
Ranch Hand
Posts: 237
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 237
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20203
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic