• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to we check if primitives like long,int becomes null?
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
primitives can't hold null 'values',
objects can hold null 'references'.
 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

M K Rayapudi wrote:
objects can hold null 'references'.



Reference variables can hold null values.
 
Ranch Hand
Posts: 123
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79471
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79471
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28263
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic