File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes What is Null in Java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "What is Null in Java?" Watch "What is Null in Java?" New topic

What is Null in Java?

Nagaraj Shivaklara
Ranch Hand

Joined: Dec 16, 2008
Posts: 78

I want to know about null. Is it an Object? Does it has size? What actually in real applications null is???


Thanks n Regards,
Nagaraj S K
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3152

null is definitely not an object. Its some value that is not existent.

Mohamed Sanaulla | My Blog
Darryl Burke

Joined: May 03, 2008
Posts: 5115

From the JLS

3.10.7 The Null Literal
The null type has one value, the null reference, represented by the literal null, which is formed from ASCII characters. A null literal is always of the null type.


4.12.5 Initial Values of Variables
  • For all reference types (ยง4.3), the default value is null.

  • luck, db
    There are no new questions, but there may be new answers.
    William Brogden
    Author and all-around good cowpoke

    Joined: Mar 22, 2000
    Posts: 13037
    Given that all Java memory allocation sets the locations to zero, the value in memory for a null reference is zero.

    Not something you should worry about or try to fool with.

    Jesper de Jong
    Java Cowboy
    Saloon Keeper

    Joined: Aug 16, 2005
    Posts: 15092

    William Brogden wrote:Given that all Java memory allocation sets the locations to zero, the value in memory for a null reference is zero.

    If you set a variable to null, then what the actual bits of the reference in memory look like depends on JVM implementation details. It doesn't necessarily have to be zeroes. But it's not something you need to be concerned about, because you can't access the direct value of a reference variable anyway.

    Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
    Rob Spoor

    Joined: Oct 27, 2005
    Posts: 20276

    In Visual Basic, the equivalent value of null is called Nothing. I find that name more descriptive than null.

    SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
    How To Ask Questions How To Answer Questions
    Bear Bibeault
    Author and ninkuma

    Joined: Jan 10, 2002
    Posts: 63866

    Of the synonyms for "nothing" shown by, the keywords I'd have preferred are: naught, nihility, zilch , or (my favorite) annihilation.

    [Asking smart questions] [About Bear] [Books by Bear]
    Randall Twede
    Ranch Hand

    Joined: Oct 21, 2000
    Posts: 4351

    to answer your implied question. we sometimes set things to null in our programs to "erase"(delete) them.
    or (my favorite) annihilation.

    ah yes, Total Annihilation, one of my all time favorite games.

    Visit my download page
    I agree. Here's the link:
    subject: What is Null in Java?
    jQuery in Action, 3rd edition