This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes What is null ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is null ?" Watch "What is null ?" New topic
Author

What is null ?

faisal usmani
Ranch Hand

Joined: Jan 14, 2006
Posts: 139
Hello ranchers ,

what is null in java , i think it is not a keyword , is it a value ??


thanx in advance
Sam Codean
Ranch Hand

Joined: Feb 26, 2006
Posts: 194
I presume the null of java is as good as the void* of C. It works in the same fashion. I do not think that it is a value.


-Sam Codean<br />SCJP 1.4 (98%)<br />SCJD 5.0 (87.5%)
Kj Reddy
Ranch Hand

Joined: Sep 20, 2003
Posts: 1704
I assume null is a special literal in Java and it can be cast to any reference type which represents empty(which is not existing).
Kj Reddy
Ranch Hand

Joined: Sep 20, 2003
Posts: 1704
Originally posted by Codean:
I presume the null of java is as good as the void* of C. It works in the same fashion. I do not think that it is a value.


Hi Codean, you display name does not follow JavaRanch naming policy. You can have a look at JavaRanch naming policyand crrect it.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
null is a keyword. It works much like NULL in C++ (not void* since null is not a type, it is a value). null simply means that a reference variable does not refer to any object.

Layne


Java API Documentation
The Java Tutorial
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[Layne]: null is a keyword.

Not according to Sun's definition. "While true and false might appear to be keywords, they are technically Boolean literals (�3.10.3). Similarly, while null might appear to be a keyword, it is technically the null literal (�3.10.7)." The difference appears to have literal practical value, since just about the only thing they do with the definition is tell us that we can't have an identifier that matches a keyword... or a boolean literal or null literal. And all three of these are incorporated in the definition of token. Big deal. It looks like "keyword" never appears in any definition in which the null literal and boolean literals aren't also included, so it would've made sense to group them all together in the first place. Regardless though, for whatever reason, Sun chose to group them separately.


"I'm not back." - Bill Harding, Twister
faisal usmani
Ranch Hand

Joined: Jan 14, 2006
Posts: 139
Hello ranchers ,

So null is a special literal and is of primtive type , correct me if i am wrong .


Thanx in advance
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

Originally posted by faisal usmani:
correct me if i am wrong .


OK: you're wrong. null is a literal of reference type.


[Jess in Action][AskingGoodQuestions]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

Originally posted by Jim Yingst:
The difference appears to have literal practical value


Cute typo
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is null ?
 
Similar Threads
HTTP Status 500
Confused: request.getParameter("userName") returns null
JSP Exception 500 Error
NullpointerExceptin while creating rootPOA
Values of Hash Map to be 2-dimensional array