Some understanding of NULL in Java

Source: Internet
Author: User

1.null is a keyword in Java, like public, static, final. It is case sensitive and you cannot write null or NULL, and the compiler will not recognize them and then make an error.

2. Null is the default value for any reference type , not strictly the default value for all object types. This applies to all variables, such as member variables, local variables, instance variables, static variables

3.null is neither an object nor a type, it is only a special value that you can assign to any reference type, or you can convert null to any type

4.null can be assigned to a reference variable, you cannot assign null to a primitive type variable , such as int, double, float, Boolean. If you do that, the compiler will give you an error, but if you assign null to the wrapper class object and then assign the object to its base type, the compiler will not error

5. any wrapper class that contains null values throws a null pointer exception when the Java unboxing generates a basic data type .

6. If a reference type variable with a null value is used, the instanceof operation will return false

7. A non-static method cannot be called to use a reference-type variable with a value of NULL. It throws a null pointer exception, and you can use a static method to use a reference-type variable with a value of NULL. Because static methods use static bindings, NULL pointer exceptions are not thrown.

8. You can pass null to the method, at which point the method can receive any reference type

9. You can use the = = or! = operation to compare null values , but you cannot use other algorithms or logical operations, such as less than or greater than. Unlike SQL, null==null in Java will return true

In summary, remember that NULL is the default value for any reference type variable, and in Java you cannot use NULL to invoke any of the instance methods or instance variables.

Some understanding of NULL in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.