The NULL keyword for Java

Source: Internet
Author: User

Overview Null is neither an object nor a type a. itonlyonlyis a special value that you can assign to any reference type. B. During the compile and run times, it is possible to cast null to any reference type, and no null pointer exception is thrown during the run time.
Null can assigned to String
Can assign null to Integer Also
null; //Null can also is assigned to Double

Null can is type cast to String
It can also is type casted to Integer
Yes it ' s possible, no error
 Any wrapper class that contains null values throws a null pointer exception when the Java unboxing generates a basic data type
Null
i = iamnull//remember-no compilation Error
If you use a reference type variable with a null value, the instanceof operation will return false
Null
System. out "False ");
Use simple techniques to avoid NULL pointer exceptions 1. When using the Equals () method, the known string is the base 2. For the string representation of an object, use String.valueof (obj) instead of obj.tostring () 3. Using the Null security method
//stringutils methods is null safe, they don ' t throw NullPointerException
System. out. println (Stringutils.isempty (NULL));//true
System. out. println (Stringutils.isblank (NULL));//true
System. out. println (Stringutils.isnumeric (NULL));//\false
System. out. println (Stringutils.isalluppercase (NULL));//false
4. The method avoids directly returning null, using Collections.empty_list, Collections.empty_set and Collections.empty_map instead of 5. Using @notnull, @Nullable annotations 6. Avoid unnecessary automatic unboxing
Person ("Ram");
Phone = Ram.getphone ();
At this point, if Getphone is an integer type and is empty, it will throw NullPointerException



From for notes (Wiz)



The NULL keyword for 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.